Search code examples
phpwebdrivercodeceptionbrowserstack

Codeception - Can't save and load session snapshot in Firefox


I have a loggin method that can save session snapshot for future calls.

public function loggedInIntoFrontend($name, $password)
{
    $I = $this->driver;
    // if snapshot exists - skipping login
    if ($I->loadSessionSnapshot('login')) {
        return;
    }
    // logging in
    $I->amOnPage(LoginPage::getUrl());
    $I->submitForm(
        LoginPage::$form,
        [
            '_username' => $name,
            '_password' => $password,
        ],
        LoginPage::$btnLogin
    );
    $I->see('Autotest');
    // saving snapshot
    $I->saveSessionSnapshot('login');
}

I use it in my Cests in _before() method. Like here:

class OrderFlowCest
{
    public function _before(AcceptanceTester $I)
        {
            $I->loggedInIntoFrontend(LoginPage::LOGIN, LoginPage::PASSWORD);
        }
}

It's possible that I use it in a few Cests. In Chrome it works fine. But when I try to run my Cests in environment with Firefox - I got this error:

[Facebook\WebDriver\Exception\InvalidCookieDomainException] You may only set cookies for the current domain Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03' System info: host: '5-255-93-81', ip: '5.255.93.81', os.name: 'windows', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_101' Driver info: driver.version: unknown

Has anyone encountered this?


Solution

  • I've got an answer from Lars Frantzen in Codeception gitter chat.

    Firefox, may be more restrictive with saving all the cookies which are currently there. You can solve this issue by just saving the cookies you really need to save the session (and not also all the other cookies which may cause Firefox to complain that they are not in the current domain). So do not use the saveSessionSnapshot function, but something like $this -> session = $I->grabCookie('MYSESSION'); and later then $I->setCookie('MYSESSION', $this->session);.