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

kiklop74's avatar

Dusk LoginAs not working

I have a legacy app in Laravel 6.2 with Spark 9 and even the basic dusk test with loginAs is not working. User is never authenticated.

class ExampleTest extends DuskTestCase
{
    use DatabaseMigrations;

    /**
     * A basic browser test example.
     *
     * @return void
     * @throws Throwable
     */
    public function testBasicExample()
    {
        $user = factory(User::class)->create([
            'email' => '[email protected]'
        ]);

        $this->browse(function (Browser $browser) use ($user) {
            $browser->loginAs($user)->assertAuthenticated()->visit('/home');
        });
    }
}

I get this as output

There was 1 failure:

1) Tests\Browser\ExampleTest::testBasicExample
The user is not authenticated.
Failed asserting that an array is not empty.

/var/www/html/vendor/laravel/dusk/src/Concerns/InteractsWithAuthentication.php:68
/var/www/html/tests/Browser/ExampleTest.php:32
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/var/www/html/tests/Browser/ExampleTest.php:33

System is running using Laravel vessel (docker) and selenium is added with docker image seleniarm/standalone-chromium

0 likes
1 reply

Please or to participate in this conversation.