For one of my Selenium Cests I want to set a cookie but this is simply not working. In order to find the problem I reduced my code to the absolut minimum and to my surprise setting cookies seems not to work at all.
/**
* Test if we can set simple cookies
*
* @param \AcceptanceTester $i
* @throws Exception
*/
public function settingCookieSetsCookie(AcceptanceTester $i)
{
$cookieDefaultParams = [
'path' => '/',
'secure' => false,
'httpOnly' => false,
'expiry' => 900,
'domain' => 'www.testdomain.local'
];
$i->amOnPage('/cookieCest.php');
$i->setCookie('example', 'myvalue', $cookieDefaultParams);
$i->amOnPage('/cookieCest.php'); // reload page
$cookieValue = $i->grabCookie('example');
$i->assertEquals('myvalue', $cookieValue);
}
For testing purposes I set up a local test domain www.testdomain.local which works fine.
Unfortunately the above test fails with the following error:
There was 1 failure:
1) BackendLoginCest: Setting cookie sets cookie Test codeception\acceptance\CookieCest.php:settingCookieSetsCookie Step Assert equals "myvalue",null Fail Failed asserting that null matches expected 'myvalue'.
Scenario Steps:
- $I->assertEquals("myvalue",null) at codeception\acceptance\CookieCest.php:36
- $I->grabCookie("example") at codeception\acceptance\CookieCest.php:35
- $I->amOnPage("/cookieCest.php") at codeception\acceptance\CookieCest.php:34
- $I->setCookie("example","myvalue",{"path":"/","secure":false,"httpOnly":false,"expiry":900,"domain":"www.new-ep...}) at codeception\acceptance\CookieCest.php:33
- $I->amOnPage("/cookieCest.php") at codeception\acceptance\CookieCest.php:32
FAILURES! Tests: 1, Assertions: 1, Failures: 1.`
As far as I can see the cookie params configuration looks good (and seems to be needed, as leaving it out results in an error).
I am currently using selenium-server-standalone-3.141.59.jar but tried older versions which produce the same problem.
The referenced file cookieCest.php
is just a simple script which var_dumps $_COOKIE
so I can see that there are no cookie values available in PHP.
Does anyone experience a similar problem and knows how to handle it?