Hi, maybe related with #765 but I have see a strange behavior:
In my index.php i have:
<?php
print_r($_COOKIE);
In a Cept I write:
<?php
$I = new WebGuy($scenario);
$I->wantTo('test application start');
$I->setCookie("MyCookie", "My Cookie content");
$I->amOnPage("index.php");
$I->see("My Cookie content");
Test results with PhpDriver:
Acceptance Tests (1) ---------------------------------------------
Trying to test application start (ApplicationCept.php) Ok
------------------------------------------------------------------
Test results with WebDriver or Selenium2:
Acceptance Tests (1) ---------------------------------------------
Trying to test application start (ApplicationCept.php) Fail
------------------------------------------------------------------
Time: 33.89 seconds, Memory: 8.75Mb
There was 1 failure:
---------
1) Failed to test application start in ApplicationCept.php
Sorry, I couldn't see "My Cookie content":
Failed asserting that
--> /index.php<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>Array
(
)
</body></html>
--> contains "my cookie content".
Scenario Steps:
3. I see "My Cookie content"
2. I am on page "index.php"
1. I set cookie "MyCookie","My Cookie content"
FAILURES!
Tests: 3, Assertions: 3, Failures: 1.
In Selenium logs, I have this row:
21:00:44.211 INFO - Executing: [add cookie: MyCookie=My Cookie content; path=/] at URL: /session/8533f595-7e93-4c04-ba52-35085cb88f17/cookie)
So apparently cookie was set… however I can't get out of this headache.
Please try to set cookie after the amOnPage command. That might help
I have tried, same results.
I think it's a problem with setCookie on WebDriver because if I use PhpBrowser, it works (but I must use setCookie before amOnPage)
Acceptance Tests (1) ---------------------------------------------
Trying to test application start (ApplicationCept.php) Fail
------------------------------------------------------------------
Time: 24.13 seconds, Memory: 9.00Mb
There was 1 failure:
---------
1) Failed to test application start in ApplicationCept.php
Sorry, I couldn't see "My Cookie content":
Failed asserting that
--> /index.php<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>Hello World..........Array
(
)
</body></html>
--> contains "my cookie content".
Scenario Steps:
4. I see "My Cookie content"
3. I see "Hello World.........."
2. I set cookie "MyCookie","My Cookie content"
1. I am on page "/index.php"
Test code:
<?php
$I = new WebGuy($scenario);
$I->wantTo('test application start');
$I->amOnPage("/index.php");
$I->setCookie("MyCookie", "My Cookie content");
$I->see("Hello World..........");
$I->see("My Cookie content");
Please try to set cookie after the amOnPage command. That might help
strange advice, in my opinion :)
so problem will be fixed, no ?))
strange advice, in my opinion :)
I have tried this because a developer say this... it's no my idea...
However I think this problem was more deeper and was the cause of failure on code coverage.
so problem will be fixed, no ?))
No.
As I am say from days, with PhpBrowser works, with PhpDriver and Selenium fail.
@DavertMik please look at this issue more when you will have time, this is really painful issue :)
this is really painful issue :)
Especially in a product that I find great, amazing and useful as codeception
Ok, ok, ok. I will take a look and fix that in next minor release.
Looking deeper into #765 I discovered that my initial suggestion was right. The only thing I can improve here is to throw exception when the site is not loaded.
CodeCoverage issue is not really related to this one.
The exception thrown here make unusable the WebDriver module as it use setCookie() for sending CODECEPTION_CODECOVERAGE cookie.
Maybe the solution was remove this exception and update the documentation on setCookie().
@DavertMik Does that mean that there is no way to set cookie for the first visited page? The setCookie call after amOnPage works only on following amOnPage calls, the first is uneffected. So when I want to write test with a cookie I have to do this:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('see cookie value in title');
$I->amOnPage('/blank.html'); // I'd like to get rid of this line but the test fails without it.
$I->setCookie('key', 'Cookie value');
$I->amOnPage('/cookie-value-as-title.php');
$I->seeInTitle('Cookie value');
cookie-value-at-title.php:
<?php
die('<title>' . $_COOKIE['key'] . '</title>');
Also I believe the exception should be added (you reverted the commit becasue of a conflict with code coverage). Right now it's very confusing that the setCookie method doesn't work as expected. Also what's the point of setting a code coverage cookie it if won't work anyway?
Most helpful comment
strange advice, in my opinion :)