419 Page Expired with Laravel Octane, Sail, Sanctum and Dusk

595 Views Asked by At

After migration to Laravel Octane, the dusk tests fails with 419 Page Expired. Before the migration, everything was fine...

I made the following change to the name file docker/8.1/supervisord.conf

-command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --host=0.0.0.0 --port=80
+command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
  • Laravel Version: 8.82.0
  • Laravel Sanctum: 2.14.0
  • Octane Version: 1.2.0
  • Dusk Version: 6.22.0
  • PHP Version: 8.1.1
  • Database Driver & Version: MySQL 8
  • OS: macOS 12.2

My part of .env.local.dusk file:

APP_ENV=local
OCTANE_SERVER=swoole
BROADCAST_DRIVER=pusher
CACHE_DRIVER=memcached
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_DOMAIN=laravel.test

My the dusk test:

        $this->browse(function (Browser $browser) use ($user) {
            $browser
                ->visit(new Login())
                ->loginUser($user->email, 'password')
                ->assertSee('Dashboard')
                ->assertPathIs('/dashboard')
                ->assertAuthenticatedAs($user)
            ;
        });
class Login extends Page
{
    public function loginUser(Browser $browser, string $email, string $password)
    {
        $browser
            ->type('@email', $email)
            ->type('@password', $password)
            ->press('@button')
        ;
    }
}

Regards! :)

1

There are 1 best solutions below

0
On

I solved. A small change to the .env.dusk.local file helped:

from:

SESSION_DRIVER=array

to:

SESSION_DRIVER=file

and adding to the tests/DuskTestCase.php file:

            '--enable-file-cookies',

diff:

        $options = (new ChromeOptions())->addArguments(collect([
            '--window-size=1920,1080',
+           '--enable-file-cookies',
        ])->unless($this->hasHeadlessDisabled(), function ($items) {