laraveltestinglaravel-8laravel-dusklaravel-dusk2

laravel dusk invalid session id by testing


  1. Tests\Browser\MedewerkerContactTest::testGeenBericht Facebook\WebDriver\Exception\InvalidSessionIdException: invalid session id

the testfile wil return this error message on a random testcase underneath here you can see the complete error message


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

/var/www/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:107
/var/www/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:372
/var/www/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/var/www/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:27
/var/www/vendor/php-webdriver/webdriver/lib/WebDriverOptions.php:166
/var/www/vendor/laravel/dusk/src/Browser.php:408
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:164
/var/www/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:242
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:165
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:81
/var/www/tests/Browser/MedewerkerContactTest.php:65

Caused by
Facebook\\WebDriver\\Exception\\InvalidSessionIdException: invalid session id

/var/www/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:107
/var/www/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:372
/var/www/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/var/www/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:27
/var/www/vendor/php-webdriver/webdriver/lib/Remote/RemoteTargetLocator.php:35
/var/www/vendor/laravel/dusk/src/Browser.php:295
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:144
/var/www/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:242
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:150
/var/www/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:71
/var/www/tests/Browser/MedewerkerContactTest.php:65

please help me i use laravel version 8 and have the latest chrome driver and use php 7 i tried many things because at first i thought something was wrong with the pc specs and failed because of the insuficiƫnt ram and i put on many places a wait function.

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.