Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Webdriver] fix cookies debug #5709

Merged
merged 1 commit into from Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/Codeception/Module/WebDriver.php
Expand Up @@ -795,6 +795,16 @@ public function resizeWindow($width, $height)
$this->webDriver->manage()->window()->setSize(new WebDriverDimension($width, $height));
}

private function debugCookies()
{
$result = [];
$cookies = $this->webDriver->manage()->getCookies();
foreach ($cookies as $cookie) {
$result[] = is_array($cookie) ? $cookie : $cookie->toArray();
}
$this->debugSection('Cookies', json_encode($result));
}

public function seeCookie($cookie, array $params = [])
{
$cookies = $this->filterCookies($this->webDriver->manage()->getCookies(), $params);
Expand All @@ -804,7 +814,7 @@ function ($c) {
},
$cookies
);
$this->debugSection('Cookies', json_encode($this->webDriver->manage()->getCookies()));
$this->debugCookies();
$this->assertContains($cookie, $cookies);
}

Expand All @@ -817,11 +827,11 @@ function ($c) {
},
$cookies
);
$this->debugSection('Cookies', json_encode($this->webDriver->manage()->getCookies()));
$this->debugCookies();
$this->assertNotContains($cookie, $cookies);
}

public function setCookie($cookie, $value, array $params = [])
public function setCookie($cookie, $value, array $params = [], $showDebug = true)
{
$params['name'] = $cookie;
$params['value'] = $value;
Expand All @@ -847,13 +857,15 @@ public function setCookie($cookie, $value, array $params = [])
}
}
$this->webDriver->manage()->addCookie($params);
$this->debugSection('Cookies', json_encode($this->webDriver->manage()->getCookies()));
if ($showDebug) {
$this->debugCookies();
}
}

public function resetCookie($cookie, array $params = [])
{
$this->webDriver->manage()->deleteCookieNamed($cookie);
$this->debugSection('Cookies', json_encode($this->webDriver->manage()->getCookies()));
$this->debugCookies();
}

public function grabCookie($cookie, array $params = [])
Expand Down Expand Up @@ -3117,8 +3129,9 @@ public function loadSessionSnapshot($name)
}

foreach ($this->sessionSnapshots[$name] as $cookie) {
$this->setCookie($cookie['name'], $cookie['value'], (array)$cookie);
$this->setCookie($cookie['name'], $cookie['value'], (array)$cookie, false);
}
$this->debugCookies();
$this->debugSection('Snapshot', "Restored \"$name\" session snapshot");
return true;
}
Expand Down