Search code examples
laraveltestinglaravel-8laravel-dusklaravel-dusk2

laravel dusk invalid session id


2) Tests\\Browser\\MedewerkerContactTest::testGeenBericht
   Facebook\\WebDriver\\Exception\\InvalidSessionIdException: invalid session id

When executing dusk test file it would crash at an random point in the test and all tests after will also automaticly fail.
specs:

  • Laravel x8
  • php x7.4
  • dusk x6
  • chrome xlast one

At first i thought something was wrong with the pc specs and failed because of the insuficiënt ram so i put on many places a wait function.
This didnt have any effect.

when it works the most likely failure after is that it cant login i watch the failure png and it seems there it forgot to delete coockies so there may be the error also the login is a custom function as you can see down below

public function login(Browser $browser, string $role = 'klant_beheerder'): Browser
    {
        $browser->visit($this->url . '/')
            ->assertSee('Inloggen')
            ->type('#email', config('dusk.' . $role . '.login'))
            ->type('#password', config('dusk.' . $role . '.password'))
            ->press('.thm-tran-bg');

            return $browser;
    }

the wierd part is that other tests do work like this one here below in another file

public function testProfiel(): void
{
    $this->browse(function (Browser $browser) {
        $this->login($browser)
            ->visit($this->url . '/home')
            ->assertSee('e2ebeheerder')
            ->click('#page-header-user-dropdown')
            ->clickLink('Profiel')
            ->assertSee('Profiel van e2ebeheerder')
            ->assertSee('Opslaan')
            ->screenshot('InloggenTest::testProfiel');
    });
}

i have tried many things to fix this problem most of them were about flsuhing the session and deleting coockies between tests


Solution

  • i solved all invalid id by using --disable-dev-shm-usage at chromeOptions

    in Chrome, I did not have enough resources allocated to my Docker Container. Adding the "--disable-dev-shm-usage" flag to Chrome fixed the issue. Since its using local /tmp instead of it's /dev/shm it has plenty of room.