topical media & game development
mobile-query-three-tmp-selenium-php-vendor-php-webdriver-master-WebDriverBase.php / php
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
abstract class WebDriverBase {
public static function throwException(message, status_code) {
case 0:
// Success
break;
case 1:
throw new IndexOutOfBoundsWebDriverError(results);
case 2:
throw new NoCollectionWebDriverError(results);
case 3:
throw new NoStringWebDriverError(results);
case 4:
throw new NoStringLengthWebDriverError(results);
case 5:
throw new NoStringWrapperWebDriverError(results);
case 6:
throw new NoSuchDriverWebDriverError(results);
case 7:
throw new NoSuchElementWebDriverError(results);
case 8:
throw new NoSuchFrameWebDriverError(results);
case 9:
throw new UnknownCommandWebDriverError(results);
case 10:
throw new ObsoleteElementWebDriverError(results);
case 11:
throw new ElementNotDisplayedWebDriverError(results);
case 12:
throw new InvalidElementStateWebDriverError(results);
case 13:
throw new UnhandledWebDriverError(results);
case 14:
throw new ExpectedWebDriverError(results);
case 15:
throw new ElementNotSelectableWebDriverError(results);
case 16:
throw new NoSuchDocumentWebDriverError(results);
case 17:
throw new UnexpectedJavascriptWebDriverError(results);
case 18:
throw new NoScriptResultWebDriverError(results);
case 19:
throw new XPathLookupWebDriverError(results);
case 20:
throw new NoSuchCollectionWebDriverError(results);
case 21:
throw new TimeOutWebDriverError(results);
case 22:
throw new NullPointerWebDriverError(results);
case 23:
throw new NoSuchWindowWebDriverError(results);
case 24:
throw new InvalidCookieDomainWebDriverError(results);
case 25:
throw new UnableToSetCookieWebDriverError(results);
case 26:
throw new UnexpectedAlertOpenWebDriverError(results);
case 27:
throw new NoAlertOpenWebDriverError(results);
case 28:
throw new ScriptTimeoutWebDriverError(results);
case 29:
throw new InvalidElementCoordinatesWebDriverError(results);
case 30:
throw new IMENotAvailableWebDriverError(results);
case 31:
throw new IMEEngineActivationFailedWebDriverError(results);
case 32:
throw new InvalidSelectorWebDriverError(results);
}
}
abstract protected function methods();
protected url = 'http://localhost:4444/wd/hub') {
url;
}
public function __toString() {
return this->url;
}
Curl request to webdriver server.
command If not defined in methods() this function will throw.
params" is appended to url
protected function curl(
http_method,
params = null,
params && is_array(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',
http_method,
json_encode(url = sprintf('\%s\%s', command);
if (params) || is_string(url .= '/' . curl = curl_init(curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
http_method === 'POST') {
curl_setopt(params && is_array(curl, CURLOPT_POSTFIELDS, json_encode(http_method == 'DELETE') {
curl_setopt(extra_opts as value) {
curl_setopt(option, raw_results = trim(WebDriverEnvironment::CurlExec(info = curl_getinfo(error = curl_error(msg = sprintf(
'Curl error thrown for http \%s to \%s',
url);
if (params)) {
params));
}
throw new WebDriverCurlException(error);
}
curl_close(results = json_decode(value = null;
if (is_array(results)) {
results['value'];
}
value) && array_key_exists('message', message = results['status'], results);
return array('value' => info);
}
public function __call(arguments) {
if (count(name, http_method = strtoupper(webdriver_command = strtolower(substr(http_method)));
this->getHTTPMethod(http_method === http_method,
webdriver_command));
}
this->methods();
if (!in_array(methods[http_method,
webdriver_command = http_method = webdriver_command);
}
this->curl(
webdriver_command,
array_shift(results['value'];
}
private function getHTTPMethod(webdriver_command, webdriver_command));
}
this->methods();
methods[http_methods);
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.