Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Brentwood Helpdesk's avatar

Dusk not loading session values

I'm having problems with Dusk (in 5.4) not loading session values after a redirect.

My test looks for a success message to confirm that the record was saved properly but occasionally the session value is not rendered in the html. I can run the same test multiple times (using all the same records) and it will fail one third of the time and pass the rest of the time.

I've echoed out the session values for my success var onto the page and in the failure screenshot there is an empty array.

In my controller I redirect to the show page like this, very straight forward stuff.

return redirect()->route('notes.show', ['id' => $note->id])->with(['success' => 'Saved Note '.$note->id]);

Again, this happens randomly, sometimes it passes sometimes it fails.

Does anyone have any insight into why session data may not be getting saved/loaded properly with Dusk??

0 likes
1 reply
Brentwood Helpdesk's avatar
Level 16

I found a work around for this issue.

After trying several different session storage types and cleaning up my middleware I still was unable to isolate the problem. I did notice that most of the pages that were failing were very simple with only one or two fields.

The solution was to add a small pause in the test to allow the session data not to be hammered. I added ->pause(500) and everything works great. True the test is slightly slower but is green every time now :)

Please or to participate in this conversation.