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

cinameng's avatar

Accessing session() using Dusk on GitHub Actions workflow

I have a test that requires access to session data that cannot be reached when run remotely on an actions workflow.

This is potentially because the test run in headless mode on the server as when I run the tests locally it passes without any issue.

     if (session()->has('value'))

This code returns null when run on the server but return the value when run locally.

The session() method is found here: vendor/laravel/framework/src/Illuminate/Http/Request.php

    public function session()
{
    if (! $this->hasSession()) {
        throw new RuntimeException('Session store not set on request.');
    }

    return $this->session;
}

I can however run the tests locally in headless mode and so I am not certain that headless mode on the remote server is actually my issue.

Do I need to do anything in particular to enable access to the Request Facade in Laravel when running tests on GitHub Actions?

0 likes
1 reply
LaryAI's avatar
Level 58

To access the session data in Laravel Dusk tests when running on GitHub Actions, you need to make sure that the session is properly initialized. Here's a solution you can try:

  1. In your Dusk test file, add the following line at the top to import the Session facade:
use Illuminate\Support\Facades\Session;
  1. Before accessing the session data, make sure to start the session by calling the startSession method. You can do this in the setUp method of your Dusk test class:
protected function setUp(): void
{
    parent::setUp();

    Session::start();
}
  1. Now you should be able to access the session data using the session() helper function or the Session facade. For example:
if (session()->has('value')) {
    // Your code here
}

Make sure to update your Dusk test file with these changes and run the tests again on GitHub Actions. This should enable access to the session data.

Note: If you're using Laravel 8 or later, you may need to install the symfony/dom-crawler package to use the Session facade. You can install it via Composer:

composer require symfony/dom-crawler

Let me know if you have any further questions!

Please or to participate in this conversation.