Codeception: "Unable to set Cookie" with phantomjs on loadSessionSnapshot

Hello,

I’m using Codeception (2.1.7) with phantomjs (2.1.1) and I’m using loadSessionSnapshot to avoid login on every test with the following code in my AcceptanceTester :

  public function login()
  {
    if ($this->loadSessionSnapshot('login'))
      return;
    $this->amOnPage('/en');
    $this->fillField('login', '***');
    $this->fillField('password', '***');
    $this->click('#btn-login');
    $this->saveSessionSnapshot('login');
  }

but when I have multiple tests with $I->login();, on second call, tests are crashing with :

[Facebook\WebDriver\Exception\UnableToSetCookieException] {"errorMessage":"Unable to set Cookie"...

I tried to move the amOnPage call of my login method to be sure that the browser is started but problem is the same…

Thanks for your help !

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 16
  • Comments: 28 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I had this issue and was not able to resolve it. Using PhantomJS 2.1. It is apparently a known issue that has been fixed, but the fix has not been officially released:

https://github.com/ariya/phantomjs/issues/14047

My solution was to switch away from PhantomJS to Selenium Server, using a docker file. I already had docker set up and running so my set up was very fast (15 minutes):

Per documentation on selenium headless testing with docker: http://codeception.com/docs/modules/WebDriver#Headless-Selenium-in-Docker

I created a very simple docker-compose file:

version: "3"
services:
  web:
    image: selenium/standalone-chrome:3.4.0-chromium
    ports:
      - "4444:4444"
    network_mode: "host"

Modified my acceptance test yml:

 - WebDriver:
          url: http://xxx.yyy
          port: 4444
          browser: chrome

Running tests based on this is very simple now:

docker-compose up -d
php codecept run
docker-compose stop

Everything works with sessions and cookies as expected. Skipped the mess of configuring selenium, web drivers and installing various browsers:

Test Output:

UserCest: Try to login
Signature: Common\UserCest:tryToLogin
Test: tests/xy/Common/UserCest.php:tryToLogin
Scenario --
 I login "Chad Windnagle","xx"
   I load session snapshot "login"
   I am on page "/sys/siteManager.cgi"
  [GET] http://dev.xy.com/sys/siteManager.cgi
   I fill field "input[name=userName]","Chad Windnagle"
   I fill field "input[name=pwd]","xx"
   I click "#submit-form"
   I wait 5
   I save session snapshot "login"
  [Snapshot] Saved "login" session snapshot
 I see "Hi, Chad Windnagle"
 PASSED

TempSearchCest: Confirm temp search page is working
Signature: Temps\TempSearchCest:loadSearchPage
Test: tests/tempbase/Temps/TempSearchCest.php:loadSearchPage
Scenario --
 I login "Chad Windnagle","xx"
   I load session snapshot "login"
  [Snapshot] Restored "login" session snapshot
 Page\AbstractTempBasePage: load page "AcceptanceTester"
   I am on page "/sys/tempsManager.cgi"
  [GET] http://dev.xx.com/sys/tempsManager.cgi
 I see "Temp Search"
 I make screenshot "temp-search-page"
  Screenshot saved to /home/chad/Projects/xx-tests/tests/_output/debug/page.png
 PASSED

Was trying PhantomJS 2.1.1 and Codeception 2.2.5.

Ended up just using PhantomJS 1.9.8 and my code that calls setCookie seems to work fine.

I built phantomjs from master

git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout master
git submodule init
git submodule update
python build.py

Still having the same issue (Codeception 2.2.1 (Phar))

According to this, the problem may be fixed in the development version of phantomjs 2.2.0. (Though I have not verified.)


I thought that I was experiencing the same thing as @tomvo:

I’m also receiving this error but looking at the screenshots Selenium generates, the session has been loaded after all. I also use it in a login flow and it shows the logged-in version of the application in the screenshot. So not sure why Webdriver throws this error.

However, I realized this was just an illusion. The screenshot shows the logged-in version of the web app, yes, but only because the first test logged in and the browser still has that old page loaded. It is not really logging in.

+1 with codeception 2.1.8 and phantomJs 2.1.1

PhantomJS 1.9.8 works for me too

Getting this error for Yii2 framework, Codeception v2.2.3, PhantomJS v2.1.1, PHP 5.4.16

I’m also receiving this error but looking at the screenshots Selenium generates, the session has been loaded after all. I also use it in a login flow and it shows the logged-in version of the application in the screenshot. So not sure why Webdriver throws this error.

edit: not using codecoverage, just a simple saveSessionSnapshot() in one test and another loadSessionSnapshot() in the next tests.