Skip to content
This repository
Browse code

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
Source Rendered
@@ -50,8 +50,9 @@ Each command is just the name of a function call, and each additional path is ju
50 50
51 51 $session->orientation();
52 52
53   -## A few Element/Cookie/Session convenience exceptions.
  53 +## A few Element/Cookie/Session/Window convenience exceptions.
54 54
55 55 * To find elements, use element($using, $value) and elements($using, $value), where $using is the locator strategy ('xpath', 'id', 'name', etc)
56 56 * Use getAllCookies(), setCookie($cookie_json), deleteAllCookies(), and deleteCookie($name)
  57 +* To focus a window, use focusWindow($name)
57 58 * Visit pages with open(), close the browser window with close()
7 WebDriver.php
@@ -34,4 +34,11 @@ public function session($browser = 'firefox',
34 34
35 35 return new WebDriverSession($results['info']['url']);
36 36 }
  37 +
  38 + // TODO(jubishop): Create WebDriverSession instances
  39 + public function sessions() {
  40 + return $this->curl(
  41 + 'GET',
  42 + '/sessions');
  43 + }
37 44 }
68 WebDriverBase.php
@@ -15,75 +15,75 @@
15 15
16 16 abstract class WebDriverBase {
17 17
18   - public static function throwException($status_code, $message) {
  18 + public static function throwException($status_code, $message, $results) {
19 19 switch ($status_code) {
20 20 case 0:
21 21 // Success
22 22 break;
23 23 case 1:
24   - throw new IndexOutOfBoundsWebDriverError($message);
  24 + throw new IndexOutOfBoundsWebDriverError($message, $results);
25 25 case 2:
26   - throw new NoCollectionWebDriverError($message);
  26 + throw new NoCollectionWebDriverError($message, $results);
27 27 case 3:
28   - throw new NoStringWebDriverError($message);
  28 + throw new NoStringWebDriverError($message, $results);
29 29 case 4:
30   - throw new NoStringLengthWebDriverError($message);
  30 + throw new NoStringLengthWebDriverError($message, $results);
31 31 case 5:
32   - throw new NoStringWrapperWebDriverError($message);
  32 + throw new NoStringWrapperWebDriverError($message, $results);
33 33 case 6:
34   - throw new NoSuchDriverWebDriverError($message);
  34 + throw new NoSuchDriverWebDriverError($message, $results);
35 35 case 7:
36   - throw new NoSuchElementWebDriverError($message);
  36 + throw new NoSuchElementWebDriverError($message, $results);
37 37 case 8:
38   - throw new NoSuchFrameWebDriverError($message);
  38 + throw new NoSuchFrameWebDriverError($message, $results);
39 39 case 9:
40   - throw new UnknownCommandWebDriverError($message);
  40 + throw new UnknownCommandWebDriverError($message, $results);
41 41 case 10:
42   - throw new ObsoleteElementWebDriverError($message);
  42 + throw new ObsoleteElementWebDriverError($message, $results);
43 43 case 11:
44   - throw new ElementNotDisplayedWebDriverError($message);
  44 + throw new ElementNotDisplayedWebDriverError($message, $results);
45 45 case 12:
46   - throw new InvalidElementStateWebDriverError($message);
  46 + throw new InvalidElementStateWebDriverError($message, $results);
47 47 case 13:
48   - throw new UnhandledWebDriverError($message);
  48 + throw new UnhandledWebDriverError($message, $results);
49 49 case 14:
50   - throw new ExpectedWebDriverError($message);
  50 + throw new ExpectedWebDriverError($message, $results);
51 51 case 15:
52   - throw new ElementNotSelectableWebDriverError($message);
  52 + throw new ElementNotSelectableWebDriverError($message, $results);
53 53 case 16:
54   - throw new NoSuchDocumentWebDriverError($message);
  54 + throw new NoSuchDocumentWebDriverError($message, $results);
55 55 case 17:
56   - throw new UnexpectedJavascriptWebDriverError($message);
  56 + throw new UnexpectedJavascriptWebDriverError($message, $results);
57 57 case 18:
58   - throw new NoScriptResultWebDriverError($message);
  58 + throw new NoScriptResultWebDriverError($message, $results);
59 59 case 19:
60   - throw new XPathLookupWebDriverError($message);
  60 + throw new XPathLookupWebDriverError($message, $results);
61 61 case 20:
62   - throw new NoSuchCollectionWebDriverError($message);
  62 + throw new NoSuchCollectionWebDriverError($message, $results);
63 63 case 21:
64   - throw new TimeOutWebDriverError($message);
  64 + throw new TimeOutWebDriverError($message, $results);
65 65 case 22:
66   - throw new NullPointerWebDriverError($message);
  66 + throw new NullPointerWebDriverError($message, $results);
67 67 case 23:
68   - throw new NoSuchWindowWebDriverError($message);
  68 + throw new NoSuchWindowWebDriverError($message, $results);
69 69 case 24:
70   - throw new InvalidCookieDomainWebDriverError($message);
  70 + throw new InvalidCookieDomainWebDriverError($message, $results);
71 71 case 25:
72   - throw new UnableToSetCookieWebDriverError($message);
  72 + throw new UnableToSetCookieWebDriverError($message, $results);
73 73 case 26:
74   - throw new UnexpectedAlertOpenWebDriverError($message);
  74 + throw new UnexpectedAlertOpenWebDriverError($message, $results);
75 75 case 27:
76   - throw new NoAlertOpenWebDriverError($message);
  76 + throw new NoAlertOpenWebDriverError($message, $results);
77 77 case 28:
78   - throw new ScriptTimeoutWebDriverError($message);
  78 + throw new ScriptTimeoutWebDriverError($message, $results);
79 79 case 29:
80   - throw new InvalidElementCoordinatesWebDriverError($message);
  80 + throw new InvalidElementCoordinatesWebDriverError($message, $results);
81 81 case 30:
82   - throw new IMENotAvailableWebDriverError($message);
  82 + throw new IMENotAvailableWebDriverError($message, $results);
83 83 case 31:
84   - throw new IMEEngineActivationFailedWebDriverError($message);
  84 + throw new IMEEngineActivationFailedWebDriverError($message, $results);
85 85 case 32:
86   - throw new InvalidSelectorWebDriverError($message);
  86 + throw new InvalidSelectorWebDriverError($message, $results);
87 87 }
88 88 }
89 89
@@ -174,7 +174,7 @@ protected function curl($http_method,
174 174 $message = $value['message'];
175 175 }
176 176
177   - self::throwException($results['status'], $message);
  177 + self::throwException($results['status'], $message, $results);
178 178
179 179 return array('value' => $value, 'info' => $info);
180 180 }
3  WebDriverContainer.php
@@ -27,7 +27,8 @@ public function element($using, $value) {
27 27 sprintf(
28 28 'Element not found with %s, %s',
29 29 $using,
30   - $value) . "\n\n" . $e->getMessage());
  30 + $value) . "\n\n" . $e->getMessage(),
  31 + $e->getResults());
