From e8de2e8155ea4da398f923fea4e9f9eec7bf03ac Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Tue, 22 Nov 2011 10:46:19 -0500 Subject: [PATCH 1/4] use single quotes to clear warning in Zend Studio about invalid escape characters --- WebDriver.php | 112 +++++++++++++++++++++---------------------- WebDriver/Driver.php | 2 +- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/WebDriver.php b/WebDriver.php index 43a35c4..35c73d5 100644 --- a/WebDriver.php +++ b/WebDriver.php @@ -6,62 +6,62 @@ class WebDriver { // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value // Example: $my_web_element->send_keys(WebDriver::ReturnKey()); private static $keys = array( - 'NullKey' => "\uE000", - 'CancelKey' => "\uE001", - 'HelpKey' => "\uE002", - 'BackspaceKey' => "\uE003", - 'TabKey' => "\uE004", - 'ClearKey' => "\uE005", - 'ReturnKey' => "\uE006", - 'EnterKey' => "\uE007", - 'ShiftKey' => "\uE008", - 'ControlKey' => "\uE009", - 'AltKey' => "\uE00A", - 'PauseKey' => "\uE00B", - 'EscapeKey' => "\uE00C", - 'SpaceKey' => "\uE00D", - 'PageUpKey' => "\uE00E", - 'PageDownKey' => "\uE00F", - 'EndKey' => "\uE010", - 'HomeKey' => "\uE011", - 'LeftArrowKey' => "\uE012", - 'UpArrowKey' => "\uE013", - 'RightArrowKey' => "\uE014", - 'DownArrowKey' => "\uE015", - 'InsertKey' => "\uE016", - 'DeleteKey' => "\uE017", - 'SemicolonKey' => "\uE018", - 'EqualsKey' => "\uE019", - 'Numpad0Key' => "\uE01A", - 'Numpad1Key' => "\uE01B", - 'Numpad2Key' => "\uE01C", - 'Numpad3Key' => "\uE01D", - 'Numpad4Key' => "\uE01E", - 'Numpad5Key' => "\uE01F", - 'Numpad6Key' => "\uE020", - 'Numpad7Key' => "\uE021", - 'Numpad8Key' => "\uE022", - 'Numpad9Key' => "\uE023", - 'MultiplyKey' => "\uE024", - 'AddKey' => "\uE025", - 'SeparatorKey' => "\uE026", - 'SubtractKey' => "\uE027", - 'DecimalKey' => "\uE028", - 'DivideKey' => "\uE029", - 'F1Key' => "\uE031", - 'F2Key' => "\uE032", - 'F3Key' => "\uE033", - 'F4Key' => "\uE034", - 'F5Key' => "\uE035", - 'F6Key' => "\uE036", - 'F7Key' => "\uE037", - 'F8Key' => "\uE038", - 'F9Key' => "\uE039", - 'F10Key' => "\uE03A", - 'F11Key' => "\uE03B", - 'F12Key' => "\uE03C", - 'CommandKey' => "\uE03D", - 'MetaKey' => "\uE03D", + 'NullKey' => '\uE000', + 'CancelKey' => '\uE001', + 'HelpKey' => '\uE002', + 'BackspaceKey' => '\uE003', + 'TabKey' => '\uE004', + 'ClearKey' => '\uE005', + 'ReturnKey' => '\uE006', + 'EnterKey' => '\uE007', + 'ShiftKey' => '\uE008', + 'ControlKey' => '\uE009', + 'AltKey' => '\uE00A', + 'PauseKey' => '\uE00B', + 'EscapeKey' => '\uE00C', + 'SpaceKey' => '\uE00D', + 'PageUpKey' => '\uE00E', + 'PageDownKey' => '\uE00F', + 'EndKey' => '\uE010', + 'HomeKey' => '\uE011', + 'LeftArrowKey' => '\uE012', + 'UpArrowKey' => '\uE013', + 'RightArrowKey' => '\uE014', + 'DownArrowKey' => '\uE015', + 'InsertKey' => '\uE016', + 'DeleteKey' => '\uE017', + 'SemicolonKey' => '\uE018', + 'EqualsKey' => '\uE019', + 'Numpad0Key' => '\uE01A', + 'Numpad1Key' => '\uE01B', + 'Numpad2Key' => '\uE01C', + 'Numpad3Key' => '\uE01D', + 'Numpad4Key' => '\uE01E', + 'Numpad5Key' => '\uE01F', + 'Numpad6Key' => '\uE020', + 'Numpad7Key' => '\uE021', + 'Numpad8Key' => '\uE022', + 'Numpad9Key' => '\uE023', + 'MultiplyKey' => '\uE024', + 'AddKey' => '\uE025', + 'SeparatorKey' => '\uE026', + 'SubtractKey' => '\uE027', + 'DecimalKey' => '\uE028', + 'DivideKey' => '\uE029', + 'F1Key' => '\uE031', + 'F2Key' => '\uE032', + 'F3Key' => '\uE033', + 'F4Key' => '\uE034', + 'F5Key' => '\uE035', + 'F6Key' => '\uE036', + 'F7Key' => '\uE037', + 'F8Key' => '\uE038', + 'F9Key' => '\uE039', + 'F10Key' => '\uE03A', + 'F11Key' => '\uE03B', + 'F12Key' => '\uE03C', + 'CommandKey' => '\uE03D', + 'MetaKey' => '\uE03D', ); public static function __callStatic($name, $arguments) { diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index df0f3bd..2be9ffd 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -39,7 +39,7 @@ protected function __construct($server_url, $capabilities) { $response = $this->execute("POST", "/session", $payload); // Parse out session id - preg_match("/\nLocation:.*\/(.*)\n/", $response['header'], $matches); + preg_match('/\nLocation:.*\/(.*)\n/', $response['header'], $matches); if (!empty($response['body'])) { $additional_info = $response['body']; } else if (!empty($response['header'])) { From d9cfebccd3cb426873ceaa1e5d0f629a3a071a32 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Tue, 22 Nov 2011 10:51:35 -0500 Subject: [PATCH 2/4] send_modifier is scoped in $this --- WebDriver/Driver.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index 2be9ffd..36e9061 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -437,14 +437,14 @@ private function send_modifier($modifier_code, $is_down) { ); $this->execute("POST", "/session/:sessionId/modifier", $payload); } - public function ctrl_down() { send_modifier("U+E009", true); } - public function ctrl_up() { send_modifier("U+E009", false); } - public function shift_down() { send_modifier("U+E008", true); } - public function shift_up() { send_modifier("U+E008", false); } - public function alt_down() { send_modifier("U+E00A", true); } - public function alt_up() { send_modifier("U+E00A", false); } - public function command_down() { send_modifier("U+E03D", true); } - public function command_up() { send_modifier("U+E03D", false); } + public function ctrl_down() { $this->send_modifier("U+E009", true); } + public function ctrl_up() { $this->send_modifier("U+E009", false); } + public function shift_down() { $this->send_modifier("U+E008", true); } + public function shift_up() { $this->send_modifier("U+E008", false); } + public function alt_down() { $this->send_modifier("U+E00A", true); } + public function alt_up() { $this->send_modifier("U+E00A", false); } + public function command_down() { $this->send_modifier("U+E03D", true); } + public function command_up() { $this->send_modifier("U+E03D", false); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/orientation // Not supported as of Selenium 2.0b3 From e8a03d8218cbbb017d0e5176ff165d823cf568d8 Mon Sep 17 00:00:00 2001 From: kdebisschop Date: Tue, 22 Nov 2011 12:40:12 -0500 Subject: [PATCH 3/4] make setters chainable --- WebDriver/Driver.php | 61 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index 36e9061..932ffbe 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -290,6 +290,7 @@ public function get_alert_text() { public function set_async_timeout($milliseconds) { $payload = array("ms" => $milliseconds); $this->execute("POST", "/session/:sessionId/timeouts/async_script", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/timeouts/implicit_wait @@ -297,27 +298,32 @@ public function set_implicit_wait($milliseconds) { WebDriver::$ImplicitWaitMS = $milliseconds; $payload = array("ms" => $milliseconds); $this->execute("POST", "/session/:sessionId/timeouts/implicit_wait", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/url public function load($url) { $payload = array("url" => $url); $this->execute("POST", "/session/:sessionId/url", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/forward public function go_forward() { $this->execute("POST", "/session/:sessionId/forward"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/back public function go_back() { $this->execute("POST", "/session/:sessionId/back"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/refresh public function reload() { $this->execute("POST", "/session/:sessionId/refresh"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window @@ -344,24 +350,28 @@ public function select_window($window_title, $ie_hash = '') { // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window public function close_window() { $this->execute("DELETE", "/session/:sessionId/window"); + return $this; } public function maximize_window() { $this->execute_js_sync("window.moveTo(0,0)"); $this->execute_js_sync("window.resizeTo(screen.width,screen.height)"); $this->execute_js_sync("window.focus()"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/ime/deactivate // Not supported as of Selenium 2.0b3 public function deactivate_ime() { $this->execute("POST", "/session/:sessionId/ime/deactivate"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/ime/activate // Not supported as of Selenium 2.0b3 public function activate_ime() { $this->execute("POST", "/session/:sessionId/ime/activate"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/frame @@ -371,6 +381,7 @@ public function select_frame($identifier = null) { } $payload = array("id" => $identifier); $this->execute("POST", "/session/:sessionId/frame", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie @@ -392,16 +403,19 @@ public function set_cookie($name, $value, $path = null, $domain = null, $secure $payload['cookie']['expiry'] = $expiry; } $this->execute("POST", "/session/:sessionId/cookie", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie public function delete_all_cookies() { $this->execute("DELETE", "/session/:sessionId/cookie"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie/:name public function delete_cookie($name) { $this->execute("DELETE", "/session/:sessionId/cookie/" . $name); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute @@ -427,6 +441,7 @@ public function execute_js_async($javascript, $arguments = array()) { public function set_input_speed($speed) { $payload = array("speed" => $speed); $this->execute("POST", "/session/:sessionId/speed", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/modifier @@ -436,24 +451,26 @@ private function send_modifier($modifier_code, $is_down) { 'isdown' => $is_down ); $this->execute("POST", "/session/:sessionId/modifier", $payload); + return $this; } - public function ctrl_down() { $this->send_modifier("U+E009", true); } - public function ctrl_up() { $this->send_modifier("U+E009", false); } - public function shift_down() { $this->send_modifier("U+E008", true); } - public function shift_up() { $this->send_modifier("U+E008", false); } - public function alt_down() { $this->send_modifier("U+E00A", true); } - public function alt_up() { $this->send_modifier("U+E00A", false); } - public function command_down() { $this->send_modifier("U+E03D", true); } - public function command_up() { $this->send_modifier("U+E03D", false); } + public function ctrl_down() { return $this->send_modifier("U+E009", true); } + public function ctrl_up() { return $this->send_modifier("U+E009", false); } + public function shift_down() { return $this->send_modifier("U+E008", true); } + public function shift_up() { return $this->send_modifier("U+E008", false); } + public function alt_down() { return $this->send_modifier("U+E00A", true); } + public function alt_up() { return $this->send_modifier("U+E00A", false); } + public function command_down() { return $this->send_modifier("U+E03D", true); } + public function command_up() { return $this->send_modifier("U+E03D", false); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/orientation // Not supported as of Selenium 2.0b3 private function set_orientation($new_orientation) { $payload = array("orientation", $new_orientation); $this->execute("POST", "/session/:sessionId/orientation", $payload); + return $this; } - public function rotate_landscape() { $this->set_orientation("LANDSCAPE"); } - public function rotate_portrait() { $this->set_orientation("PORTRAIT"); } + public function rotate_landscape() { return $this->set_orientation("LANDSCAPE"); } + public function rotate_portrait() { return $this->set_orientation("PORTRAIT"); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto public function move_cursor($right, $down) { @@ -462,6 +479,7 @@ public function move_cursor($right, $down) { "yoffset" => $down ); $this->execute("POST", "/session/:sessionId/moveto", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/click @@ -469,57 +487,66 @@ private function click_mouse($button) { $payload = array("button" => $button); $this->execute("POST", "/session/:sessionId/click", $payload); } - public function click() { $this->click_mouse(0); } - public function middle_click() { $this->click_mouse(1); } - public function right_click() { $this->click_mouse(2); } + public function click() { return $this->click_mouse(0); } + public function middle_click() { return $this->click_mouse(1); } + public function right_click() { return $this->click_mouse(2); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttondown public function click_and_hold() { $this->execute("POST", "/session/:sessionId/buttondown"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttonup public function release_click() { $this->execute("POST", "/session/:sessionId/buttonup"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/doubleclick public function double_click() { $this->execute("POST", "/session/:sessionId/doubleclick"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/alert_text public function type_alert($text) { $payload = array("keysToSend" => $text); $this->execute("POST", "/session/:sessionId/alert_text", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/accept_alert public function accept_alert() { $this->execute("POST", "/session/:sessionId/accept_alert"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/dismiss_alert public function dismiss_alert() { $this->execute("POST", "/session/:sessionId/dismiss_alert"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/click public function single_tap($element_id) { $payload = array("element" => $element_id); $this->execute("POST", "/session/:sessionId/touch/click", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/doubleclick public function double_tap($element_id) { $payload = array("element" => $element_id); $this->execute("POST", "/session/:sessionId/touch/doubleclick", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/longclick public function long_tap($element_id) { $payload = array("element" => $element_id); $this->execute("POST", "/session/:sessionId/touch/longclick", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/down @@ -529,6 +556,7 @@ public function touch_down($x_coordinate, $y_coordinate) { "y" => $y_coordinate, ); $this->execute("POST", "/session/:sessionId/touch/down", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/up @@ -538,6 +566,7 @@ public function touch_up($x_coordinate, $y_coordinate) { "y" => $y_coordinate, ); $this->execute("POST", "/session/:sessionId/touch/up", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/move @@ -547,6 +576,7 @@ public function touch_move($x_coordinate, $y_coordinate) { "y" => $y_coordinate, ); $this->execute("POST", "/session/:sessionId/touch/move", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/scroll @@ -557,6 +587,7 @@ public function touch_scroll_at($start_element_id, $pixels_offset_x, $pixels_off "yOffset" => $pixels_offset_y, ); $this->execute("POST", "/session/:sessionId/touch/scroll", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/scroll @@ -566,6 +597,7 @@ public function touch_scroll($pixels_offset_x, $pixels_offset_y) { "yOffset" => $pixels_offset_y, ); $this->execute("POST", "/session/:sessionId/touch/scroll", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#session/:sessionId/touch/flick @@ -577,6 +609,7 @@ public function touch_flick_at($start_element_id, $pixels_offset_x, $pixels_offs "speed" => $pixels_per_second, ); $this->execute("POST", "/session/:sessionId/touch/flick", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#session/:sessionId/touch/flick @@ -586,6 +619,7 @@ public function touch_flick($pixels_per_second_x, $pixels_per_second_y) { "ySpeed" => $pixels_per_second_y, ); $this->execute("POST", "/session/:sessionId/touch/flick", $payload); + return $this; } // See https://saucelabs.com/docs/sauce-ondemand#alternative-annotation-methods @@ -595,6 +629,7 @@ public function set_sauce_context($field, $value) { $url_parts = parse_url($this->server_url); WebDriver::Curl("PUT", "http://" . $url_parts['user'] . ":" . $url_parts['pass'] . "@saucelabs.com/rest/v1/" . $url_parts['user'] . "/jobs/" . $this->session_id, $payload); } + return $this; } /******************************************************************** From 10c237babd1efa4c40207bb47860218cf093525a Mon Sep 17 00:00:00 2001 From: kdebisschop Date: Tue, 22 Nov 2011 12:43:59 -0500 Subject: [PATCH 4/4] make setters chainable --- WebDriver/Driver.php | 61 +++++++++++++++++++++++++++++++--------- WebDriver/WebElement.php | 13 +++++++++ 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index 36e9061..932ffbe 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -290,6 +290,7 @@ public function get_alert_text() { public function set_async_timeout($milliseconds) { $payload = array("ms" => $milliseconds); $this->execute("POST", "/session/:sessionId/timeouts/async_script", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/timeouts/implicit_wait @@ -297,27 +298,32 @@ public function set_implicit_wait($milliseconds) { WebDriver::$ImplicitWaitMS = $milliseconds; $payload = array("ms" => $milliseconds); $this->execute("POST", "/session/:sessionId/timeouts/implicit_wait", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/url public function load($url) { $payload = array("url" => $url); $this->execute("POST", "/session/:sessionId/url", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/forward public function go_forward() { $this->execute("POST", "/session/:sessionId/forward"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/back public function go_back() { $this->execute("POST", "/session/:sessionId/back"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/refresh public function reload() { $this->execute("POST", "/session/:sessionId/refresh"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window @@ -344,24 +350,28 @@ public function select_window($window_title, $ie_hash = '') { // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window public function close_window() { $this->execute("DELETE", "/session/:sessionId/window"); + return $this; } public function maximize_window() { $this->execute_js_sync("window.moveTo(0,0)"); $this->execute_js_sync("window.resizeTo(screen.width,screen.height)"); $this->execute_js_sync("window.focus()"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/ime/deactivate // Not supported as of Selenium 2.0b3 public function deactivate_ime() { $this->execute("POST", "/session/:sessionId/ime/deactivate"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/ime/activate // Not supported as of Selenium 2.0b3 public function activate_ime() { $this->execute("POST", "/session/:sessionId/ime/activate"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/frame @@ -371,6 +381,7 @@ public function select_frame($identifier = null) { } $payload = array("id" => $identifier); $this->execute("POST", "/session/:sessionId/frame", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie @@ -392,16 +403,19 @@ public function set_cookie($name, $value, $path = null, $domain = null, $secure $payload['cookie']['expiry'] = $expiry; } $this->execute("POST", "/session/:sessionId/cookie", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie public function delete_all_cookies() { $this->execute("DELETE", "/session/:sessionId/cookie"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie/:name public function delete_cookie($name) { $this->execute("DELETE", "/session/:sessionId/cookie/" . $name); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute @@ -427,6 +441,7 @@ public function execute_js_async($javascript, $arguments = array()) { public function set_input_speed($speed) { $payload = array("speed" => $speed); $this->execute("POST", "/session/:sessionId/speed", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/modifier @@ -436,24 +451,26 @@ private function send_modifier($modifier_code, $is_down) { 'isdown' => $is_down ); $this->execute("POST", "/session/:sessionId/modifier", $payload); + return $this; } - public function ctrl_down() { $this->send_modifier("U+E009", true); } - public function ctrl_up() { $this->send_modifier("U+E009", false); } - public function shift_down() { $this->send_modifier("U+E008", true); } - public function shift_up() { $this->send_modifier("U+E008", false); } - public function alt_down() { $this->send_modifier("U+E00A", true); } - public function alt_up() { $this->send_modifier("U+E00A", false); } - public function command_down() { $this->send_modifier("U+E03D", true); } - public function command_up() { $this->send_modifier("U+E03D", false); } + public function ctrl_down() { return $this->send_modifier("U+E009", true); } + public function ctrl_up() { return $this->send_modifier("U+E009", false); } + public function shift_down() { return $this->send_modifier("U+E008", true); } + public function shift_up() { return $this->send_modifier("U+E008", false); } + public function alt_down() { return $this->send_modifier("U+E00A", true); } + public function alt_up() { return $this->send_modifier("U+E00A", false); } + public function command_down() { return $this->send_modifier("U+E03D", true); } + public function command_up() { return $this->send_modifier("U+E03D", false); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/orientation // Not supported as of Selenium 2.0b3 private function set_orientation($new_orientation) { $payload = array("orientation", $new_orientation); $this->execute("POST", "/session/:sessionId/orientation", $payload); + return $this; } - public function rotate_landscape() { $this->set_orientation("LANDSCAPE"); } - public function rotate_portrait() { $this->set_orientation("PORTRAIT"); } + public function rotate_landscape() { return $this->set_orientation("LANDSCAPE"); } + public function rotate_portrait() { return $this->set_orientation("PORTRAIT"); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto public function move_cursor($right, $down) { @@ -462,6 +479,7 @@ public function move_cursor($right, $down) { "yoffset" => $down ); $this->execute("POST", "/session/:sessionId/moveto", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/click @@ -469,57 +487,66 @@ private function click_mouse($button) { $payload = array("button" => $button); $this->execute("POST", "/session/:sessionId/click", $payload); } - public function click() { $this->click_mouse(0); } - public function middle_click() { $this->click_mouse(1); } - public function right_click() { $this->click_mouse(2); } + public function click() { return $this->click_mouse(0); } + public function middle_click() { return $this->click_mouse(1); } + public function right_click() { return $this->click_mouse(2); } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttondown public function click_and_hold() { $this->execute("POST", "/session/:sessionId/buttondown"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttonup public function release_click() { $this->execute("POST", "/session/:sessionId/buttonup"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/doubleclick public function double_click() { $this->execute("POST", "/session/:sessionId/doubleclick"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/alert_text public function type_alert($text) { $payload = array("keysToSend" => $text); $this->execute("POST", "/session/:sessionId/alert_text", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/accept_alert public function accept_alert() { $this->execute("POST", "/session/:sessionId/accept_alert"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/dismiss_alert public function dismiss_alert() { $this->execute("POST", "/session/:sessionId/dismiss_alert"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/click public function single_tap($element_id) { $payload = array("element" => $element_id); $this->execute("POST", "/session/:sessionId/touch/click", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/doubleclick public function double_tap($element_id) { $payload = array("element" => $element_id); $this->execute("POST", "/session/:sessionId/touch/doubleclick", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/longclick public function long_tap($element_id) { $payload = array("element" => $element_id); $this->execute("POST", "/session/:sessionId/touch/longclick", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/down @@ -529,6 +556,7 @@ public function touch_down($x_coordinate, $y_coordinate) { "y" => $y_coordinate, ); $this->execute("POST", "/session/:sessionId/touch/down", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/up @@ -538,6 +566,7 @@ public function touch_up($x_coordinate, $y_coordinate) { "y" => $y_coordinate, ); $this->execute("POST", "/session/:sessionId/touch/up", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/move @@ -547,6 +576,7 @@ public function touch_move($x_coordinate, $y_coordinate) { "y" => $y_coordinate, ); $this->execute("POST", "/session/:sessionId/touch/move", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/scroll @@ -557,6 +587,7 @@ public function touch_scroll_at($start_element_id, $pixels_offset_x, $pixels_off "yOffset" => $pixels_offset_y, ); $this->execute("POST", "/session/:sessionId/touch/scroll", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/scroll @@ -566,6 +597,7 @@ public function touch_scroll($pixels_offset_x, $pixels_offset_y) { "yOffset" => $pixels_offset_y, ); $this->execute("POST", "/session/:sessionId/touch/scroll", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#session/:sessionId/touch/flick @@ -577,6 +609,7 @@ public function touch_flick_at($start_element_id, $pixels_offset_x, $pixels_offs "speed" => $pixels_per_second, ); $this->execute("POST", "/session/:sessionId/touch/flick", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#session/:sessionId/touch/flick @@ -586,6 +619,7 @@ public function touch_flick($pixels_per_second_x, $pixels_per_second_y) { "ySpeed" => $pixels_per_second_y, ); $this->execute("POST", "/session/:sessionId/touch/flick", $payload); + return $this; } // See https://saucelabs.com/docs/sauce-ondemand#alternative-annotation-methods @@ -595,6 +629,7 @@ public function set_sauce_context($field, $value) { $url_parts = parse_url($this->server_url); WebDriver::Curl("PUT", "http://" . $url_parts['user'] . ":" . $url_parts['pass'] . "@saucelabs.com/rest/v1/" . $url_parts['user'] . "/jobs/" . $this->session_id, $payload); } + return $this; } /******************************************************************** diff --git a/WebDriver/WebElement.php b/WebDriver/WebElement.php index 534d78e..6647cce 100644 --- a/WebDriver/WebElement.php +++ b/WebDriver/WebElement.php @@ -157,27 +157,32 @@ public function get_options() { // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/click public function click() { $this->execute("POST", "/click"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/submit public function submit() { $this->execute("POST", "/submit"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/clear public function clear() { $this->execute("POST", "/clear"); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/hover public function hover() { // $this->execute("POST", "/hover"); // Not supported as of Selenium 2.0rc3 $this->move_cursor_to_center(); // Workaround until /hover is implemented + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/selected public function select() { $this->click(); // POST /session/:sessionId/element/:id/selected is deprecated as of Selenium 2.0.0 + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/toggle @@ -190,6 +195,7 @@ public function toggle() { public function send_keys($keys) { $payload = array("value" => preg_split('//u', $keys, -1, PREG_SPLIT_NO_EMPTY)); $this->execute("POST", "/value", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/drag @@ -199,12 +205,14 @@ public function drag_and_drop($pixels_right, $pixels_down) { "y" => $pixels_down ); $this->execute("POST", "/drag", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto public function move_cursor_to_center() { $payload = array("element" => $this->element_id); $this->driver->execute("POST", "/session/:sessionId/moveto", $payload); + return $this; } // See http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto @@ -215,6 +223,7 @@ public function move_cursor_relative($right, $down) { "yoffset" => $down, ); $this->driver->execute("POST", "/session/:sessionId/moveto", $payload); + return $this; } /******************************************************************** @@ -223,21 +232,25 @@ public function move_cursor_relative($right, $down) { public function select_label($label) { $this->get_next_element("//option[text()=" . WebDriver::QuoteXPath($label) . "]")->select(); + return $this; } public function select_value($value) { $this->get_next_element("//option[@value=" . WebDriver::QuoteXPath($value) . "]")->select(); + return $this; } // 1-based index public function select_index($index) { $this->get_next_element("//option[" . $index . "]")->select(); + return $this; } public function select_random() { $all_elements = $this->get_options(); $new_index = rand(1, count($all_elements)); $this->select_index($new_index); + return $this; } /********************************************************************