Last active
September 26, 2018 06:33
-
-
Save clasense4/11be9563f91c05813786 to your computer and use it in GitHub Desktop.
Yii2 + Codeception Cookie & Session problem / error, still got no solution for this. The cookie / session won't be share between tests (function). [Edit] check acceptance.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Codeception Test Suite Configuration | |
class_name: AcceptanceTester | |
modules: | |
enabled: | |
- WebDriver | |
config: | |
WebDriver: | |
url: http://localhost:8080/ | |
browser: chrome | |
window_size: 1366x768 | |
clear_cookies: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ../../../vendor/bin/codecept run acceptance --debug | |
Codeception PHP Testing Framework v2.1.0-rc1 | |
Powered by PHPUnit 4.7.7 by Sebastian Bergmann and contributors. | |
Tests\codeception\backend.acceptance Tests (3) ------------------------------------------------------------------------------------------- | |
Modules: WebDriver | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Test login with valid user (CustomerCest::login) | |
Scenario: | |
* I load session snapshot "login" | |
* As a Fajri | |
* I am on page "/auth/login/" | |
[GET] http://localhost:8080/auth/login/ | |
* I fill field "input[name="LoginForm[username]"]","[email protected]" | |
* I fill field "input[name="LoginForm[password]"]","mnbvcxz" | |
* I click "Log In" | |
* I grab cookie "PHPSESSID" | |
* I save session snapshot "login" | |
PASSED | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
See if all the Menu is ok (CustomerCest::testMenu) | |
Scenario: | |
* I set cookie "PHPSESSID","9v1eqhgujod77dl7fk1hbtnk25" | |
[Cookies] [{"path":"/","domain":"localhost:8080","name":"PHPSESSID","httpOnly":false,"hCode":-1505796059,"secure":false,"value":"9v1eqhgujod77dl7fk1hbtnk25","class":"org.openqa.selenium.Cookie"}] | |
* As a Loggedin User | |
* I pause execution | |
The execution has been paused. Press ENTER to continue | |
* I see current url equals "/dashboard/index" | |
* I pause execution | |
The execution has been paused. Press ENTER to continue | |
* I am on page "/customer/index" | |
[GET] http://localhost:8080/customer/index | |
* I see "Customer" | |
* I pause execution | |
The execution has been paused. Press ENTER to continue | |
PASSED | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
Test create (CustomerCest::testCreate) | |
Scenario: | |
* I set cookie "PHPSESSID","9v1eqhgujod77dl7fk1hbtnk25" | |
[Cookies] [{"path":"/","domain":"localhost:8080","name":"PHPSESSID","httpOnly":false,"hCode":-1505796059,"secure":false,"value":"9v1eqhgujod77dl7fk1hbtnk25","class":"org.openqa.selenium.Cookie"}] | |
9v1eqhgujod77dl7fk1hbtnk25 | |
* I pause execution | |
The execution has been paused. Press ENTER to continue | |
* I am on page "/customer/index" | |
[GET] http://localhost:8080/customer/index | |
* I see "Customer" | |
Screenshot and page source were saved into '_output' dir | |
FAIL | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Time: 28.28 seconds, Memory: 11.00Mb | |
There was 1 failure: | |
--------- | |
1) Failed to test create in CustomerCest::testCreate (.\acceptance\CustomerCest.php) | |
Failed asserting that /auth/login | |
--> Log in to get started | |
Username | |
Password | |
Remember Me | |
› | |
--> contains "customer". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// use tests\codeception\backend\AcceptanceTester; | |
use tests\codeception\backend\acceptance\BaseStep; | |
class CustomerCest | |
{ | |
public $user = 'Fajri'; | |
// private $cookie = 'xyz'; | |
private $cookie = null; | |
public static $username = '[email protected]'; | |
public static $password = 'mnbvcxz'; | |
public function login(BaseStep $I) | |
{ | |
if ($I->loadSessionSnapshot('login')) return; | |
$I->am($this->user); | |
$I->wantTo('test login with valid user'); | |
$I->amOnPage('/auth/login/'); | |
$I->fillField('input[name="LoginForm[username]"]', self::$username); | |
$I->fillField('input[name="LoginForm[password]"]', self::$password); | |
$I->click('Log In'); | |
$this->cookie = $I->grabCookie('PHPSESSID'); | |
// $I->pauseExecution(); | |
// echo $this->cookie; | |
// codecept_debug($this->cookie); | |
// saving snapshot | |
$I->saveSessionSnapshot('login'); | |
// $I->pauseExecution(); | |
} | |
/** | |
* @depends login | |
*/ | |
public function testMenu(BaseStep $I) | |
{ | |
// if ($I->loadSessionSnapshot('login')) return; | |
// $I->pauseExecution(); | |
$I->setCookie('PHPSESSID', $this->cookie); | |
$I->am('Loggedin User'); | |
$I->wantTo('see if all the Menu is ok'); | |
// Dashboard | |
// $I->amOnPage('/'); | |
$I->pauseExecution(); | |
$I->seeCurrentUrlEquals('/dashboard/index'); | |
// $I->see('xyz'); | |
// // Customer | |
// $I->click('Customers'); | |
$I->pauseExecution(); | |
$I->amOnPage('/customer/index'); | |
// $I->amOnPage('/customer/index'); | |
// $I->pauseExecution(); | |
$I->see('Customer'); | |
$I->pauseExecution(); | |
} | |
/** | |
* @depends login | |
*/ | |
public function testCreate(BaseStep $I) | |
{ | |
// $I->loadSessionSnapshot('login'); | |
// $I->seeCurrentUrlEquals('/dashboard/index'); | |
$I->setCookie('PHPSESSID', $this->cookie); | |
codecept_debug($this->cookie); | |
$I->pauseExecution(); | |
$I->amOnPage('/customer/index'); | |
$I->see('Customer'); | |
$I->pauseExecution(); | |
// $I->click('New Customer'); | |
// $I->pauseExecution(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java -Dwebdriver.chrome.driver=./chromedriver.exe -jar selenium-server-standal one-2.43.1.jar | |
22:37:49.451 INFO - Launching a standalone server | |
22:37:49.572 INFO - Java: Oracle Corporation 25.40-b25 | |
22:37:49.572 INFO - OS: Windows 8.1 6.3 amd64 | |
22:37:49.600 INFO - v2.43.1, with Core v2.43.1. Built from revision 5163bce | |
22:37:49.800 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub | |
22:37:49.802 INFO - Version Jetty/5.1.x | |
22:37:49.804 INFO - Started HttpContext[/selenium-server,/selenium-server] | |
22:37:49.890 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@2aaf7cc2 | |
22:37:49.891 INFO - Started HttpContext[/wd,/wd] | |
22:37:49.891 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver] | |
22:37:49.891 INFO - Started HttpContext[/,/] | |
22:37:49.900 INFO - Started SocketListener on 0.0.0.0:4444 | |
22:37:49.901 INFO - Started org.openqa.jetty.jetty.Server@133314b | |
22:38:00.389 INFO - Executing: [new session: Capabilities [{browserName=chrome}]]) | |
22:38:00.414 INFO - Creating a new session for Capabilities [{browserName=chrome}] | |
Starting ChromeDriver (v2.9.248315) on port 34781 | |
22:38:02.539 INFO - Done: [new session: Capabilities [{browserName=chrome}]] | |
22:38:03.080 INFO - Executing: [implicitly wait: 0]) | |
22:38:03.090 INFO - Done: [implicitly wait: 0] | |
22:38:03.598 INFO - Executing: [set window size]) | |
22:38:06.732 INFO - Done: [set window size] | |
22:38:06.909 INFO - Executing: [get: http://localhost:8080/auth/login/]) | |
22:38:10.322 INFO - Done: [get: http://localhost:8080/auth/login/] | |
22:38:10.449 INFO - Executing: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][(((./@name = 'input[name="LoginForm[username]"]') or ./@id = //label[contains(normalize-space(string(.)), 'input[name="LoginForm[username]"]')]/@for) or ./@placeholder = 'input[name="LoginForm[username]"]')] | .//label[contains(normalize-space(string(.)), 'input[name="LoginForm[username]"]')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]]) | |
22:38:10.488 INFO - Done: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][(((./@name = 'input[name="LoginForm[username]"]') or ./@id = //label[contains(normalize-space(string(.)), 'input[name="LoginForm[username]"]')]/@for) or ./@placeholder = 'input[name="LoginForm[username]"]')] | .//label[contains(normalize-space(string(.)), 'input[name="LoginForm[username]"]')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]] | |
22:38:10.492 INFO - Executing: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][@name = 'input[name="LoginForm[username]"]']]) | |
22:38:10.521 INFO - Done: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][@name = 'input[name="LoginForm[username]"]']] | |
22:38:10.535 INFO - Executing: [find elements: By.selector: input[name="LoginForm[username]"]]) | |
22:38:10.582 INFO - Done: [find elements: By.selector: input[name="LoginForm[username]"]] | |
22:38:10.607 INFO - Executing: [clear: 0 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[username]"]]]) | |
22:38:10.649 INFO - Done: [clear: 0 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[username]"]]] | |
22:38:10.656 INFO - Executing: [send keys: 0 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[username]"]], [[email protected]]]) | |
22:38:10.740 INFO - Done: [send keys: 0 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[username]"]], [[email protected]]] | |
22:38:10.764 INFO - Executing: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][(((./@name = 'input[name="LoginForm[password]"]') or ./@id = //label[contains(normalize-space(string(.)), 'input[name="LoginForm[password]"]')]/@for) or ./@placeholder = 'input[name="LoginForm[password]"]')] | .//label[contains(normalize-space(string(.)), 'input[name="LoginForm[password]"]')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]]) | |
22:38:10.832 INFO - Done: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][(((./@name = 'input[name="LoginForm[password]"]') or ./@id = //label[contains(normalize-space(string(.)), 'input[name="LoginForm[password]"]')]/@for) or ./@placeholder = 'input[name="LoginForm[password]"]')] | .//label[contains(normalize-space(string(.)), 'input[name="LoginForm[password]"]')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]] | |
22:38:10.839 INFO - Executing: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][@name = 'input[name="LoginForm[password]"]']]) | |
22:38:10.873 INFO - Done: [find elements: By.xpath: .//*[self::input | self::textarea | self::select][@name = 'input[name="LoginForm[password]"]']] | |
22:38:10.881 INFO - Executing: [find elements: By.selector: input[name="LoginForm[password]"]]) | |
22:38:10.917 INFO - Done: [find elements: By.selector: input[name="LoginForm[password]"]] | |
22:38:10.922 INFO - Executing: [clear: 1 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[password]"]]]) | |
22:38:10.957 INFO - Done: [clear: 1 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[password]"]]] | |
22:38:10.962 INFO - Executing: [send keys: 1 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[password]"]], [mnbvcxz]]) | |
22:38:11.059 INFO - Done: [send keys: 1 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: input[name="LoginForm[password]"]], [mnbvcxz]] | |
22:38:11.072 INFO - Executing: [find elements: By.selector: Log In]) | |
22:38:11.110 INFO - Done: [find elements: By.selector: Log In] | |
22:38:11.161 INFO - Executing: [find elements: By.xpath: .//a[normalize-space(.)='Log In'] | .//button[normalize-space(.)='Log In'] | .//a/img[normalize-space(@alt)='Log In']/ancestor::a | .//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)='Log In']]) | |
22:38:11.198 INFO - Done: [find elements: By.xpath: .//a[normalize-space(.)='Log In'] | .//button[normalize-space(.)='Log In'] | .//a/img[normalize-space(@alt)='Log In']/ancestor::a | .//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)='Log In']] | |
22:38:11.205 INFO - Executing: [click: 2 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> xpath: .//a[normalize-space(.)='Log In'] | .//button[normalize-space(.)='Log In'] | .//a/img[normalize-space(@alt)='Log In']/ancestor::a | .//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)='Log In']]]) | |
22:38:11.292 INFO - Done: [click: 2 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> xpath: .//a[normalize-space(.)='Log In'] | .//button[normalize-space(.)='Log In'] | .//a/img[normalize-space(@alt)='Log In']/ancestor::a | .//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)='Log In']]] | |
22:38:11.298 INFO - Executing: [get all cookies]) | |
22:38:11.317 INFO - Done: [get all cookies] | |
22:38:11.323 INFO - Executing: [get all cookies]) | |
22:38:11.328 INFO - Done: [get all cookies] | |
22:38:11.336 INFO - Executing: [delete all cookies]) | |
22:38:11.380 INFO - Done: [delete all cookies] | |
22:38:11.405 INFO - Executing: [add cookie: PHPSESSID=9v1eqhgujod77dl7fk1hbtnk25; path=/]) | |
22:38:11.426 INFO - Done: [add cookie: PHPSESSID=9v1eqhgujod77dl7fk1hbtnk25; path=/] | |
22:38:11.429 INFO - Executing: [get all cookies]) | |
22:38:11.437 INFO - Done: [get all cookies] | |
22:38:18.273 INFO - Executing: [get current url]) | |
22:38:18.288 INFO - Done: [get current url] | |
22:38:20.018 INFO - Executing: [get: http://localhost:8080/customer/index]) | |
22:38:20.628 INFO - Done: [get: http://localhost:8080/customer/index] | |
22:38:20.633 INFO - Executing: [find elements: By.selector: body]) | |
22:38:20.666 INFO - Done: [find elements: By.selector: body] | |
22:38:20.670 INFO - Executing: [get text: 3 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: body]]) | |
22:38:20.807 INFO - Done: [get text: 3 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: body]] | |
22:38:20.813 INFO - Executing: [get current url]) | |
22:38:20.818 INFO - Done: [get current url] | |
22:38:21.941 INFO - Executing: [delete all cookies]) | |
22:38:21.991 INFO - Done: [delete all cookies] | |
22:38:22.001 INFO - Executing: [add cookie: PHPSESSID=9v1eqhgujod77dl7fk1hbtnk25; path=/]) | |
22:38:22.009 INFO - Done: [add cookie: PHPSESSID=9v1eqhgujod77dl7fk1hbtnk25; path=/] | |
22:38:22.019 INFO - Executing: [get all cookies]) | |
22:38:22.022 INFO - Done: [get all cookies] | |
22:38:23.434 INFO - Executing: [get: http://localhost:8080/customer/index]) | |
22:38:23.875 INFO - Done: [get: http://localhost:8080/customer/index] | |
22:38:23.880 INFO - Executing: [find elements: By.selector: body]) | |
22:38:23.934 INFO - Done: [find elements: By.selector: body] | |
22:38:23.937 INFO - Executing: [get text: 4 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: body]]) | |
22:38:24.054 INFO - Done: [get text: 4 [[ChromeDriver: chrome on WIN8_1 (f9aaaf56c10a125eed177093fd5218cd)] -> css selector: body]] | |
22:38:24.056 INFO - Executing: [get current url]) | |
22:38:24.062 INFO - Done: [get current url] | |
22:38:24.086 INFO - Executing: [take screenshot]) | |
22:38:24.338 INFO - Done: [take screenshot] | |
22:38:24.355 INFO - Executing: [get page source]) | |
22:38:24.381 INFO - Done: [get page source] | |
22:38:24.395 INFO - Executing: [delete all cookies]) | |
22:38:24.452 INFO - Done: [delete all cookies] | |
22:38:24.456 INFO - Executing: [delete session: 5c2b9c45-58c8-4db9-99e1-f82393160f6c]) | |
22:38:25.697 INFO - Done: [delete session: 5c2b9c45-58c8-4db9-99e1-f82393160f6c] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see:
https://github.com/Codeception/Codeception/issues/4476
for a workaround, which is from @yujin1st :
For all who's tired with waiting, i suggest temporary solution to add a line into vendor/phpunit/phpunit/src/Util/Printer.php:43: