Skip to content

Commit

Permalink
[Webdriver] fix cookies debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitrichius committed Oct 10, 2019
1 parent afc5260 commit 7bf79ce
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit 7bf79ce

Please sign in to comment.