Last active
March 31, 2020 02:37
-
-
Save dsantuc/68b91f9c2fcc01d14802d60524afcd60 to your computer and use it in GitHub Desktop.
Revisions
-
David Santucci renamed this gist
Feb 14, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
David Santucci renamed this gist
Feb 14, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
David Santucci created this gist
Feb 14, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ public function getAllCookies ($driver) { $cookies = array(); if ($driver instanceof Behat\Mink\Driver\BrowserKitDriver) { $cookies = $this->getBrowserKitCookies($driver); } else if ($driver instanceof Behat\Mink\Driver\Selenium2Driver) { $cookies = $this->getSeleniumCookies($driver); } else if ($driver instanceof Behat\Mink\Driver\ZombieDriver) { $cookies = $this->getZombieCookies($driver); } else if ($driver instanceof Zumba\Mink\Driver\PhantomJSDriver) { $cookies = $this->getPhantomJSCookies($driver); } return $cookies; } private function getBrowserKitCookies ($driver) { $cookies = array(); $cookieJar = $driver->getClient()->getCookieJar(); foreach ($cookieJar->all() as $cookie) { $cookies[] = array( "name"=>$cookie->getName(), "value"=>$cookie->getValue() ); } return $cookies; } private function getSeleniumCookies ($driver) { $cookies = array(); $wdSession = $driver->getWebDriverSession(); return $this->urlDecodeCookies($wdSession->getAllCookies()); } private function urlDecodeCookies ($cookiesIn) { $cookies = array(); foreach ($cookiesIn as $cookie) { $cookie['value'] = urldecode($cookie['value']); $cookies[] = $cookie; } return $cookies; } private function getZombieCookies ($driver) { $cookies = json_decode($driver->getServer()->evalJS("JSON.stringify(browser.cookies);"), true); return $this->urlDecodeCookies($cookies); } private function getPhantomJSCookies ($driver) { $cookies = array(); foreach ($driver->getBrowser()->cookies() as $cookie) { $cookies[] = array( "name"=>$cookie->getName(), "value"=>$cookie->getValue() ); } return $cookies; }