31 32 }
32 33
33 34 return $this->webDriverElement($results['value']);
14 WebDriverExceptions.php
@@ -15,7 +15,19 @@
15 15
16 16 final class WebDriverCurlException extends Exception {} // When curls fail
17 17
18   -abstract class WebDriverException extends Exception {}
  18 +abstract class WebDriverException extends Exception {
  19 + private $results;
  20 +
  21 + public function __construct($message, $results = null) {
  22 + parent::__construct($message);
  23 + $this->results = $results;
  24 + }
  25 +
  26 + public function getResults() {
  27 + return $this->results;
  28 + }
  29 +}
  30 +
19 31 class IndexOutOfBoundsWebDriverError extends WebDriverException {} // 1
20 32 class NoCollectionWebDriverError extends WebDriverException {} // 2
21 33 class NoStringWebDriverError extends WebDriverException {} // 3
19 WebDriverSession.php
@@ -29,7 +29,7 @@ protected function methods() {
29 29 'window' => array('POST', 'DELETE'),
30 30 'source' => 'GET',
31 31 'title' => 'GET',
32   - 'modifier' => 'POST',
  32 + 'keys' => 'POST',
33 33 'orientation' => array('GET', 'POST'),
34 34 'alert_text' => array('GET', 'POST'),
35 35 'accept_alert' => 'POST',
@@ -100,6 +100,23 @@ public function ime() {
100 100 ));
101 101 }
102 102
  103 + // /session/:sessionId/window (POST)
  104 + public function focusWindow($name) {
  105 + $this->curl(
  106 + 'POST',
  107 + '/window',
  108 + array('name' => $name));
  109 + return $this;
  110 + }
  111 +
  112 + public function window($window_handle = 'current') {
  113 + $item = new WebDriverSimpleItem($this->url . '/window/' . $window_handle);
  114 + return $item->setMethods(array(
  115 + 'size' => array('GET', 'POST'),
  116 + 'position' => array('GET', 'POST'),
  117 + ));
  118 + }
  119 +
103 120 public function touch() {
104 121 $item = new WebDriverSimpleItem($this->url . '/touch');
105 122 return $item->setMethods(array(

0 comments on commit 9d23692

Please sign in to comment.
Something went wrong with that request. Please try again.