PK k?VW W lib/WebDriverTargetLocator.phpnu W+A executor = $executor;
$this->driver = $driver;
}
/**
* Switch to the main document if the page contains iframes. Otherwise, switch
* to the first frame on the page.
*
* @return WebDriver The driver focused on the top window or the first frame.
*/
public function defaultContent() {
$this->executor->execute('focusFrame', array());
return $this->driver;
}
/**
* Switch to the iframe by its id or name.
*
* @return WebDriver The driver focused on the given frame.
*/
public function frame($id_or_name) {
$params = array('id' => (string)$id_or_name);
$this->executor->execute('focusFrame', $params);
return $this->driver;
}
/**
* Switch the focus to another window by its handle.
*
* @param string $handle The handle of the window to be focused on.
* @return WebDriver Tge driver focused on the given window.
* @see WebDriver::getWindowHandles
*/
public function window($handle) {
$params = array('name' => (string)$handle);
$this->executor->execute('focusWindow', $params);
return $this->driver;
}
/**
* Switch to the currently active modal dialog for this particular driver
* instance.
*
* @return WebDriverAlert
*/
public function alert() {
return new WebDriverAlert($this->executor);
}
}
PK k?Ve0Y lib/WebDriverNavigation.phpnu W+A executor = $executor;
}
/**
* Move back a single entry in the browser's history, if possible.
*
* @return WebDriverNavigation The instance.
*/
public function back() {
$this->executor->execute('goBack');
return $this;
}
/**
* Move forward a single entry in the browser's history, if possible.
*
* @return WebDriverNavigation The instance.
*/
public function forward() {
$this->executor->execute('goForward');
return $this;
}
/**
* Refresh the current page.
*
* @return WebDriverNavigation The instance.
*/
public function refresh() {
$this->executor->execute('refreshPage');
return $this;
}
/**
* Navigate to the given URL.
*
* @return WebDriverNavigation The instance.
*/
public function to($url) {
$params = array('url' => (string)$url);
$this->executor->execute('get', $params);
return $this;
}
}
PK k?VU lib/WebDriverSearchContext.phpnu W+A width = $width;
$this->height = $height;
}
/**
* Get the height.
*
* @return int The height.
*/
public function getHeight() {
return $this->height;
}
/**
* Get the width.
*
* @return int The width.
*/
public function getWidth() {
return $this->width;
}
/**
* Check whether the given dimension is the same as the instance.
*
* @param WebDriverDimension $dimension The dimension to be compared with.
* @return bool Whether the height and the width are the same as the
* instance.
*/
public function equals(WebDriverDimension $dimension) {
return $this->height === $dimension->getHeight() &&
$this->width === $dimension->getWidth();
}
}
PK k?V0ʱM M lib/WebDriverExceptions.phpnu W+A results = $results;
}
public function getResults() {
return $this->results;
}
public static function throwException($status_code, $message, $results) {
switch ($status_code) {
case 0:
// Success
break;
case 1:
throw new IndexOutOfBoundsWebDriverError($message, $results);
case 2:
throw new NoCollectionWebDriverError($message, $results);
case 3:
throw new NoStringWebDriverError($message, $results);
case 4:
throw new NoStringLengthWebDriverError($message, $results);
case 5:
throw new NoStringWrapperWebDriverError($message, $results);
case 6:
throw new NoSuchDriverWebDriverError($message, $results);
case 7:
throw new NoSuchElementWebDriverError($message, $results);
case 8:
throw new NoSuchFrameWebDriverError($message, $results);
case 9:
throw new UnknownCommandWebDriverError($message, $results);
case 10:
throw new ObsoleteElementWebDriverError($message, $results);
case 11:
throw new ElementNotDisplayedWebDriverError($message, $results);
case 12:
throw new InvalidElementStateWebDriverError($message, $results);
case 13:
throw new UnhandledWebDriverError($message, $results);
case 14:
throw new ExpectedWebDriverError($message, $results);
case 15:
throw new ElementNotSelectableWebDriverError($message, $results);
case 16:
throw new NoSuchDocumentWebDriverError($message, $results);
case 17:
throw new UnexpectedJavascriptWebDriverError($message, $results);
case 18:
throw new NoScriptResultWebDriverError($message, $results);
case 19:
throw new XPathLookupWebDriverError($message, $results);
case 20:
throw new NoSuchCollectionWebDriverError($message, $results);
case 21:
throw new TimeOutWebDriverError($message, $results);
case 22:
throw new NullPointerWebDriverError($message, $results);
case 23:
throw new NoSuchWindowWebDriverError($message, $results);
case 24:
throw new InvalidCookieDomainWebDriverError($message, $results);
case 25:
throw new UnableToSetCookieWebDriverError($message, $results);
case 26:
throw new UnexpectedAlertOpenWebDriverError($message, $results);
case 27:
throw new NoAlertOpenWebDriverError($message, $results);
case 28:
throw new ScriptTimeoutWebDriverError($message, $results);
case 29:
throw new InvalidElementCoordinatesWebDriverError($message, $results);
case 30:
throw new IMENotAvailableWebDriverError($message, $results);
case 31:
throw new IMEEngineActivationFailedWebDriverError($message, $results);
case 32:
throw new InvalidSelectorWebDriverError($message, $results);
case 33:
throw new SessionNotCreatedWebDriverError($message, $results);
case 34:
throw new MoveTargetOutOfBoundsWebDriverError($message, $results);
default:
throw new UnrecognizedWebDriverErrorWebDriverError($message, $results);
}
}
}
class IndexOutOfBoundsWebDriverError extends WebDriverException {} // 1
class NoCollectionWebDriverError extends WebDriverException {} // 2
class NoStringWebDriverError extends WebDriverException {} // 3
class NoStringLengthWebDriverError extends WebDriverException {} // 4
class NoStringWrapperWebDriverError extends WebDriverException {} // 5
class NoSuchDriverWebDriverError extends WebDriverException {} // 6
class NoSuchElementWebDriverError extends WebDriverException {} // 7
class NoSuchFrameWebDriverError extends WebDriverException {} // 8
class UnknownCommandWebDriverError extends WebDriverException {} // 9
class ObsoleteElementWebDriverError extends WebDriverException {} // 10
class ElementNotDisplayedWebDriverError extends WebDriverException {} // 11
class InvalidElementStateWebDriverError extends WebDriverException {} // 12
class UnhandledWebDriverError extends WebDriverException {} // 13
class ExpectedWebDriverError extends WebDriverException {} // 14
class ElementNotSelectableWebDriverError extends WebDriverException {} // 15
class NoSuchDocumentWebDriverError extends WebDriverException {} // 16
class UnexpectedJavascriptWebDriverError extends WebDriverException {} // 17
class NoScriptResultWebDriverError extends WebDriverException {} // 18
class XPathLookupWebDriverError extends WebDriverException {} // 19
class NoSuchCollectionWebDriverError extends WebDriverException {} // 20
class TimeOutWebDriverError extends WebDriverException {} // 21
class NullPointerWebDriverError extends WebDriverException {} // 22
class NoSuchWindowWebDriverError extends WebDriverException {} // 23
class InvalidCookieDomainWebDriverError extends WebDriverException {} // 24
class UnableToSetCookieWebDriverError extends WebDriverException {} // 25
class UnexpectedAlertOpenWebDriverError extends WebDriverException {} // 26
class NoAlertOpenWebDriverError extends WebDriverException {} // 27
class ScriptTimeoutWebDriverError extends WebDriverException {} // 28
class InvalidElementCoordinatesWebDriverError extends WebDriverException {}// 29
class IMENotAvailableWebDriverError extends WebDriverException {} // 30
class IMEEngineActivationFailedWebDriverError extends WebDriverException {}// 31
class InvalidSelectorWebDriverError extends WebDriverException {} // 32
class SessionNotCreatedWebDriverError extends WebDriverException {} // 33
class MoveTargetOutOfBoundsWebDriverError extends WebDriverException {} // 34
// Fallback
class UnrecognizedWebDriverErrorWebDriverError extends WebDriverException {}
class UnexpectedTagNameException extends WebDriverException {
public function __construct(
string $expected_tag_name,
string $actual_tag_name) {
parent::__construct(
sprintf(
"Element should have been \"%s\" but was \"%s\"",
$expected_tag_name, $actual_tag_name
)
);
}
}
class UnsupportedOperationException extends WebDriverException {}
PK k?V.Dt t lib/WebDriver.phpnu W+A wait(20, 1000)->until(
* WebDriverExpectedCondition::titleIs('WebDriver Page')
* );
*
* @return WebDriverWait
*/
public function wait(
$timeout_in_second = 30,
$interval_in_millisecond = 250);
/**
* An abstraction for managing stuff you would do in a browser menu. For
* example, adding and deleting cookies.
*
* @return WebDriverOptions
*/
public function manage();
/**
* An abstraction allowing the driver to access the browser's history and to
* navigate to a given URL.
*
* @return WebDriverNavigation
* @see WebDriverNavigation
*/
public function navigate();
/**
* Switch to a different window or frame.
*
* @return WebDriverTargetLocator
* @see WebDriverTargetLocator
*/
public function switchTo();
}
PK k?Vr~ǀ lib/WebDriverHasInputDevices.phpnu W+A driver = $driver;
$this->timeout = ($timeout_in_second) ? $timeout_in_second : 30;
$this->interval =
($interval_in_millisecond) ? $interval_in_millisecond : 250;
}
/**
* Calls the function provided with the driver as an argument until the return
* value is not falsey.
*
* @param (closure|WebDriverExpectedCondition)
* @return mixed The return value of $func_or_ec
*/
public function until($func_or_ec, $message = "") {
$end = time() + $this->timeout;
$last_exception = null;
while ($end > time()) {
try {
if ($func_or_ec instanceof WebDriverExpectedCondition) {
$ret_val = call_user_func($func_or_ec->getApply(), $this->driver);
} else {
$ret_val = call_user_func($func_or_ec, $this->driver);
}
if ($ret_val) {
return $ret_val;
}
} catch (NoSuchElementWebDriverError $e) {
$last_exception = $e;
}
usleep($this->interval * 1000);
}
if ($last_exception) {
throw $last_exception;
}
throw new TimeOutWebDriverError($message);
}
}
PK k?V_\ \ lib/WebDriverBy.phpnu W+A mechanism = $mechanism;
$this->value = $value;
}
public function getMechanism() {
return $this->mechanism;
}
public function getValue() {
return $this->value;
}
/**
* Locates elements whose class name contains the search value; compound class
* names are not permitted.
*
* @return WebDriverBy
*/
public static function className($class_name) {
return new WebDriverBy('class name', $class_name);
}
/**
* Locates elements matching a CSS selector.
*
* @return WebDriverBy
*/
public static function cssSelector($css_selector) {
return new WebDriverBy('css selector', $css_selector);
}
/**
* Locates elements whose ID attribute matches the search value.
*
* @return WebDriverBy
*/
public static function id($id) {
return new WebDriverBy('id', $id);
}
/**
* Locates elements whose NAME attribute matches the search value.
*/
public static function name($name) {
return new WebDriverBy('name', $name);
}
/**
* Locates anchor elements whose visible text matches the search value.
*
* @return WebDriverBy
*/
public static function linkText($link_text) {
return new WebDriverBy('link text', $link_text);
}
/**
* Locates anchor elements whose visible text partially matches the search
* value.
*
* @return WebDriverBy
*/
public static function partialLinkText($partial_link_text) {
return new WebDriverBy('partial link text', $partial_link_text);
}
/**
* Locates elements whose tag name matches the search value.
*
* @return WebDriverBy
*/
public static function tagName($tag_name) {
return new WebDriverBy('tag name', $tag_name);
}
/**
* Locates elements matching an XPath expression.
*
* @return WebDriverBy
*/
public static function xpath($xpath) {
return new WebDriverBy('xpath', $xpath);
}
}
PK k?V{v2 v2 " lib/WebDriverExpectedCondition.phpnu W+A apply;
}
protected function __construct($apply) {
$this->apply = $apply;
}
/**
* An expectation for checking the title of a page.
*
* @param string title The expected title, which must be an exact match.
* @return bool True when the title matches, false otherwise.
*/
public static function titleIs($title) {
return new WebDriverExpectedCondition(
function ($driver) use ($title) {
return $title === $driver->getTitle();
}
);
}
/**
* An expectation for checking substring of a page Title.
*
* @param string title The expected substring of Title.
* @return bool True when in title, false otherwise.
*/
public static function titleContains($title) {
return new WebDriverExpectedCondition(
function ($driver) use ($title) {
return strpos($driver->getTitle(), $title) !== false;
}
);
}
/**
* An expectation for checking that an element is present on the DOM of a
* page. This does not necessarily mean that the element is visible.
*
* @param WebDriverBy $by The locator used to find the element.
* @return WebDriverElement The element which is located.
*/
public static function presenceOfElementLocated(WebDriverBy $by) {
return new WebDriverExpectedCondition(
function ($driver) use ($by) {
return $driver->findElement($by);
}
);
}
/**
* An expectation for checking that an element is present on the DOM of a page
* and visible. Visibility means that the element is not only displayed but
* also has a height and width that is greater than 0.
*
* @param WebDriverBy $by The locator used to find the element.
* @return WebDriverElement The element which is located and visible.
*/
public static function visibilityOfElementLocated(WebDriverBy $by) {
return new WebDriverExpectedCondition(
function ($driver) use ($by) {
try {
$element = $driver->findElement($by);
return $element->isDisplayed() ? $element : null;
} catch (ObsoleteElementWebDriverError $e) {
return null;
}
}
);
}
/**
* An expectation for checking that an element, known to be present on the DOM
* of a page, is visible. Visibility means that the element is not only
* displayed but also has a height and width that is greater than 0.
*
* @param WebDriverElement $element The element to be checked.
* @return WebDriverElement The same WebDriverElement once it is visible.
*/
public static function visibilityOf(WebDriverElement $element) {
return new WebDriverExpectedCondition(
function ($driver) use ($element) {
return $element->isDisplayed() ? $element : null;
}
);
}
/**
* An expectation for checking that there is at least one element present on a
* web page.
*
* @param WebDriverBy $by The locator used to find the element.
* @return array An array of WebDriverElements once they are located.
*/
public static function presenceOfAllElementsLocatedBy(WebDriverBy $by) {
return new WebDriverExpectedCondition(
function ($driver) use ($by) {
$elements = $driver->findElements($by);
return count($elements) > 0 ? $elements : null;
}
);
}
/**
* An expectation for checking if the given text is present in the specified
* element.
*
* @param WebDriverBy $by The locator used to find the element.
* @param string $text The text to be presented in the element.
* @return bool Whether the text is presented.
*/
public static function textToBePresentInElement(
WebDriverBy $by, $text) {
return new WebDriverExpectedCondition(
function ($driver) use ($by, $text) {
try {
$element_text = $driver->findElement($by)->getText();
return strpos($element_text, $text) !== false;
} catch (ObsoleteElementWebDriverError $e) {
return null;
}
}
);
}
/**
* An expectation for checking if the given text is present in the specified
* elements value attribute.
*
* @param WebDriverBy $by The locator used to find the element.
* @param string $text The text to be presented in the element value.
* @return bool Whether the text is presented.
*/
public static function textToBePresentInElementValue(
WebDriverBy $by, $text) {
return new WebDriverExpectedCondition(
function ($driver) use ($by, $text) {
try {
$element_text = $driver->findElement($by)->getAttribute('value');
return strpos($element_text, $text) !== false;
} catch (ObsoleteElementWebDriverError $e) {
return null;
}
}
);
}
/**
* Expectation for checking if iFrame exists.
* If iFrame exists switches driver's focus to the iFrame
*
* @param string frame_locator The locator used to find the iFrame
* expected to be either the id or name value of the i/frame
* @return WebDriver object focused on new frame when frame is found
* bool false otherwise
*/
public static function frameToBeAvailableAndSwitchToIt(
string $frame_locator) {
return new WebDriverExpectedCondition(
function ($driver) use ($frame_locator) {
try {
return $driver->switchTo()->frame($frame_locator);
} catch (NoSuchFrameWebDriverError $e) {
return false;
}
}
);
}
/**
* An expectation for checking that an element is either invisible or not
* present on the DOM.
*
* @param WebDriverBy $by The locator used to find the element.
* @return bool Whether there is no element located.
*/
public static function invisibilityOfElementLocated(WebDriverBy $by) {
return new WebDriverExpectedCondition(
function ($driver) use ($by) {
try {
return !($driver->findElement($by)->isDisplayed());
} catch (NoSuchElementWebDriverError $e) {
return true;
} catch (ObsoleteElementWebDriverError $e) {
return true;
}
}
);
}
/**
* An expectation for checking that an element with text is either invisible
* or not present on the DOM.
*
* @param WebdriverBy $by The locator used to find the element.
* @param string $text The text of the element.
* @return bool Whether the text is found in the element located.
*/
public static function invisibilityOfElementWithText(
WebDriverBy $by, $text) {
return new WebDriverExpectedCondition(
function ($driver) use ($by, $text) {
try {
return !($driver->findElement($by)->getText() === $text);
} catch (NoSuchElementWebDriverError $e) {
return true;
} catch (ObsoleteElementWebDriverError $e) {
return true;
}
}
);
}
/**
* An expectation for checking an element is visible and enabled such that you
* can click it.
*
* @param WebDriverBy $by The locator used to find the element
* @return WebDriverElement The WebDriverElement once it is located, visible
* and clickable
*/
public static function elementToBeClickable(WebDriverBy $by) {
$visibility_of_element_located =
WebDriverExpectedCondition::visibilityOfElementLocated($by);
return new WebDriverExpectedCondition(
function ($driver) use ($visibility_of_element_located) {
$element = call_user_func(
$visibility_of_element_located->getApply(),
$driver
);
try {
if ($element !== null && $element->isEnabled()) {
return $element;
} else {
return null;
}
} catch (ObsoleteElementWebDriverError $e) {
return null;
}
}
);
}
/**
* Wait until an element is no longer attached to the DOM.
*
* @param WebDriverElement $element The element to wait for.
* @return bool false if the element is still attached to the DOM, true
* otherwise.
*/
public static function stalenessOf(WebDriverElement $element) {
return new WebDriverExpectedCondition(
function ($driver) use ($element) {
try {
$element->isEnabled();
return false;
} catch (ObsoleteElementWebDriverError $e) {
return true;
}
}
);
}
/**
* Wrapper for a condition, which allows for elements to update by redrawing.
*
* This works around the problem of conditions which have two parts: find an
* element and then check for some condition on it. For these conditions it is
* possible that an element is located and then subsequently it is redrawn on
* the client. When this happens a ObsoleteElementWebDriverError is thrown
* when the second part of the condition is checked.
*
* @param WebDriverExpectedCondition $condition The condition wrapped.
* @return mixed The return value of the getApply() of the given condition.
*/
public static function refreshed(WebDriverExpectedCondition $condition) {
return new WebDriverExpectedCondition(
function ($driver) use ($condition) {
try {
return call_user_func($condition->getApply(), $driver);
} catch (ObsoleteElementWebDriverError $e) {
return null;
}
}
);
}
/**
* An expectation for checking if the given element is selected.
*
* @param mixed element_or_by Either the element or the locator.
* @return bool whether the element is selected.
*/
public static function elementToBeSelected($element_or_by) {
return WebDriverExpectedCondition::elementSelectionStateToBe(
$element_or_by,
true
);
}
/**
* An expectation for checking if the given element is selected.
*
* @param mixed $element_or_by Either the element or the locator.
* @param bool $selected The required state.
* @return bool Whether the element is selected.
*/
public static function elementSelectionStateToBe(
$element_or_by, bool $selected) {
if ($element_or_by instanceof WebDriverElement) {
return new WebDriverExpectedCondition(
function ($driver) use ($element_or_by, $selected) {
return $element_or_by->isSelected === $selected;
}
);
} else if ($element_or_by instanceof WebDriverBy) {
return new WebDriverExpectedCondition(
function ($driver) use ($element_or_by, $selected) {
try {
$element = $driver->findElement($element_or_by);
return $element->isSelected === $selected;
} catch (ObsoleteElementWebDriverError $e) {
return null;
}
}
);
}
}
/**
* An expectation for whether an alert() box is present.
*
* @return WebDriverAlert if alert() is present, null otherwise.
*/
public static function alertIsPresent() {
return new WebDriverExpectedCondition(
function ($driver) {
try {
// Unlike the Java code, we get a WebDriverAlert object regardless
// of whether there is an alert. Calling getText() will throw
// an exception if it is not really there.
$alert = $driver->switchTo()->alert();
$alert->getText();
return $alert;
} catch (NoAlertOpenWebDriverError $e) {
return null;
}
}
);
}
/**
* An expectation with the logical opposite condition of the given condition.
*
* @param WebDriverExpectedCondition $condition The condition to be negated.
* @return mixed The nagation of the result of the given condition.
*/
public static function not(WebDriverExpectedCondition $condition) {
return new WebDriverExpectedCondition(
function ($driver) use ($condition) {
$result = call_user_func($condition->getApply(), $driver);
return !$result;
}
);
}
}
PK k?Vw#~ ~ lib/WebDriverPoint.phpnu W+A x = $x;
$this->y = $y;
}
/**
* Get the x-coordinate.
*
* @return int The x-coordinate of the point.
*/
public function getX() {
return $this->x;
}
/**
* Get the y-coordinate.
*
* @return int The y-coordinate of the point.
*/
public function getY() {
return $this->y;
}
/**
* Set the point to a new position.
*
* @return WebDriverPoint The same instance with updated coordinates.
*/
public function move($new_x, $new_y) {
$this->x = $new_x;
$this->y = $new_y;
return $this;
}
/**
* Move the current by offsets.
*
* @return WebDriverPoint The same instance with updated coordinates.
*/
public function moveBy($x_offset, $y_offset) {
$this->x += $x_offset;
$this->y += $y_offset;
return $this;
}
/**
* Check whether the given point is the same as the instance.
*
* @param WebDriverPoint $point The point to be compared with.
* @return bool Whether the x and y coordinates are the same as the instance.
*/
public function equals(WebDriverPoint $point) {
return $this->x === $point->getX() &&
$this->y === $point->getY();
}
}
PK k?Vs> lib/remote/RemoteMouse.phpnu W+A executor = $executor;
}
public function click(WebDriverCoordinates $where = null) {
$this->moveIfNeeded($where);
$this->executor->execute('mouseClick', array(
'button' => 0,
));
return $this;
}
public function contextClick(WebDriverCoordinates $where = null) {
$this->moveIfNeeded($where);
$this->executor->execute('mouseClick', array(
'button' => 2,
));
return $this;
}
public function doubleClick(WebDriverCoordinates $where = null) {
$this->moveIfNeeded($where);
$this->executor->execute('mouseDoubleClick');
return $this;
}
public function mouseDown(WebDriverCoordinates $where = null) {
$this->moveIfNeeded($where);
$this->executor->execute('mouseButtonDown');
return $this;
}
public function mouseMove(WebDriverCoordinates $where,
$x_offset = null,
$y_offset = null) {
$params = array('element' => $where->getAuxiliary());
if ($x_offset !== null) {
$params['xoffset'] = $x_offset;
}
if ($y_offset !== null) {
$params['yoffset'] = $y_offset;
}
$this->executor->execute('mouseMoveTo', $params);
return $this;
}
public function mouseUp(WebDriverCoordinates $where = null) {
$this->moveIfNeeded($where);
$this->executor->execute('mouseButtonUp');
return $this;
}
protected function moveIfNeeded(WebDriverCoordinates $where = null) {
if ($where) {
$this->mouseMove($where);
}
}
}
PK k?Vgi i lib/remote/RemoteWebDriver.phpnu W+A $url,
'name' => 'newSession',
'parameters' => array('desiredCapabilities' => $desired_capabilities),
);
$response = HttpCommandExecutor::remoteExecute($command);
$this->executor = new HttpCommandExecutor(
$url,
$response['sessionId']
);
}
/**
* Close the current window.
*
* @return WebDriver The current instance.
*/
public function close() {
$this->executor->execute('closeCurrentWindow', array());
return $this;
}
/**
* Find the first WebDriverElement using the given mechanism.
*
* @param WebDriverBy $by
* @return WebDriverElement NoSuchElementWebDriverError is thrown in
* HttpCommandExecutor if no element is found.
* @see WebDriverBy
*/
public function findElement(WebDriverBy $by) {
$params = array('using' => $by->getMechanism(), 'value' => $by->getValue());
$raw_element = $this->executor->execute('findElement', $params);
return $this->newElement($raw_element['ELEMENT']);
}
/**
* Find all WebDriverElements within the current page using the given
* mechanism.
*
* @param WebDriverBy $by
* @return array A list of all WebDriverElements, or an empty array if
* nothing matches
* @see WebDriverBy
*/
public function findElements(WebDriverBy $by) {
$params = array('using' => $by->getMechanism(), 'value' => $by->getValue());
$raw_elements = $this->executor->execute('findElements', $params);
$elements = array();
foreach ($raw_elements as $raw_element) {
$elements[] = $this->newElement($raw_element['ELEMENT']);
}
return $elements;
}
/**
* Load a new web page in the current browser window.
*
* @return WebDriver The current instance.
*/
public function get($url) {
$params = array('url' => (string)$url);
$this->executor->execute('get', $params);
return $this;
}
/**
* Get a string representing the current URL that the browser is looking at.
*
* @return string The current URL.
*/
public function getCurrentURL() {
return $this->executor->execute('getCurrentURL');
}
/**
* Get the source of the last loaded page.
*
* @return string The current page source.
*/
public function getPageSource() {
return $this->executor->execute('getPageSource');
}
/**
* Get the title of the current page.
*
* @return string The title of the current page.
*/
public function getTitle() {
return $this->executor->execute('getTitle');
}
/**
* Return an opaque handle to this window that uniquely identifies it within
* this driver instance.
*
* @return string The current window handle.
*/
public function getWindowHandle() {
return $this->executor->execute('getCurrentWindowHandle', array());
}
/**
* Get all window handles available to the current session.
*
* @return array An array of string containing all available window handles.
*/
public function getWindowHandles() {
return $this->executor->execute('getWindowHandles', array());
}
/**
* Quits this driver, closing every associated window.
*
* @return void
*/
public function quit() {
$this->executor->execute('quit');
$this->executor = null;
}
/**
* Prepare arguments for JavaScript injection
*
* @param array $arguments
* @return array
*/
private function prepareScriptArguments(array $arguments) {
$args = array();
foreach ($arguments as $arg) {
if ($arg instanceof WebDriverElement) {
array_push($args, array('ELEMENT' => $arg->getID()));
} else {
if (is_array($arg)) {
$arg = $this->prepareScriptArguments($arg);
}
array_push($args, $arg);
}
}
return $args;
}
/**
* Inject a snippet of JavaScript into the page for execution in the context
* of the currently selected frame. The executed script is assumed to be
* synchronous and the result of evaluating the script will be returned.
*
* @param string $script The script to inject.
* @param array $arguments The arguments of the script.
* @return mixed The return value of the script.
*/
public function executeScript($script, array $arguments = array()) {
$params = array(
'script' => $script,
'args' => $this->prepareScriptArguments($arguments),
);
$response = $this->executor->execute('executeScript', $params);
return $response;
}
/**
* Take a screenshot of the current page.
*
* @param $save_as The path of the screenshot to be saved.
* @return string The screenshot in PNG format.
*/
public function takeScreenshot($save_as = null) {
$screenshot = base64_decode(
$this->executor->execute('takeScreenshot')
);
if ($save_as) {
file_put_contents($save_as, $screenshot);
}
return $screenshot;
}
/**
* Construct a new WebDriverWait by the current WebDriver instance.
* Sample usage:
*
* $driver->wait(20, 1000)->until(
* WebDriverExpectedCondition::titleIs('WebDriver Page')
* );
*
* @return WebDriverWait
*/
public function wait(
$timeout_in_second = 30,
$interval_in_millisecond = 250) {
return new WebDriverWait(
$this, $timeout_in_second, $interval_in_millisecond
);
}
/**
* 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);
}
/**
* An abstraction allowing the driver to access the browser's history and to
* navigate to a given URL.
*
* @return WebDriverNavigation
* @see WebDriverNavigation
*/
public function navigate() {
return new WebDriverNavigation($this->executor);
}
/**
* Switch to a different window or frame.
*
* @return WebDriverTargetLocator
* @see WebDriverTargetLocator
*/
public function switchTo() {
return new WebDriverTargetLocator($this->executor, $this);
}
/**
* @return WebDriverMouse
*/
public function getMouse() {
if (!$this->mouse) {
$this->mouse = new RemoteMouse($this->executor);
}
return $this->mouse;
}
/**
* @return WebDriverKeyboard
*/
public function getKeyboard() {
if (!$this->keyboard) {
$this->keyboard = new RemoteKeyboard($this->executor);
}
return $this->keyboard;
}
/**
* @return WebDriverTouchScreen
*/
public function getTouch() {
if (!$this->touch) {
$this->touch = new RemoteTouchScreen($this->executor);
}
return $this->touch;
}
/**
* Construct a new action builder.
*
* @return WebDriverActions
*/
public function action() {
return new WebDriverActions($this);
}
/**
* Get the element on the page that currently has focus.
*
* @return WebDriverElement
*/
public function getActiveElement() {
$response = $this->executor->execute('getActiveElement');
return $this->newElement($response['ELEMENT']);
}
/**
* Return the WebDriverElement with the given id.
*
* @param string $id The id of the element to be created.
* @return WebDriverElement
*/
private function newElement($id) {
return new RemoteWebElement($this->executor, $id);
}
}
PK k?V[ lib/remote/RemoteTouchScreen.phpnu W+A executor = $executor;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function tap(WebDriverElement $element) {
$this->executor->execute('touchTap', array('element' => $element->getID()));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function doubleTap(WebDriverElement $element) {
$this->executor->execute(
'touchDoubleTap',
array('element' => $element->getID())
);
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function down($x, $y) {
$this->executor->execute('touchDown', array(
'x' => $x,
'y' => $y,
));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function flick($xspeed, $yspeed) {
$this->executor->execute('touchFlick', array(
'xspeed' => $xspeed,
'yspeed' => $yspeed,
));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function flickFromElement(
WebDriverElement $element, $xoffset, $yoffset, $speed
) {
$this->executor->execute('touchFlick', array(
'xoffset' => $xoffset,
'yoffset' => $yoffset,
'element' => $element->getID(),
'speed' => $speed,
));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function longPress(WebDriverElement $element) {
$this->executor->execute(
'touchLongPress',
array('element' => $element->getID())
);
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function move($x, $y) {
$this->executor->execute('touchMove', array(
'x' => $x,
'y' => $y,
));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function scroll($xoffset, $yoffset) {
$this->executor->execute('touchScroll', array(
'xoffset' => $xoffset,
'yoffset' => $yoffset,
));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function scrollFromElement(
WebDriverElement $element, $xoffset, $yoffset
) {
$this->executor->execute('touchScroll', array(
'element' => $element->getID(),
'xoffset' => $xoffset,
'yoffset' => $yoffset,
));
return $this;
}
/**
* @return RemoteTouchScreen The instance.
*/
public function up($x, $y) {
$this->executor->execute('touchUp', array(
'x' => $x,
'y' => $y,
));
return $this;
}
}
PK k?VeQN N lib/remote/RemoteKeyboard.phpnu W+A executor = $executor;
}
/**
* Send keys to active element
*
* @param $keys
* @return $this
*/
public function sendKeys($keys) {
$this->executor->execute('sendKeys', array(
'value' => WebDriverKeys::encode($keys),
));
return $this;
}
/**
* Press a modifier key
*
* @see WebDriverKeys
* @param string $key
* @return $this
*/
public function pressKey($key) {
$this->executor->execute('sendKeys', array(
'value' => array((string)$key),
));
return $this;
}
/**
* Release a modifier key
*
* @see WebDriverKeys
* @param string $key
* @return $this
*/
public function releaseKey($key) {
$this->executor->execute('sendKeys', array(
'value' => array((string)$key),
));
return $this;
}
}
PK k?VwJ' ' lib/remote/RemoteWebElement.phpnu W+A executor = $executor;
$this->id = $id;
}
/**
* If this element is a TEXTAREA or text INPUT element, this will clear the
* value.
*
* @return WebDriverElement The current instance.
*/
public function clear() {
$this->executor->execute('clear', array(':id' => $this->id));
return $this;
}
/**
* Click this element.
*
* @return WebDriverElement The current instance.
*/
public function click() {
$this->executor->execute('clickElement', array(':id' => $this->id));
return $this;
}
/**
* Find the first WebDriverElement within this element using the given
* mechanism.
*
* @param WebDriverBy $by
* @return WebDriverElement NoSuchElementWebDriverError is thrown in
* HttpCommandExecutor if no element is found.
* @see WebDriverBy
*/
public function findElement(WebDriverBy $by) {
$params = array(
'using' => $by->getMechanism(),
'value' => $by->getValue(),
':id' => $this->id,
);
$raw_element = $this->executor->execute('elementFindElement', $params);
return $this->newElement($raw_element['ELEMENT']);
}
/**
* Find all WebDriverElements within this element using the given mechanism.
*
* @param WebDriverBy $by
* @return array A list of all WebDriverElements, or an empty array if
* nothing matches
* @see WebDriverBy
*/
public function findElements(WebDriverBy $by) {
$params = array(
'using' => $by->getMechanism(),
'value' => $by->getValue(),
':id' => $this->id,
);
$raw_elements = $this->executor->execute('elementFindElements', $params);
$elements = array();
foreach ($raw_elements as $raw_element) {
$elements[] = $this->newElement($raw_element['ELEMENT']);
}
return $elements;
}
/**
* Get the value of a the given attribute of the element.
*
* @param string $attribute_name The name of the attribute.
* @return string The value of the attribute.
*/
public function getAttribute($attribute_name) {
$params = array(
':name' => $attribute_name,
':id' => $this->id,
);
return $this->executor->execute('getElementAttribute', $params);
}
/**
* Get the value of a given CSS property.
*
* @param string $css_property_name The name of the CSS property.
* @return string The value of the CSS property.
*/
public function getCSSValue($css_property_name) {
$params = array(
':propertyName' => $css_property_name,
':id' => $this->id,
);
return $this->executor->execute('getElementCSSValue', $params);
}
/**
* Get the location of element relative to the top-left corner of the page.
*
* @return WebDriverLocation The location of the element.
*/
public function getLocation() {
$location = $this->executor->execute(
'getElementLocation',
array(':id' => $this->id)
);
return new WebDriverPoint($location['x'], $location['y']);
}
/**
* Try scrolling the element into the view port and return the location of
* element relative to the top-left corner of the page afterwards.
*
* @return WebDriverLocation The location of the element.
*/
public function getLocationOnScreenOnceScrolledIntoView() {
$location = $this->executor->execute(
'getElementLocationOnceScrolledIntoView',
array(':id' => $this->id)
);
return new WebDriverPoint($location['x'], $location['y']);
}
/**
* @return WebDriverCoordinates
*/
public function getCoordinates() {
$element = $this;
$on_screen = null; // planned but not yet implemented
$in_view_port = function () use ($element) {
return $element->getLocationOnScreenOnceScrolledIntoView();
};
$on_page = function () use ($element) {
return $element->getLocation();
};
$auxiliary = $this->getID();
return new WebDriverCoordinates(
$on_screen,
$in_view_port,
$on_page,
$auxiliary
);
}
/**
* Get the size of element.
*
* @return WebDriverDimension The dimension of the element.
*/
public function getSize() {
$size = $this->executor->execute(
'getElementSize',
array(':id' => $this->id)
);
return new WebDriverDimension($size['width'], $size['height']);
}
/**
* Get the tag name of this element.
*
* @return string The tag name.
*/
public function getTagName() {
return $this->executor->execute(
'getElementTagName',
array(':id' => $this->id)
);
}
/**
* Get the visible (i.e. not hidden by CSS) innerText of this element,
* including sub-elements, without any leading or trailing whitespace.
*
* @return string The visible innerText of this element.
*/
public function getText() {
return $this->executor->execute(
'getElementText',
array(':id' => $this->id)
);
}
/**
* Is this element displayed or not? This method avoids the problem of having
* to parse an element's "style" attribute.
*
* @return bool
*/
public function isDisplayed() {
return $this->executor->execute(
'isElementDisplayed',
array(':id' => $this->id)
);
}
/**
* Is the element currently enabled or not? This will generally return true
* for everything but disabled input elements.
*
* @return bool
*/
public function isEnabled() {
return $this->executor->execute(
'isElementEnabled',
array(':id' => $this->id)
);
}
/**
* Determine whether or not this element is selected or not.
*
* @return bool
*/
public function isSelected() {
return $this->executor->execute(
'isElementSelected',
array(':id' => $this->id)
);
}
/**
* Simulate typing into an element, which may set its value.
*
* @param mixed $value The data to be typed.
* @return WebDriverElement The current instance.
*/
public function sendKeys($value) {
$params = array(
'value' => WebDriverKeys::encode($value),
':id' => $this->id,
);
$this->executor->execute('sendKeysToElement', $params);
return $this;
}
/**
* If this current element is a form, or an element within a form, then this
* will be submitted to the remote server.
*
* @return WebDriverElement The current instance.
*/
public function submit() {
$this->executor->execute('submitElement', array(':id' => $this->id));
return $this;
}
/**
* Get the opaque ID of the element.
*
* @return string The opaque ID.
*/
public function getID() {
return $this->id;
}
/**
* Test if two element IDs refer to the same DOM element.
*
* @param WebDriverElement $other
* @return boolean
*/
public function equals(WebDriverElement $other) {
return $this->executor->execute('elementEquals', array(
':id' => $this->id,
':other' => $other->getID(),
));
}
/**
* Return the WebDriverElement with $id
*
* @return WebDriverElement
*/
private function newElement($id) {
return new RemoteWebElement($this->executor, $id);
}
}
PK k?VRK1 1 " lib/remote/HttpCommandExecutor.phpnu W+A array('method' => 'POST', 'url' => '/session/:sessionId/accept_alert'),
'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'),
'closeCurrentWindow' => array('method' => 'DELETE', 'url' => '/session/:sessionId/window'),
'deleteAllCookies' => array('method' => 'DELETE', 'url' => '/session/:sessionId/cookie'),
'deleteCookie' => array('method' => 'DELETE', 'url' => '/session/:sessionId/cookie/:name'),
'dismissAlert' => array('method' => 'POST', 'url' => '/session/:sessionId/dismiss_alert'),
'elementEquals' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/equals/:other'),
'elementFindElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/element'),
'elementFindElements' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/elements'),
'executeScript' => array('method' => 'POST', 'url' => '/session/:sessionId/execute'),
'findElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element'),
'findElements' => array('method' => 'POST', 'url' => '/session/:sessionId/elements'),
'focusFrame' => array('method' => 'POST', 'url' => '/session/:sessionId/frame'),
'focusWindow' => array('method' => 'POST', 'url' => '/session/:sessionId/window'),
'get' => array('method' => 'POST', 'url' => '/session/:sessionId/url'),
'getActiveElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/active'),
'getAlertText' => array('method' => 'GET', 'url' => '/session/:sessionId/alert_text'),
'getAllCookies' => array('method' => 'GET', 'url' => '/session/:sessionId/cookie'),
'getAvailableLogTypes' => array('method' => 'GET', 'url' => '/session/:sessionId/log/types'),
'getCurrentURL' => array('method' => 'GET', 'url' => '/session/:sessionId/url'),
'getCurrentWindowHandle' => array('method' => 'GET', 'url' => '/session/:sessionId/window_handle'),
'getElementAttribute' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/attribute/:name'),
'getElementCSSValue' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/css/:propertyName'),
'getElementLocation' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/location'),
'getElementLocationOnceScrolledIntoView' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/location_in_view'),
'getElementSize' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/size'),
'getElementTagName' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/name'),
'getElementText' => array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/text'),
'getLog' => array('method' => 'POST', 'url' => '/session/:sessionId/log'),
'getPageSource' => array('method' => 'GET', 'url' => '/session/:sessionId/source'),
'getScreenOrientation' => array('method' => 'GET', 'url' => '/session/:sessionId/orientation'),
'getSession' => array('method' => 'GET', 'url' => '/session/:sessionId'),
'getTitle' => array('method' => 'GET', 'url' => '/session/:sessionId/title'),
'getWindowHandles' => array('method' => 'GET', 'url' => '/session/:sessionId/window_handles'),
'getWindowPosition' => array('method' => 'GET', 'url' => '/session/:sessionId/window/:windowHandle/position'),
'getWindowSize' => array('method' => 'GET', 'url' => '/session/:sessionId/window/:windowHandle/size'),
'goBack' => array('method' => 'POST', 'url' => '/session/:sessionId/back'),
'goForward' => array('method' => 'POST', 'url' => '/session/:sessionId/forward'),
'isElementDisplayed'=> array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/displayed'),
'isElementEnabled'=> array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/enabled'),
'isElementSelected'=> array('method' => 'GET', 'url' => '/session/:sessionId/element/:id/selected'),
'maximizeWindow' => array('method' => 'POST', 'url' => '/session/:sessionId/window/:windowHandle/maximize'),
'mouseButtonDown' => array('method' => 'POST', 'url' => '/session/:sessionId/buttondown'),
'mouseButtonUp' => array('method' => 'POST', 'url' => '/session/:sessionId/buttonup'),
'mouseClick' => array('method' => 'POST', 'url' => '/session/:sessionId/click'),
'mouseDoubleClick' => array('method' => 'POST', 'url' => '/session/:sessionId/doubleclick'),
'mouseMoveTo' => array('method' => 'POST', 'url' => '/session/:sessionId/moveto'),
'newSession' => array('method' => 'POST', 'url' => '/session'),
'quit' => array('method' => 'DELETE', 'url' => '/session/:sessionId'),
'refreshPage' => array('method' => 'POST', 'url' => '/session/:sessionId/refresh'),
'sendFile' => array('method' => 'POST', 'url' => '/session/:sessionId/file'), // undocumented
'sendKeys' => array('method' => 'POST', 'url' => '/session/:sessionId/keys'),
'sendKeysToAlert' => array('method' => 'POST', 'url' => '/session/:sessionId/alert_text'),
'sendKeysToElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/value'),
'setImplicitWaitTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts/implicit_wait'),
'setScreenOrientation' => array('method' => 'POST', 'url' => '/session/:sessionId/orientation'),
'setPageLoadTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts'),
'setScriptTimeout' => array('method' => 'POST', 'url' => '/session/:sessionId/timeouts/async_script'),
'setWindowPosition' => array('method' => 'POST', 'url' => '/session/:sessionId/window/:windowHandle/position'),
'setWindowSize' => array('method' => 'POST', 'url' => '/session/:sessionId/window/:windowHandle/size'),
'submitElement' => array('method' => 'POST', 'url' => '/session/:sessionId/element/:id/submit'),
'takeScreenshot' => array('method' => 'GET', 'url' => '/session/:sessionId/screenshot'),
'touchTap' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/click'),
'touchDown' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/down'),
'touchDoubleTap' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/doubleclick'),
'touchFlick' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/flick'),
'touchLongPress' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/longclick'),
'touchMove' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/move'),
'touchScroll' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/scroll'),
'touchUp' => array('method' => 'POST', 'url' => '/session/:sessionId/touch/up'),
);
protected $url;
protected $sessionID;
protected $capabilities;
public function __construct($url, $session_id) {
$this->url = $url;
$this->sessionID = $session_id;
$this->capabilities = $this->execute('getSession', array());
}
public function execute($name, array $params = array()) {
$command = array(
'url' => $this->url,
'sessionId' => $this->sessionID,
'name' => $name,
'parameters' => $params,
);
$raw = self::remoteExecute($command);
return $raw['value'];
}
/**
* Execute a command on a remote server. The command should be an array
* contains
* url : the url of the remote server
* sessionId : the session id if needed
* name : the name of the command
* parameters : the parameters of the command required
*
* @return array The response of the command.
*/
public static function remoteExecute($command) {
if (!isset(self::$commands[$command['name']])) {
throw new Exception($command['name']." is not a valid command.");
}
$raw = self::$commands[$command['name']];
$extra_opts = array();
if ($command['name'] == 'newSession') {
$extra_opts[CURLOPT_FOLLOWLOCATION] = true;
}
return self::curl(
$raw['method'],
sprintf("%s%s", $command['url'], $raw['url']),
$command,
$extra_opts
);
}
/**
* Curl request to webdriver server.
*
* @param http_method 'GET', 'POST', or 'DELETE'
* @param suffix What to append to the base URL.
* @param command The Command object, modelled as a hash.
* @param extra_opts key => value pairs of curl options for curl_setopt()
*/
protected static function curl(
$http_method,
$url,
$command,
$extra_opts = array()) {
$params = $command['parameters'];
foreach ($params as $name => $value) {
if ($name[0] === ':') {
$url = str_replace($name, $value, $url);
if ($http_method != 'POST') {
unset($params[$name]);
}
}
}
if (isset($command['sessionId'])) {
$url = str_replace(':sessionId', $command['sessionId'], $url);
}
if ($params && is_array($params) && $http_method !== 'POST') {
throw new Exception(sprintf(
'The http method called for %s is %s but it has to be POST' .
' if you want to pass the JSON params %s',
$url,
$http_method,
json_encode($params)));
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_TIMEOUT, 300);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json;charset=UTF-8',
'Accept: application/json'));
if ($http_method === 'POST') {
curl_setopt($curl, CURLOPT_POST, true);
if ($params && is_array($params)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
}
} else if ($http_method == 'DELETE') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
}
foreach ($extra_opts as $option => $value) {
curl_setopt($curl, $option, $value);
}
$raw_results = trim(curl_exec($curl));
$info = curl_getinfo($curl);
if ($error = curl_error($curl)) {
$msg = sprintf(
'Curl error thrown for http %s to %s',
$http_method,
$url);
if ($params && is_array($params)) {
$msg .= sprintf(' with params: %s', json_encode($params));
}
throw new WebDriverCurlException($msg . "\n\n" . $error);
}
curl_close($curl);
$results = json_decode($raw_results, true);
$value = null;
if (is_array($results) && array_key_exists('value', $results)) {
$value = $results['value'];
}
$message = null;
if (is_array($value) && array_key_exists('message', $value)) {
$message = $value['message'];
}
$sessionId = null;
if (is_array($results) && array_key_exists('sessionId', $results)) {
$sessionId = $results['sessionId'];
}
$status = isset($results['status']) ? $results['status'] : 0;
WebDriverException::throwException($status, $message, $results);
return array('value' => $value, 'info' => $info, 'sessionId' => $sessionId);
}
public function getSessionID() {
return $this->sessionID;
}
}
PK k?VRT T # lib/remote/WebDriverBrowserType.phpnu W+A executor = $executor;
}
/**
* 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->executor->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->executor->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->executor->execute('setPageLoadTimeout', array(
'type' => 'page load',
'ms' => $seconds * 1000,
));
return $this;
}
}
PK k?Vtn! ! lib/WebDriverKeyboard.phpnu W+A touchScreen = $touch_screen;
$this->locationProvider = $location_provider;
}
protected function getActionLocation() {
return $this->locationProvider !== null
? $this->locationProvider->getCoordinates() : null;
}
}
PK k?V
j - lib/interactions/touch/WebDriverTapAction.phpnu W+A touchScreen->tap($this->locationProvider);
}
}
PK k?Ve- , lib/interactions/touch/WebDriverUpAction.phpnu W+A x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform() {
$this->touchScreen->up($this->x, $this->y);
}
}
PK k?V, , 3 lib/interactions/touch/WebDriverDoubleTapAction.phpnu W+A touchScreen->doubleTap($this->locationProvider);
}
}
PK k?VY . lib/interactions/touch/WebDriverMoveAction.phpnu W+A x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform() {
$this->touchScreen->move($this->x, $this->y);
}
}
PK k?Vϝ / lib/interactions/touch/WebDriverFlickAction.phpnu W+A x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform() {
$this->touchScreen->flick($this->x, $this->y);
}
}
PK k?V$# : lib/interactions/touch/WebDriverFlickFromElementAction.phpnu W+A x = $x;
$this->y = $y;
$this->speed = $speed;
parent::__construct($touch_screen, $element);
}
public function perform() {
$this->touchScreen->flickFromElement(
$this->locationProvider,
$this->x,
$this->y,
$this->speed
);
}
}
PK k?V3|, , 3 lib/interactions/touch/WebDriverLongPressAction.phpnu W+A touchScreen->longPress($this->locationProvider);
}
}
PK k?VY]S S ; lib/interactions/touch/WebDriverScrollFromElementAction.phpnu W+A x = $x;
$this->y = $y;
parent::__construct($touch_screen, $element);
}
public function perform() {
$this->touchScreen->scrollFromElement(
$this->locationProvider,
$this->x,
$this->y
);
}
}
PK k?VJK 0 lib/interactions/touch/WebDriverScrollAction.phpnu W+A x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform() {
$this->touchScreen->scroll($this->x, $this->y);
}
}
PK k?V]| . lib/interactions/touch/WebDriverDownAction.phpnu W+A x = $x;
$this->y = $y;
parent::__construct($touch_screen);
}
public function perform() {
$this->touchScreen->down($this->x, $this->y);
}
}
PK k?VN P_ _ - lib/interactions/WebDriverCompositeAction.phpnu W+A actions[] = $action;
return $this;
}
/**
* Get the number of actions in the sequence.
*
* @return int The number of actions.
*/
public function getNumberOfActions() {
return count($this->actions);
}
/**
* Perform the seqeunce of actions.
*/
public function perform() {
foreach ($this->actions as $action) {
$action->perform();
}
}
}
PK k?Vߟ%V * lib/interactions/WebDriverTouchActions.phpnu W+A driver = $driver;
$this->keyboard = $driver->getKeyboard();
$this->mouse = $driver->getMouse();
$this->touchScreen = $driver->getTouch();
$this->action = new WebDriverCompositeAction();
}
public function tap(WebDriverElement $element) {
$this->action->addAction(
new WebDriverTapAction($this->touchScreen, $element)
);
return $this;
}
public function down($x, $y) {
$this->action->addAction(
new WebDriverDownAction($this->touchScreen, $x, $y)
);
return $this;
}
public function up($x, $y) {
$this->action->addAction(
new WebDriverUpAction($this->touchScreen, $x, $y)
);
return $this;
}
public function move($x, $y) {
$this->action->addAction(
new WebDriverMoveAction($this->touchScreen, $x, $y)
);
return $this;
}
public function scroll($x, $y) {
$this->action->addAction(
new WebDriverScrollAction($this->touchScreen, $x, $y)
);
return $this;
}
public function scrollFromElement(WebDriverElement $element, $x, $y) {
$this->action->addAction(
new WebDriverScrollFromElementAction($this->touchScreen, $element, $x, $y)
);
return $this;
}
public function doubleTap(WebDriverElement $element) {
$this->action->addAction(
new WebDriverDoubleTapAction($this->touchScreen, $element)
);
return $this;
}
public function longPress(WebDriverElement $element) {
$this->action->addAction(
new WebDriverLongPressAction($this->touchScreen, $element)
);
return $this;
}
public function flick($x, $y) {
$this->action->addAction(
new WebDriverFlickAction($this->touchScreen, $x, $y)
);
return $this;
}
public function flickFromElement(WebDriverElement $element, $x, $y, $speed) {
$this->action->addAction(
new WebDriverFlickFromElementAction(
$this->touchScreen, $element, $x, $y, $speed
)
);
return $this;
}
}
PK k?Vj0T T 5 lib/interactions/internal/WebDriverSendKeysAction.phpnu W+A keys = $keys;
}
public function perform() {
$this->focusOnElement();
$this->keyboard->sendKeys($this->keys);
}
}
PK k?Vk)> > 2 lib/interactions/internal/WebDriverKeyUpAction.phpnu W+A focusOnElement();
$this->keyboard->releaseKey($this->key);
}
}
PK k?VVI~ 9 lib/interactions/internal/WebDriverMoveToOffsetAction.phpnu W+A xOffset = $x_offset;
$this->yOffset = $y_offset;
}
public function perform() {
$this->mouse->mouseMove(
$this->getActionLocation(),
$this->xOffset,
$this->yOffset
);
}
}
PK k?Vws% 6 lib/interactions/internal/WebDriverSingleKeyAction.phpnu W+A key = $key;
}
abstract public function perform();
}
PK k?Vzݢ? ? 2 lib/interactions/internal/WebDriverCoordinates.phpnu W+A onScreen = $on_screen;
$this->inViewPort = $in_view_port;
$this->onPage = $on_page;
$this->auxiliary = $auxiliary;
}
/**
* @return WebDriverPoint
*/
public function onScreen() {
throw new UnsupportedOperationException(
'onScreen is planned but not yet supported by Selenium'
);
}
/**
* @return WebDriverPoint
*/
public function inViewPort() {
return call_user_func($this->inViewPort);
}
/**
* @return WebDriverPoint
*/
public function onPage() {
return call_user_func($this->onPage);
}
/**
* @return Object The attached object.
*/
public function getAuxiliary() {
return $this->auxiliary;
}
}
PK k?V 2 lib/interactions/internal/WebDriverMouseAction.phpnu W+A mouse = $mouse;
$this->locationProvider = $location_provider;
}
protected function getActionLocation() {
if ($this->locationProvider !== null) {
return $this->locationProvider->getCoordinates();
} else {
return null;
}
}
protected function moveToLocation() {
$this->mouse->mouseMove($this->locationProvider);
}
}
PK k?V~- - 6 lib/interactions/internal/WebDriverMouseMoveAction.phpnu W+A mouse->mouseMove($this->getActionLocation());
}
}
PK k?V#_21 1 8 lib/interactions/internal/WebDriverDoubleClickAction.phpnu W+A mouse->doubleClick($this->getActionLocation());
}
}
PK k?VmPļ 8 lib/interactions/internal/WebDriverKeysRelatedAction.phpnu W+A keyboard = $keyboard;
$this->mouse = $mouse;
$this->locationProvider = $location_provider;
}
protected function focusOnElement() {
if ($this->locationProvider) {
$this->mouse->click($this->locationProvider->getCoordinates());
}
}
}
PK k?V뷻> > 4 lib/interactions/internal/WebDriverKeyDownAction.phpnu W+A focusOnElement();
$this->keyboard->pressKey($this->key);
}
}
PK k?V22i i 9 lib/interactions/internal/WebDriverContextClickAction.phpnu W+A mouse->contextClick($this->getActionLocation());
}
}
PK k?V=o o : lib/interactions/internal/WebDriverButtonReleaseAction.phpnu W+A mouse->mouseUp($this->getActionLocation());
}
}
PK k?V% % 2 lib/interactions/internal/WebDriverClickAction.phpnu W+A mouse->click($this->getActionLocation());
}
}
PK k?V9b b 9 lib/interactions/internal/WebDriverClickAndHoldAction.phpnu W+A mouse->mouseDown($this->getActionLocation());
}
}
PK k?Vm % lib/interactions/WebDriverActions.phpnu W+A driver = $driver;
$this->keyboard = $driver->getKeyboard();
$this->mouse = $driver->getMouse();
$this->action = new WebDriverCompositeAction();
}
/**
* A convenience method for performing the actions without calling build().
*/
public function perform() {
$this->action->perform();
}
/**
* Mouse click.
* If $element is provided, move to the middle of the element first.
*/
public function click(WebDriverElement $element = null) {
$this->action->addAction(
new WebDriverClickAction($this->mouse, $element)
);
return $this;
}
/**
* Mouse click and hold.
* If $element is provided, move to the middle of the element first.
*/
public function clickAndHold(WebDriverElement $element = null) {
$this->action->addAction(
new WebDriverClickAndHoldAction($this->mouse, $element)
);
return $this;
}
/**
* Context-click (right click).
* If $element is provided, move to the middle of the element first.
*/
public function contextClick(WebDriverElement $element = null) {
$this->action->addAction(
new WebDriverContextClickAction($this->mouse, $element)
);
return $this;
}
/**
* Double click.
* If $element is provided, move to the middle of the element first.
*/
public function doubleClick(WebDriverElement $element = null) {
$this->action->addAction(
new WebDriverDoubleClickAction($this->mouse, $element)
);
return $this;
}
/**
* Drag and drop from $source to $target.
*/
public function dragAndDrop(WebDriverElement $source,
WebDriverElement $target) {
$this->action->addAction(
new WebDriverClickAndHoldAction($this->mouse, $source)
);
$this->action->addAction(
new WebDriverMouseMoveAction($this->mouse, $target)
);
$this->action->addAction(
new WebDriverButtonReleaseAction($this->mouse, $target)
);
return $this;
}
/**
* Drag $source and drop by offset ($x_offset, $y_offset).
*/
public function dragAndDropBy(WebDriverElement $source,
$x_offset,
$y_offset) {
$this->action->addAction(
new WebDriverClickAndHoldAction($this->mouse, $source)
);
$this->action->addAction(
new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset)
);
$this->action->addAction(
new WebDriverButtonReleaseAction($this->mouse, null)
);
return $this;
}
/**
* Mouse move by offset.
*/
public function moveByOffset($x_offset, $y_offset) {
$this->action->addAction(
new WebDriverMoveToOffsetAction($this->mouse, null, $x_offset, $y_offset)
);
return $this;
}
/**
* Move to the middle of the given WebDriverElement. If offset are provided,
* move the an offset from the top-left cornerof that element.
*/
public function moveToElement(WebDriverElement $element,
$x_offset = null,
$y_offset = null) {
$this->action->addAction(new WebDriverMoveToOffsetAction(
$this->mouse, $element, $x_offset, $y_offset
));
return $this;
}
/**
* Release the mouse button.
* If $element is provided, move to the middle of the element first.
*/
public function release(WebDriverElement $element = null) {
$this->action->addAction(
new WebDriverButtonReleaseAction($this->mouse, $element)
);
return $this;
}
/**
* Press a key on keyboard.
* If $element is provided, focus on that element first.
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
*/
public function keyDown(WebDriverElement $element = null, $key) {
$this->action->addAction(
new WebDriverKeyDownAction($this->keyboard, $this->mouse, $element, $key)
);
return $this;
}
/**
* Release a key on keyboard.
* If $element is provided, focus on that element first.
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
*/
public function keyUp(WebDriverElement $element = null, $key) {
$this->action->addAction(
new WebDriverKeyUpAction($this->keyboard, $this->mouse, $element, $key)
);
return $this;
}
/**
* Send keys by keyboard.
* If $element is provided, focus on that element first.
*
* @see WebDriverKeys for special keys like CONTROL, ALT, etc.
*/
public function sendKeys(WebDriverElement $element = null, $keys) {
$this->action->addAction(
new WebDriverSendKeysAction(
$this->keyboard, $this->mouse, $element, $keys
)
);
return $this;
}
}
PK k?V
] ) lib/interactions/WebDriverTouchScreen.phpnu W+A driver = $driver;
return $this;
}
/**
* @return null|EventFiringWebDriver
*/
public function getDefaultDriver() {
return $this->driver;
}
/**
* @param WebDriverEventListener $listener
* @return $this
*/
public function register(WebDriverEventListener $listener) {
$this->listeners[] = $listener;
return $this;
}
/**
* @param WebDriverEventListener $listener
* @return $this
*/
public function unregister(WebDriverEventListener $listener) {
$key = array_search($listener, $this->listeners, true);
if ($key !== false) {
unset($this->listeners[$key]);
}
return $this;
}
/**
* @param $method
* @param $arguments
* @return $this
*/
public function dispatch($method, $arguments) {
foreach ($this->listeners as $listener) {
call_user_func_array(array($listener, $method), $arguments);
}
return $this;
}
}
PK k?Vrz z lib/WebDriverSelect.phpnu W+A getTagName();
if ($tag_name !== 'select') {
throw new UnexpectedTagNameException('select', $tag_name);
}
$this->element = $element;
$value = $element->getAttribute('multiple');
$this->isMulti = ($value === 'true');
}
/**
* @return bool Whether this select element support selecting multiple
* options. This is done by checking the value of the 'multiple'
* attribute.
*/
public function isMultiple() {
return $this->isMulti;
}
/**
* @return array All options belonging to this select tag.
*/
public function getOptions() {
return $this->element->findElements(WebDriverBy::tagName('option'));
}
/**
* @return array All selected options belonging to this select tag.
*/
public function getAllSelectedOptions() {
$selected_options = array();
foreach ($this->getOptions() as $option) {
if ($option->isSelected()) {
$selected_options[] = $option;
}
}
return $selected_options;
}
/**
* @return WebDriverElement The first selected option in this select tag (or
* the currently selected option in a normal select)
*/
public function getFirstSelectedOption() {
foreach ($this->getOptions() as $option) {
if ($option->isSelected()) {
return $option;
}
}
throw new NoSuchElementWebDriverError('No options are selected');
}
/**
* Deselect all options in multiple select tag.
*
* @return void
*/
public function deselectAll() {
if (!$this->isMultiple()) {
throw new UnsupportedOperationException(
'You may only deselect all options of a multi-select'
);
}
foreach ($this->getOptions() as $option) {
if ($option->isSelected()) {
$option->click();
}
}
}
/**
* Select the option at the given index.
*
* @param int $index The index of the option. (0-based)
* @return void
*/
public function selectByIndex($index) {
$matched = false;
foreach ($this->getOptions() as $option) {
if ($option->getAttribute('index') === (string)$index) {
if (!$option->isSelected()) {
$option->click();
if (!$this->isMultiple()) {
return;
}
}
$matched = true;
}
}
if (!$matched) {
throw new NoSuchElementWebDriverError(
sprintf('Cannot locate option with index: %d', $index)
);
}
}
/**
* Select all options that have value attribute matching the argument. That
* is, when given "foo" this would select an option like:
*
* ;
*
* @param string $value The value to match against.
* @return void
*/
public function selectByValue($value) {
$matched = false;
$xpath = './/option[@value = '.$this->escapeQuotes($value).']';
$options = $this->element->findElements(WebDriverBy::xpath($xpath));
foreach ($options as $option) {
if (!$option->isSelected()) {
$option->click();
}
if (!$this->isMultiple()) {
return;
}
$matched = true;
}
if (!$matched) {
throw new NoSuchElementWebDriverError(
sprintf('Cannot locate option with value: %s', $value)
);
}
}
/**
* Select all options that display text matching the argument. That is, when
* given "Bar" this would select an option like:
*
* ;
*
* @param string $text The visible text to match against.
* @return void
*/
public function selectByVisibleText($text) {
$matched = false;
$xpath = './/option[normalize-space(.) = '.$this->escapeQuotes($text).']';
$options = $this->element->findElements(WebDriverBy::xpath($xpath));
foreach ($options as $option) {
if (!$option->isSelected()) {
$option->click();
}
if (!$this->isMultiple()) {
return;
}
$matched = true;
}
// Since the mechanism of getting the text in xpath is not the same as
// webdriver, use the expensive getText() to check if nothing is matched.
if (!$matched) {
foreach ($this->getOptions() as $option) {
if ($option->getText() === $text) {
if (!$option->isSelected()) {
$option->click();
}
if (!$this->isMultiple()) {
return;
}
$matched = true;
}
}
}
if (!$matched) {
throw new NoSuchElementWebDriverError(
sprintf('Cannot locate option with text: %s', $text)
);
}
}
/**
* Deselect the option at the given index.
*
* @param int $index The index of the option. (0-based)
* @return void
*/
public function deselectByIndex($index) {
foreach ($this->getOptions() as $option) {
if ($option->getAttribute('index') === (string)$index &&
$option->isSelected()) {
$option->click();
}
}
}
/**
* Deselect all options that have value attribute matching the argument. That
* is, when given "foo" this would select an option like:
*
* ;
*
* @param string $value The value to match against.
* @return void
*/
public function deselectByValue($value) {
$xpath = './/option[@value = '.$this->escapeQuotes($value).']';
$options = $this->element->findElements(WebDriverBy::xpath($xpath));
foreach ($options as $option) {
if ($option->isSelected()) {
$option->click();
}
}
}
/**
* Deselect all options that display text matching the argument. That is, when
* given "Bar" this would select an option like:
*
* ;
*
* @param string $text The visible text to match against.
* @return void
*/
public function deselectByVisibleText($text) {
$xpath = './/option[normalize-space(.) = '.$this->escapeQuotes($text).']';
$options = $this->element->findElements(WebDriverBy::xpath($xpath));
foreach ($options as $option) {
if ($option->isSelected()) {
$option->click();
}
}
}
/**
* Convert strings with both quotes and ticks into:
* foo'"bar -> concat("foo'", '"', "bar")
*
* @param string $to_escape The string to be converted.
* @return string The escaped string.
*/
protected function escapeQuotes($to_escape) {
if (strpos($to_escape, '"') !== false && strpos($to_escape, "'" != false)) {
$substrings = explode('"', $to_escape);
$escaped = "concat(";
$first = true;
foreach ($substrings as $string) {
if (!$first) {
$escaped .= ", '\"',";
$first = false;
}
$escaped .= '"' . $string . '"';
}
return $escaped;
}
if (strpos($to_escape, '"' !== false)) {
return sprintf("'%s'", $to_escape);
}
return sprintf('"%s"', $to_escape);
}
}
PK k?V> lib/WebDriverAlert.phpnu W+A executor = $executor;
}
/**
* Accept alert
*
* @return WebDriverAlert The instance.
*/
public function accept() {
$this->executor->execute('acceptAlert');
return $this;
}
/**
* Dismiss alert
*
* @return WebDriverAlert The instance.
*/
public function dismiss() {
$this->executor->execute('dismissAlert');
return $this;
}
/**
* Get alert text
*
* @return string
*/
public function getText() {
return $this->executor->execute('getAlertText');
}
/**
* Send keystrokes to javascript prompt() dialog
*
* @return WebDriverAlert
*/
public function sendKeys($value) {
$this->executor->execute('sendKeysToAlert', array('text' => $value));
return $this;
}
}
PK k?V]u u lib/WebDriverOptions.phpnu W+A executor = $executor;
}
/**
* Add a specific cookie.
*
* Here are the valid attributes of a cookie array.
* 'name' : string The name of the cookie; may not be null or an empty
* string.
* 'value' : string The cookie value; may not be null.
* 'path' : string The path the cookie is visible to. If left blank or set
* to null, will be set to "/".
* 'domain': string The domain the cookie is visible to. It should be null or
* the same as the domain of the current URL.
* 'secure': bool Whether this cookie requires a secure connection(https?).
* It should be null or equal to the security of the current
* URL.
* 'expiry': int The cookie's expiration date; may be null.
*
* @param array $cookie An array with key as the attributes mentioned above.
* @return WebDriverOptions The current instance.
*/
public function addCookie(array $cookie) {
$this->validate($cookie);
$this->executor->execute('addCookie', array('cookie' => $cookie));
return $this;
}
/**
* Delete all the cookies that are currently visible.
*
* @return WebDriverOptions The current instance.
*/
public function deleteAllCookies() {
$this->executor->execute('deleteAllCookies');
return $this;
}
/**
* Delete the cookie with the give name.
*
* @return WebDriverOptions The current instance.
*/
public function deleteCookieNamed($name) {
$this->executor->execute('deleteCookie', array(':name' => $name));
return $this;
}
/**
* Get the cookie with a given name.
*
* @return array The cookie, or null if no cookie with the given name is
* presented.
*/
public function getCookieNamed($name) {
$cookies = $this->getCookies();
foreach ($cookies as $cookie) {
if ($cookie['name'] === $name) {
return $cookie;
}
}
return null;
}
/**
* Get all the cookies for the current domain.
*
* @return array The array of cookies presented.
*/
public function getCookies() {
return $this->executor->execute('getAllCookies');
}
private function validate(array $cookie) {
if (!isset($cookie['name']) ||
$cookie['name'] === '' ||
strpos($cookie['name'], ';') !== false) {
throw new InvalidArgumentException(
'"name" should be non-empty and does not contain a ";"');
}
if (!isset($cookie['value'])) {
throw new InvalidArgumentException(
'"value" is required when setting a cookie.');
}
if (isset($cookie['domain']) && strpos($cookie['domain'], ':') !== false) {
throw new InvalidArgumentException(
'"domain" should not contain a port:'.(string)$cookie['domain']);
}
}
/**
* Return the interface for managing driver timeouts.
*
* @return WebDriverTimeouts
*/
public function timeouts() {
return new WebDriverTimeouts($this->executor);
}
/**
* An abstraction allowing the driver to manipulate the browser's window
*
* @return WebDriverWindow
* @see WebDriverWindow
*/
public function window() {
return new WebDriverWindow($this->executor);
}
/**
* Get the log for a given log type. Log buffer is reset after each request.
*
* @param $logType The log type.
* @return array The list of log entries.
* @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#Log_Type
*/
public function getLog($log_type) {
return $this->executor->execute(
'getLog',
array('type' => $log_type)
);
}
/**
* Get available log types.
*
* @return array The list of available log types.
* @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#Log_Type
*/
public function getAvailableLogTypes() {
return $this->executor->execute('getAvailableLogTypes');
}
}
PK k?V!rҲQ Q lib/WebDriverCommandExecutor.phpnu W+A navigator = $navigator;
$this->dispatcher = $dispatcher;
return $this;
}
/**
* @return WebDriverDispatcher
*/
public function getDispatcher() {
return $this->dispatcher;
}
/**
* @param $method
*/
protected function dispatch($method) {
if (!$this->dispatcher) {
return;
}
$arguments = func_get_args();
unset($arguments[0]);
$this->dispatcher->dispatch($method, $arguments);
}
/**
* @return WebDriverNavigation
*/
public function getNavigator() {
return $this->navigator;
}
/**
* @return $this
* @throws WebDriverException
*/
public function back() {
$this->dispatch(
'beforeNavigateBack',
$this->getDispatcher()->getDefaultDriver()
);
try {
$this->navigator->back();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch(
'afterNavigateBack',
$this->getDispatcher()->getDefaultDriver()
);
return $this;
}
/**
* @return $this
* @throws WebDriverException
*/
public function forward() {
$this->dispatch(
'beforeNavigateForward',
$this->getDispatcher()->getDefaultDriver()
);
try {
$this->navigator->forward();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch(
'afterNavigateForward',
$this->getDispatcher()->getDefaultDriver()
);
return $this;
}
/**
* @return $this
* @throws WebDriverException
*/
public function refresh() {
try {
$this->navigator->refresh();
return $this;
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @param $url
* @return $this
* @throws WebDriverException
*/
public function to($url) {
$this->dispatch(
'beforeNavigateTo',
$url,
$this->getDispatcher()->getDefaultDriver()
);
try {
$this->navigator->to($url);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch(
'afterNavigateTo',
$url,
$this->getDispatcher()->getDefaultDriver()
);
return $this;
}
private function dispatchOnException($exception) {
$this->dispatch('onException', $exception);
throw $exception;
}
}
PK k?V'Ԙ , lib/support/events/EventFiringWebElement.phpnu W+A element = $element;
$this->dispatcher = $dispatcher;
return $this;
}
/**
* @return WebDriverDispatcher
*/
public function getDispatcher() {
return $this->dispatcher;
}
/**
* @param $method
*/
protected function dispatch($method) {
if (!$this->dispatcher) {
return;
}
$arguments = func_get_args();
unset($arguments[0]);
$this->dispatcher->dispatch($method, $arguments);
}
/**
* @return WebDriverElement
*/
public function getElement() {
return $this->element;
}
/**
* @param WebDriverElement $element
* @return EventFiringWebElement
*/
private function newElement(WebDriverElement $element) {
return new EventFiringWebElement($element, $this->getDispatcher());
}
/**
* @param $value
* @return $this
* @throws WebDriverException
*/
public function sendKeys($value) {
$this->dispatch('beforeChangeValueOf', $this);
try {
$this->element->sendKeys($value);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch('afterChangeValueOf', $this);
return $this;
}
/**
* @return $this
* @throws WebDriverException
*/
public function click() {
$this->dispatch('beforeClickOn', $this);
try {
$this->element->click();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch('afterClickOn', $this);
return $this;
}
/**
* @param WebDriverBy $by
* @return EventFiringWebElement
* @throws WebDriverException
*/
public function findElement(WebDriverBy $by) {
$this->dispatch(
'beforeFindBy',
$by,
$this,
$this->dispatcher->getDefaultDriver());
try {
$element = $this->newElement($this->element->findElement($by));
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch(
'afterFindBy',
$by,
$this,
$this->dispatcher->getDefaultDriver()
);
return $element;
}
/**
* @param WebDriverBy $by
* @return array
* @throws WebDriverException
*/
public function findElements(WebDriverBy $by) {
$this->dispatch(
'beforeFindBy',
$by,
$this,
$this->dispatcher->getDefaultDriver()
);
try {
$elements = array();
foreach ($this->element->findElements($by) as $element) {
$elements[] = $this->newElement($element);
}
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch(
'afterFindBy',
$by,
$this,
$this->dispatcher->getDefaultDriver()
);
return $elements;
}
/**
* @return $this
* @throws WebDriverException
*/
public function clear() {
try {
$this->element->clear();
return $this;
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @param $attribute_name
* @return string
* @throws WebDriverException
*/
public function getAttribute($attribute_name) {
try {
return $this->element->getAttribute($attribute_name);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @param $css_property_name
* @return string
* @throws WebDriverException
*/
public function getCSSValue($css_property_name) {
try {
return $this->element->getCSSValue($css_property_name);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverLocation
* @throws WebDriverException
*/
public function getLocation() {
try {
return $this->element->getLocation();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverLocation
* @throws WebDriverException
*/
public function getLocationOnScreenOnceScrolledIntoView() {
try {
return $this->element->getLocationOnScreenOnceScrolledIntoView();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverCoordinates
*/
public function getCoordinates() {
try {
return $this->element->getCoordinates();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverDimension
* @throws WebDriverException
*/
public function getSize() {
try {
return $this->element->getSize();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getTagName() {
try {
return $this->element->getTagName();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getText() {
try {
return $this->element->getText();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return bool
* @throws WebDriverException
*/
public function isDisplayed() {
try {
return $this->element->isDisplayed();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return bool
* @throws WebDriverException
*/
public function isEnabled() {
try {
return $this->element->isEnabled();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return bool
* @throws WebDriverException
*/
public function isSelected() {
try {
return $this->element->isSelected();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return $this
* @throws WebDriverException
*/
public function submit() {
try {
$this->element->submit();
return $this;
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getID() {
try {
return $this->element->getID();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* Test if two element IDs refer to the same DOM element.
*
* @param WebDriverElement $other
* @return boolean
*/
public function equals(WebDriverElement $other) {
try {
return $this->element->equals($other);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
private function dispatchOnException($exception) {
$this->dispatch(
'onException',
$exception,
$this->dispatcher->getDefaultDriver()
);
throw $exception;
}
}
PK k?V] + lib/support/events/EventFiringWebDriver.phpnu W+A dispatcher = $dispatcher ?: new WebDriverDispatcher();
if (!$this->dispatcher->getDefaultDriver()) {
$this->dispatcher->setDefaultDriver($this);
}
$this->driver = $driver;
return $this;
}
/**
* @return WebDriverDispatcher
*/
public function getDispatcher() {
return $this->dispatcher;
}
/**
* @param $method
*/
protected function dispatch($method) {
if (!$this->dispatcher) {
return;
}
$arguments = func_get_args();
unset($arguments[0]);
$this->dispatcher->dispatch($method, $arguments);
}
/**
* @return WebDriver
*/
public function getWebDriver() {
return $this->driver;
}
/**
* @param WebDriverElement $element
* @return EventFiringWebElement
*/
private function newElement(WebDriverElement $element) {
return new EventFiringWebElement($element, $this->getDispatcher());
}
/**
* @param $url
* @return $this
* @throws WebDriverException
*/
public function get($url) {
$this->dispatch('beforeNavigateTo', $url, $this);
try {
$this->driver->get($url);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch('afterNavigateTo', $url, $this);
return $this;
}
/**
* @param WebDriverBy $by
* @return array
* @throws WebDriverException
*/
public function findElements(WebDriverBy $by) {
$this->dispatch('beforeFindBy', $by, null, $this);
try {
$elements = array();
foreach ($this->driver->findElements($by) as $element) {
$elements[] = $this->newElement($element);
}
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch('afterFindBy', $by, null, $this);
return $elements;
}
/**
* @param WebDriverBy $by
* @return EventFiringWebElement
* @throws WebDriverException
*/
public function findElement(WebDriverBy $by) {
$this->dispatch('beforeFindBy', $by, null, $this);
try {
$element = $this->newElement($this->driver->findElement($by));
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch('afterFindBy', $by, null, $this);
return $element;
}
/**
* @param $script
* @param array $arguments
* @return mixed
* @throws WebDriverException
*/
public function executeScript($script, array $arguments = array()) {
$this->dispatch('beforeScript', $script, $this);
try {
$result = $this->driver->executeScript($script, $arguments);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
$this->dispatch('afterScript', $script, $this);
return $result;
}
/**
* @return $this
* @throws WebDriverException
*/
public function close() {
try {
$this->driver->close();
return $this;
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getCurrentURL() {
try {
return $this->driver->getCurrentURL();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getPageSource() {
try {
return $this->driver->getPageSource();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getTitle() {
try {
return $this->driver->getTitle();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return string
* @throws WebDriverException
*/
public function getWindowHandle() {
try {
return $this->driver->getWindowHandle();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return array
* @throws WebDriverException
*/
public function getWindowHandles() {
try {
return $this->driver->getWindowHandles();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @throws WebDriverException
*/
public function quit() {
try {
$this->driver->quit();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @param null $save_as
* @return string
* @throws WebDriverException
*/
public function takeScreenshot($save_as = null) {
try {
return $this->driver->takeScreenshot($save_as);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @param int $timeout_in_second
* @param int $interval_in_millisecond
* @return WebDriverWait
* @throws WebDriverException
*/
public function wait($timeout_in_second = 30,
$interval_in_millisecond = 250) {
try {
return $this->driver->wait($timeout_in_second, $interval_in_millisecond);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverOptions
* @throws WebDriverException
*/
public function manage() {
try {
return $this->driver->manage();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return EventFiringWebDriverNavigation
* @throws WebDriverException
*/
public function navigate() {
try {
return new EventFiringWebDriverNavigation(
$this->driver->navigate(),
$this->getDispatcher()
);
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverTargetLocator
* @throws WebDriverException
*/
public function switchTo() {
try {
return $this->driver->switchTo();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* @return WebDriverTouchScreen
* @throws WebDriverException
*/
public function getTouch() {
try {
return $this->driver->getTouch();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
/**
* Get the element on the page that currently has focus.
*
* @return WebDriverElement
*/
public function getActiveElement() {
try {
return $this->driver->getActiveElement();
} catch (WebDriverException $exception) {
$this->dispatchOnException($exception);
}
}
private function dispatchOnException($exception) {
$this->dispatch('onException', $exception, $this);
throw $exception;
}
}
PK k?V lib/WebDriverWindow.phpnu W+A executor = $executor;
}
/**
* Get the position of the current window, relative to the upper left corner
* of the screen.
*
* @return array The current window position.
*/
public function getPosition() {
$position = $this->executor->execute(
'getWindowPosition',
array(':windowHandle' => 'current')
);
return new WebDriverPoint(
$position['x'],
$position['y']
);
}
/**
* Get the size of the current window. This will return the outer window
* dimension, not just the view port.
*
* @return array The current window size.
*/
public function getSize() {
$size = $this->executor->execute(
'getWindowSize',
array(':windowHandle' => 'current')
);
return new WebDriverDimension(
$size['width'],
$size['height']
);
}
/**
* Maximizes the current window if it is not already maximized
*
* @return WebDriverWindow The instance.
*/
public function maximize() {
$this->executor->execute(
'maximizeWindow',
array(':windowHandle' => 'current')
);
return $this;
}
/**
* Set the size of the current window. This will change the outer window
* dimension, not just the view port.
*
* @param int $width The target window width.
* @param int $height The target height height.
* @return WebDriverWindow The instance.
*/
public function setSize(WebDriverDimension $size) {
$params = array(
'width' => $size->getWidth(),
'height' => $size->getHeight(),
':windowHandle' => 'current',
);
$this->executor->execute('setWindowSize', $params);
return $this;
}
/**
* Set the position of the current window. This is relative to the upper left
* corner of the screen.
*
* @param int $width The target window width.
* @param int $height The target height height.
* @return WebDriverWindow The instance.
*/
public function setPosition(WebDriverPoint $position) {
$params = array(
'x' => $position->getX(),
'y' => $position->getY(),
':windowHandle' => 'current',
);
$this->executor->execute('setWindowPosition', $params);
return $this;
}
/**
* Get the current browser orientation.
*
* @return string Either LANDSCAPE|PORTRAIT
*/
public function getScreenOrientation() {
return $this->executor->execute('getScreenOrientation');
}
/**
* Set the browser orientation. The orientation should either
* LANDSCAPE|PORTRAIT
*
* @param string $orientation
* @return WebDriverWindow The instance.
* @throws IndexOutOfBoundsWebDriverError
*/
public function setScreenOrientation($orientation) {
$orientation = strtoupper($orientation);
if (!in_array($orientation, array('PORTRAIT', 'LANDSCAPE'))) {
throw new IndexOutOfBoundsWebDriverError(
"Orientation must be either PORTRAIT, or LANDSCAPE"
);
}
$this->executor->execute(
'setScreenOrientation',
array('orientation' => $orientation)
);
return $this;
}
}
PK k?V
composer.jsonnu W+A {
"name": "facebook/webdriver",
"description": "A php client for WebDriver",
"homepage": "https://github.com/facebook/php-webdriver",
"license": "Apache-2.0",
"require": {
"php": ">=5.4.20"
},
"autoload": {
"classmap": ["lib/"]
}
}
PK k?Vm example.phpnu W+A 'firefox');
$driver = new RemoteWebDriver($host, $capabilities);
// navigate to 'http://docs.seleniumhq.org/'
$driver->get('http://docs.seleniumhq.org/');
// click the link 'About'
$link = $driver->findElement(
WebDriverBy::id('menu_about')
);
$link->click();
// print the title of the current page
echo "The title is " . $driver->getTitle() . "'\n";
// print the title of the current page
echo "The current URI is " . $driver->getCurrentURL() . "'\n";
// Search 'php' in the search box
$input = $driver->findElement(
WebDriverBy::id('q')
);
$input->sendKeys('php')->submit();
// wait at most 10 seconds until at least one result is shown
$driver->wait(10)->until(
WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
WebDriverBy::className('gsc-result')
)
);
// close the Firefox
$driver->quit();
PK k?V
c README.mdnu W+A php-webdriver -- WebDriver bindings for PHP
===========================================
## DESCRIPTION
This WebDriver client aims to be as close as possible to bindings in other languages. The concepts are very similar to the Java, .NET, Python and Ruby bindings for WebDriver.
Looking for documentation about Selenium WebDriver? See http://docs.seleniumhq.org/docs/ and https://code.google.com/p/selenium/wiki
The PHP client was rewritten from scratch. Using the old version? Check out Adam Goucher's fork of it at https://github.com/Element-34/php-webdriver
Any complaint, question, idea? You can post it on the user group https://www.facebook.com/groups/phpwebdriver/.
## GETTING THE CODE
* git clone git@github.com:facebook/php-webdriver.git
* If you are using Packagist, add the dependency. https://packagist.org/packages/facebook/webdriver
{
"require": {
"facebook/webdriver": "dev-master"
}
}
## GETTING STARTED
* All you need as the server for this client is the selenium-server-standalone-#.jar file provided here: http://code.google.com/p/selenium/downloads/list
* Download and run that file, replacing # with the current server version.
java -jar selenium-server-standalone-#.jar
* Then when you create a session, be sure to pass the url to where your server is running.
// This would be the url of the host running the server-standalone.jar
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox');
$driver = new RemoteWebDriver($host, $capabilities);
* The $capabilities array lets you specify (among other things) which browser to use. See https://code.google.com/p/selenium/wiki/DesiredCapabilities for more details.
## MORE INFORMATION
Check out the Selenium docs and wiki at http://docs.seleniumhq.org/docs/ and https://code.google.com/p/selenium/wiki
## SUPPORT
We have a great community willing to try and help you!
Currently we offer support in two manners:
### Via our Facebook Group
If you have questions or are an active contributor consider joining our facebook group and contributing to the communal discussion and support
https://www.facebook.com/groups/phpwebdriver/
### Via Github
If you're reading this you've already found our Github repository. If you have a question, feel free to submit it as an issue and our staff will do their best to help you as soon as possible.
## CONTRIBUTING
We love to have your help to make php-webdriver better. Feel free to
* open an [issue](https://github.com/facebook/php-webdriver/issues) if you run into any problem.
* fork the project and submit [pull request](https://github.com/facebook/php-webdriver/pulls). Before the pull requests can be accepted, a [Contributors Licensing Agreement](http://developers.facebook.com/opensource/cla) must be signed.
When you are going to contribute, please keep in mind that this webdriver client aims to be as close as possible to other languages Java/Ruby/Python/C#.
FYI, here is the overview of [the official Java API](http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html?overview-summary.html)
PK k?VW W lib/WebDriverTargetLocator.phpnu W+A PK k?Ve0Y lib/WebDriverNavigation.phpnu W+A PK k?VU lib/WebDriverSearchContext.phpnu W+A PK k?VCa lib/WebDriverDimension.phpnu W+A PK k?V0ʱM M lib/WebDriverExceptions.phpnu W+A PK k?V.Dt t 8 lib/WebDriver.phpnu W+A PK k?Vr~ǀ 6I lib/WebDriverHasInputDevices.phpnu W+A PK k?Vvr r M lib/WebDriverMouse.phpnu W+A PK k?V]= Q lib/WebDriverAction.phpnu W+A PK k?V&ҍ T lib/WebDriverElement.phpnu W+A PK k?Vn # e lib/internal/WebDriverLocatable.phpnu W+A PK k?V]]- - 3i lib/WebDriverWait.phpnu W+A PK k?V_\ \ q lib/WebDriverBy.phpnu W+A PK k?V{v2 v2 " D} lib/WebDriverExpectedCondition.phpnu W+A PK k?Vw#~ ~ lib/WebDriverPoint.phpnu W+A PK k?Vs> з lib/remote/RemoteMouse.phpnu W+A PK k?Vgi i lib/remote/RemoteWebDriver.phpnu W+A PK k?V[ lib/remote/RemoteTouchScreen.phpnu W+A PK k?VeQN N # lib/remote/RemoteKeyboard.phpnu W+A PK k?VwJ' ' lib/remote/RemoteWebElement.phpnu W+A PK k?VRK1 1 " 4 lib/remote/HttpCommandExecutor.phpnu W+A PK k?VRT T # F lib/remote/WebDriverBrowserType.phpnu W+A PK k?Vۙv &