Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding new functions to match protocol, putting more data in exceptions.

Summary:adding window, window/size, window/position, keys. removing modifiers. also putting full server result in exceptions for those who may find it
useful.  note focusWindow() is how you call the window/ protocol endpoint directly, which has been added to the readme.

Reviewers:

Test Plan:

Task ID:
  • Loading branch information...
commit 9d236926f556a95df1e9735f80038e5071de5a15 1 parent bc79640
Justin Bishop authored
3  README.md
View
@@ -50,8 +50,9 @@ Each command is just the name of a function call, and each additional path is ju
$session->orientation();
-## A few Element/Cookie/Session convenience exceptions.
+## A few Element/Cookie/Session/Window convenience exceptions.
* To find elements, use element($using, $value) and elements($using, $value), where $using is the locator strategy ('xpath', 'id', 'name', etc)
* Use getAllCookies(), setCookie($cookie_json), deleteAllCookies(), and deleteCookie($name)
+* To focus a window, use focusWindow($name)
* Visit pages with open(), close the browser window with close()
7 WebDriver.php
View
@@ -34,4 +34,11 @@ public function session($browser = 'firefox',
return new WebDriverSession($results['info']['url']);
}
+
+ // TODO(jubishop): Create WebDriverSession instances
+ public function sessions() {
+ return $this->curl(
+ 'GET',
+ '/sessions');
+ }
}
68 WebDriverBase.php
View
@@ -15,75 +15,75 @@
abstract class WebDriverBase {
- public static function throwException($status_code, $message) {
+ public static function throwException($status_code, $message, $results) {
switch ($status_code) {
case 0:
// Success
break;
case 1:
- throw new IndexOutOfBoundsWebDriverError($message);
+ throw new IndexOutOfBoundsWebDriverError($message, $results);
case 2:
- throw new NoCollectionWebDriverError($message);
+ throw new NoCollectionWebDriverError($message, $results);
case 3:
- throw new NoStringWebDriverError($message);
+ throw new NoStringWebDriverError($message, $results);
case 4:
- throw new NoStringLengthWebDriverError($message);
+ throw new NoStringLengthWebDriverError($message, $results);
case 5:
- throw new NoStringWrapperWebDriverError($message);
+ throw new NoStringWrapperWebDriverError($message, $results);
case 6:
- throw new NoSuchDriverWebDriverError($message);
+ throw new NoSuchDriverWebDriverError($message, $results);
case 7:
- throw new NoSuchElementWebDriverError($message);
+ throw new NoSuchElementWebDriverError($message, $results);
case 8:
- throw new NoSuchFrameWebDriverError($message);
+ throw new NoSuchFrameWebDriverError($message, $results);
case 9:
- throw new UnknownCommandWebDriverError($message);
+ throw new UnknownCommandWebDriverError($message, $results);
case 10:
- throw new ObsoleteElementWebDriverError($message);
+ throw new ObsoleteElementWebDriverError($message, $results);
case 11:
- throw new ElementNotDisplayedWebDriverError($message);
+ throw new ElementNotDisplayedWebDriverError($message, $results);
case 12:
- throw new InvalidElementStateWebDriverError($message);
+ throw new InvalidElementStateWebDriverError($message, $results);
case 13:
- throw new UnhandledWebDriverError($message);
+ throw new UnhandledWebDriverError($message, $results);
case 14:
- throw new ExpectedWebDriverError($message);
+ throw new ExpectedWebDriverError($message, $results);
case 15:
- throw new ElementNotSelectableWebDriverError($message);
+ throw new ElementNotSelectableWebDriverError($message, $results);
case 16:
- throw new NoSuchDocumentWebDriverError($message);
+ throw new NoSuchDocumentWebDriverError($message, $results);
case 17:
- throw new UnexpectedJavascriptWebDriverError($message);
+ throw new UnexpectedJavascriptWebDriverError($message, $results);
case 18:
- throw new NoScriptResultWebDriverError($message);
+ throw new NoScriptResultWebDriverError($message, $results);
case 19:
- throw new XPathLookupWebDriverError($message);
+ throw new XPathLookupWebDriverError($message, $results);
case 20:
- throw new NoSuchCollectionWebDriverError($message);
+ throw new NoSuchCollectionWebDriverError($message, $results);
case 21:
- throw new TimeOutWebDriverError($message);
+ throw new TimeOutWebDriverError($message, $results);
case 22:
- throw new NullPointerWebDriverError($message);
+ throw new NullPointerWebDriverError($message, $results);
case 23:
- throw new NoSuchWindowWebDriverError($message);
+ throw new NoSuchWindowWebDriverError($message, $results);
case 24:
- throw new InvalidCookieDomainWebDriverError($message);
+ throw new InvalidCookieDomainWebDriverError($message, $results);
case 25:
- throw new UnableToSetCookieWebDriverError($message);
+ throw new UnableToSetCookieWebDriverError($message, $results);
case 26:
- throw new UnexpectedAlertOpenWebDriverError($message);
+ throw new UnexpectedAlertOpenWebDriverError($message, $results);
case 27:
- throw new NoAlertOpenWebDriverError($message);
+ throw new NoAlertOpenWebDriverError($message, $results);
case 28:
- throw new ScriptTimeoutWebDriverError($message);
+ throw new ScriptTimeoutWebDriverError($message, $results);
case 29:
- throw new InvalidElementCoordinatesWebDriverError($message);
+ throw new InvalidElementCoordinatesWebDriverError($message, $results);
case 30:
- throw new IMENotAvailableWebDriverError($message);
+ throw new IMENotAvailableWebDriverError($message, $results);
case 31:
- throw new IMEEngineActivationFailedWebDriverError($message);
+ throw new IMEEngineActivationFailedWebDriverError($message, $results);
case 32:
- throw new InvalidSelectorWebDriverError($message);
+ throw new InvalidSelectorWebDriverError($message, $results);
}
}
@@ -174,7 +174,7 @@ protected function curl($http_method,
$message = $value['message'];
}
- self::throwException($results['status'], $message);
+ self::throwException($results['status'], $message, $results);
return array('value' => $value, 'info' => $info);
}
3  WebDriverContainer.php
View
@@ -27,7 +27,8 @@ public function element($using, $value) {
sprintf(
'Element not found with %s, %s',
$using,
- $value) . "\n\n" . $e->getMessage());
+ $value) . "\n\n" . $e->getMessage(),
+ $e->getResults());
}
return $this->webDriverElement($results['value']);
14 WebDriverExceptions.php
View
@@ -15,7 +15,19 @@
final class WebDriverCurlException extends Exception {} // When curls fail
-abstract class WebDriverException extends Exception {}
+abstract class WebDriverException extends Exception {
+ private $results;
+
+ public function __construct($message, $results = null) {
+ parent::__construct($message);
+ $this->results = $results;
+ }
+
+ public function getResults() {
+ return $this->results;
+ }
+}
+
class IndexOutOfBoundsWebDriverError extends WebDriverException {} // 1
class NoCollectionWebDriverError extends WebDriverException {} // 2
class NoStringWebDriverError extends WebDriverException {} // 3
19 WebDriverSession.php
View
@@ -29,7 +29,7 @@ protected function methods() {
'window' => array('POST', 'DELETE'),
'source' => 'GET',
'title' => 'GET',
- 'modifier' => 'POST',
+ 'keys' => 'POST',
'orientation' => array('GET', 'POST'),
'alert_text' => array('GET', 'POST'),
'accept_alert' => 'POST',
@@ -100,6 +100,23 @@ public function ime() {
));
}
+ // /session/:sessionId/window (POST)
+ public function focusWindow($name) {
+ $this->curl(
+ 'POST',
+ '/window',
+ array('name' => $name));
+ return $this;
+ }
+
+ public function window($window_handle = 'current') {
+ $item = new WebDriverSimpleItem($this->url . '/window/' . $window_handle);
+ return $item->setMethods(array(
+ 'size' => array('GET', 'POST'),
+ 'position' => array('GET', 'POST'),
+ ));
+ }
+
public function touch() {
$item = new WebDriverSimpleItem($this->url . '/touch');
return $item->setMethods(array(
Please sign in to comment.
Something went wrong with that request. Please try again.