123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace Facebook\WebDriver;
- use Facebook\WebDriver\Remote\DriverCommand;
- use Facebook\WebDriver\Remote\ExecuteMethod;
- use InvalidArgumentException;
- class WebDriverOptions
- {
-
- protected $executor;
- public function __construct(ExecuteMethod $executor)
- {
- $this->executor = $executor;
- }
-
- public function addCookie($cookie)
- {
- if (is_array($cookie)) {
- $cookie = Cookie::createFromArray($cookie);
- }
- if (!$cookie instanceof Cookie) {
- throw new InvalidArgumentException('Cookie must be set from instance of Cookie class or from array.');
- }
- $this->executor->execute(
- DriverCommand::ADD_COOKIE,
- ['cookie' => $cookie->toArray()]
- );
- return $this;
- }
-
- public function deleteAllCookies()
- {
- $this->executor->execute(DriverCommand::DELETE_ALL_COOKIES);
- return $this;
- }
-
- public function deleteCookieNamed($name)
- {
- $this->executor->execute(
- DriverCommand::DELETE_COOKIE,
- [':name' => $name]
- );
- return $this;
- }
-
- public function getCookieNamed($name)
- {
- $cookies = $this->getCookies();
- foreach ($cookies as $cookie) {
- if ($cookie['name'] === $name) {
- return $cookie;
- }
- }
- return null;
- }
-
- public function getCookies()
- {
- $cookieArrays = $this->executor->execute(DriverCommand::GET_ALL_COOKIES);
- $cookies = [];
- foreach ($cookieArrays as $cookieArray) {
- $cookies[] = Cookie::createFromArray($cookieArray);
- }
- return $cookies;
- }
-
- public function timeouts()
- {
- return new WebDriverTimeouts($this->executor);
- }
-
- public function window()
- {
- return new WebDriverWindow($this->executor);
- }
-
- public function getLog($log_type)
- {
- return $this->executor->execute(
- DriverCommand::GET_LOG,
- ['type' => $log_type]
- );
- }
-
- public function getAvailableLogTypes()
- {
- return $this->executor->execute(DriverCommand::GET_AVAILABLE_LOG_TYPES);
- }
- }
|