diff --git a/WebDriver.php b/WebDriver.php index 5afbff9fe..772cb3bde 100644 --- a/WebDriver.php +++ b/WebDriver.php @@ -177,6 +177,19 @@ public function executeScript($script, array $arguments = array()) { } } + /** + * An abstraction for managing stuff you would do in a browser menu. For + * example, adding and deleting cookies. + * + * @return WebDriverOptions + */ + public function manage() { + return new WebDriverOptions( + $this->executor, + $this->sessionID + ); + } + /** * An abstraction allowing the driver to access the browser's history and to * navigate to a given URL. diff --git a/WebDriverOptions.php b/WebDriverOptions.php new file mode 100644 index 000000000..ca664d0cc --- /dev/null +++ b/WebDriverOptions.php @@ -0,0 +1,35 @@ +executor = $executor; + $this->sessionID = $session_id; + } + + /** + * Return the interface for managing driver timeouts. + * + * @return WebDriverTimeouts + */ + public function timeouts() { + return new WebDriverTimeouts($this->executor, $this->sessionID); + } + + private function execute($name, array $params = array()) { + $command = array( + 'sessionId' => $this->sessionID, + 'name' => $name, + 'parameters' => $params, + ); + $raw = $this->executor->execute($command); + return $raw['value']; + } +} diff --git a/WebDriverTimeouts.php b/WebDriverTimeouts.php new file mode 100644 index 000000000..06a73b742 --- /dev/null +++ b/WebDriverTimeouts.php @@ -0,0 +1,64 @@ +executor = $executor; + $this->sessionID = $session_id; + } + + /** + * Specify the amount of time the driver should wait when searching for an + * element if it is not immediately present. + * + * @param int $seconds Wait time in second. + * @return WebDriverTimeouts The current instance. + */ + public function implicitlyWait($seconds) { + $this->execute('setImplicitWaitTimeout', array('ms' => $seconds * 1000)); + return $this; + } + + /** + * Set the amount of time to wait for an asynchronous script to finish + * execution before throwing an error. + * + * @param int $seconds Wait time in second. + * @return WebDriverTimeouts The current instance. + */ + public function setScriptTimeout($seconds) { + $this->execute('setScriptTimeout', array('ms' => $seconds * 1000)); + return $this; + } + + /** + * Set the amount of time to wait for a page load to complete before throwing + * an error. + * + * @param int $seconds Wait time in second. + * @return WebDriverTimeouts The current instance. + */ + public function pageLoadTimeout($seconds) { + $this->execute('setPageLoadTimeout', array( + 'type' => 'page load', + 'ms' => $seconds * 1000, + )); + return $this; + } + + private function execute($name, array $params = array()) { + $command = array( + 'sessionId' => $this->sessionID, + 'name' => $name, + 'parameters' => $params, + ); + $raw = $this->executor->execute($command); + } +} diff --git a/__init__.php b/__init__.php index 7aab8d5e4..528f4d1a4 100644 --- a/__init__.php +++ b/__init__.php @@ -19,7 +19,9 @@ require_once('WebDriverExceptions.php'); require_once('WebDriverExpectedCondition.php'); require_once('WebDriverNavigation.php'); +require_once('WebDriverOptions.php'); require_once('WebDriverSelect.php'); +require_once('WebDriverTimeouts.php'); require_once('WebDriverWait.php'); require_once('remote/WebDriverBrowserType.php'); require_once('remote/WebDriverCapabilityType.php'); diff --git a/remote/WebDriverCommandExecutor.php b/remote/WebDriverCommandExecutor.php index 8de5ece1d..fa92f9e72 100644 --- a/remote/WebDriverCommandExecutor.php +++ b/remote/WebDriverCommandExecutor.php @@ -20,6 +20,7 @@ class WebDriverCommandExecutor { * http://code.google.com/p/selenium/wiki/JsonWireProtocol#Command_Reference */ private $commands = array( + 'addCookie' => array('method' => 'POST', 'url' => '/session/:sessionId/cookie'), 'clear' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/clear'), 'clickElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/click'), 'executeScript' => array('method' => 'POST', 'url' => '/session/:sessionId/execute'), @@ -28,7 +29,7 @@ class WebDriverCommandExecutor { 'findElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element'), 'findElements' => array('method' => 'POST', 'url' => '/session/:sessionId/elements'), 'get' => array('method' => 'POST', 'url' => '/session/:sessionId/url'), - 'getAllCookie' => array('method' => 'GET', 'url' => '/session/:sessionId/cookie'), + 'getAllCookies' => array('method' => 'GET', 'url' => '/session/:sessionId/cookie'), 'getElementAttribute' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/attribute/:name'), 'getElementCSSValue' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/css/:propertyName'), 'getCurrentURL' => array('method' => 'GET', 'url' => '/session/:sessionId/url'), @@ -43,9 +44,11 @@ class WebDriverCommandExecutor { 'isElementSelected'=> array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/selected'), 'newSession' => array('method' => 'POST', 'url' => '/session'), 'refreshPage' => array('method' => 'POST', 'url' => '/session/:sessionId/refresh'), + 'setImplicitWaitTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts/implicit_wait'), + 'setPageLoadTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts'), + 'setScriptTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts/async_script'), 'quit' => array('method' => 'DELETE', 'url' => '/session/:sessionId'), 'sendKeysToElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/value'), - 'setCookie' => array('method' => 'POST', 'url' => '/session/:sessionId/cookie'), 'submitElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/submit'), );