Entries tagged browser testing

Laravel Dusk: The currently authenticated user is not who was expected.

Posted on 31. Oktober 2019 Comments

If you’re having trouble using $browser->loginAs($user) it might be because the SESSION_DRIVER is set to array. So even this simple code will fail:

$this->browse(function (Browser $browser) {
    $browser->loginAs(User::first())
            ->assertAuthenticatedAs(User::first());
});

Error: The currently authenticated user is not who was expected.
Failed asserting that two arrays are identical.

/vendor/laravel/dusk/src/Concerns/InteractsWithAuthentication.php:102
/tests/Browser/AuthTest.php:162
/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
/tests/Browser/AuthTest.php:163

Write a .env.dusk.local (or where ever you’re starting the tests from) and use a persistent driver like SESSION_DRIVER=database or SESSION_DRIVER=file