Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 01ed732

Browse files
committed
Implement various additional wire protocol commands.
Logging Orientation Equals ActiveElement
1 parent 3121f59 commit 01ed732

8 files changed

+110
-1
lines changed

lib/WebDriverCommandExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
interface WebDriverCommandExecutor {
2020

2121
// $command and $params will be merged to an command object in the future.
22-
public function execute($command, array $params);
22+
public function execute($command, array $params = array());
2323
}

lib/WebDriverOptions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,26 @@ public function timeouts() {
131131
public function window() {
132132
return new WebDriverWindow($this->executor);
133133
}
134+
135+
/**
136+
* Get the log for a given log type. Log buffer is reset after each request.
137+
*
138+
* @param The log type (https://code.google.com/p/selenium/wiki/JsonWireProtocol#Log_Type)
139+
* @return array The list of log entries.
140+
*/
141+
public function getLog($logType) {
142+
return $this->executor->execute('getLog', array(
143+
'type' => $logType
144+
));
145+
}
146+
147+
/**
148+
* Get available log types.
149+
*
150+
* @return array The list of available log types (https://code.google.com/p/selenium/wiki/JsonWireProtocol#Log_Type)
151+
*/
152+
public function getAvailableLogTypes() {
153+
return $this->executor->execute('getAvailableLogTypes');
154+
}
155+
134156
}

lib/WebDriverWindow.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,34 @@ public function setPosition(WebDriverPoint $position) {
106106
$this->executor->execute('setWindowPosition', $params);
107107
return $this;
108108
}
109+
110+
/**
111+
* Get the current browser orientation.
112+
*
113+
* @return string Either LANDSCAPE|PORTRAIT
114+
*/
115+
public function getScreenOrientation() {
116+
return $this->executor->execute('getScreenOrientation');
117+
}
118+
119+
120+
/**
121+
* Set the browser orientation. The orientation should either LANDSCAPE|PORTRAIT
122+
*
123+
* @param string $orientation
124+
* @return WebDriverWindow The instance.
125+
* @throws IndexOutOfBoundsWebDriverError
126+
*/
127+
public function setScreenOrientation($orientation) {
128+
129+
$orientation = strtoupper($orientation);
130+
if (!in_array($orientation, array('PORTRAIT', 'LANDSCAPE')))
131+
throw new IndexOutOfBoundsWebDriverError("Orientation must be either PORTRAIT, or LANDSCAPE");
132+
133+
$this->executor->execute('setScreenOrientation', array('orientation' => $orientation));
134+
135+
return $this;
136+
137+
}
138+
109139
}

lib/remote/HttpCommandExecutor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class HttpCommandExecutor implements WebDriverCommandExecutor {
3131
'deleteAllCookies' => array('method' => 'DELETE', 'url' => '/session/:sessionId/cookie'),
3232
'deleteCookie' => array('method' => 'DELETE', 'url' => '/session/:sessionId/cookie/:name'),
3333
'dismissAlert' => array('method' => 'POST', 'url' => '/session/:sessionId/dismiss_alert'),
34+
'elementEquals' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/equals/:other'),
3435
'elementFindElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/element'),
3536
'elementFindElements' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/elements'),
3637
'executeScript' => array('method' => 'POST', 'url' => '/session/:sessionId/execute'),
@@ -39,8 +40,10 @@ class HttpCommandExecutor implements WebDriverCommandExecutor {
3940
'focusFrame' => array('method' => 'POST', 'url' => '/session/:sessionId/frame'),
4041
'focusWindow' => array('method' => 'POST', 'url' => '/session/:sessionId/window'),
4142
'get' => array('method' => 'POST', 'url' => '/session/:sessionId/url'),
43+
'getActiveElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/active'),
4244
'getAlertText' => array('method' => 'GET', 'url' => '/session/:sessionId/alert_text'),
4345
'getAllCookies' => array('method' => 'GET', 'url' => '/session/:sessionId/cookie'),
46+
'getAvailableLogTypes' => array('method' => 'GET', 'url' => '/session/:sessionId/log/types'),
4447
'getCurrentURL' => array('method' => 'GET', 'url' => '/session/:sessionId/url'),
4548
'getCurrentWindowHandle' => array('method' => 'GET', 'url' => '/session/:sessionId/window_handle'),
4649
'getElementAttribute' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/attribute/:name'),
@@ -50,7 +53,9 @@ class HttpCommandExecutor implements WebDriverCommandExecutor {
5053
'getElementSize' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/size'),
5154
'getElementTagName' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/name'),
5255
'getElementText' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/text'),
56+
'getLog' => array('method' => 'POST', 'url' => '/session/:sessionId/log'),
5357
'getPageSource' => array('method' => 'GET', 'url' => '/session/:sessionId/source'),
58+
'getScreenOrientation' => array('method' => 'GET', 'url' => '/session/:sessionId/orientation'),
5459
'getSession' => array('method' => 'GET', 'url' => '/session/:sessionId'),
5560
'getTitle' => array('method' => 'GET', 'url' => '/session/:sessionId/title'),
5661
'getWindowHandles' => array('method' => 'GET', 'url' => '/session/:sessionId/window_handles'),
@@ -75,6 +80,7 @@ class HttpCommandExecutor implements WebDriverCommandExecutor {
7580
'sendKeysToAlert' => array('method' => 'POST', 'url' => '/session/:sessionId/alert_text'),
7681
'sendKeysToElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/value'),
7782
'setImplicitWaitTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts/implicit_wait'),
83+
'setScreenOrientation' => array('method' => 'POST', 'url' => '/session/:sessionId/orientation'),
7884
'setPageLoadTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts'),
7985
'setScriptTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts/async_script'),
8086
'setWindowPosition' => array('method' => 'POST', 'url' => '/session/:sessionId/window/:windowHandle/position'),

lib/remote/RemoteWebDriver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ public function action() {
276276
return new WebDriverActions($this);
277277
}
278278

279+
/**
280+
* Get the element on the page that currently has focus.
281+
*
282+
* @return WebDriverElement
283+
*/
284+
public function getActiveElement() {
285+
$response = $this->executor->execute('getActiveElement');
286+
return $this->newElement($response['ELEMENT']);
287+
}
288+
279289
/**
280290
* Return the WebDriverElement with the given id.
281291
*

lib/remote/RemoteWebElement.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ public function getID() {
280280
return $this->id;
281281
}
282282

283+
/**
284+
* Test if two element IDs refer to the same DOM element.
285+
*
286+
* @param WebDriverElement $other
287+
* @return boolean
288+
*/
289+
public function equals(WebDriverElement $other) {
290+
return $this->executor->execute('elementEquals', array(
291+
':id' => $this->id,
292+
':other' => $other->getID()
293+
));
294+
}
295+
283296
/**
284297
* Return the WebDriverElement with $id
285298
*

lib/support/events/EventFiringWebDriver.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ public function switchTo() {
294294
}
295295
}
296296

297+
/**
298+
* Get the element on the page that currently has focus.
299+
*
300+
* @return WebDriverElement
301+
*/
302+
public function getActiveElement() {
303+
try {
304+
return $this->driver->getActiveElement();
305+
} catch (WebDriverException $exception) {
306+
$this->dispatchOnException($exception);
307+
}
308+
}
309+
297310
private function dispatchOnException($exception) {
298311
$this->dispatch('onException', $exception, $this);
299312
throw $exception;

lib/support/events/EventFiringWebElement.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ public function getID() {
317317
}
318318
}
319319

320+
321+
/**
322+
* Test if two element IDs refer to the same DOM element.
323+
*
324+
* @param WebDriverElement $other
325+
* @return boolean
326+
*/
327+
public function equals(WebDriverElement $other) {
328+
try {
329+
return $this->element->equals($other);
330+
} catch (WebDriverException $exception) {
331+
$this->dispatchOnException($exception);
332+
}
333+
}
334+
320335
private function dispatchOnException($exception) {
321336
$this->dispatch(
322337
'onException',

0 commit comments

Comments
 (0)