SIGN IN SIGN UP
SeleniumHQ / selenium UNCLAIMED

A browser automation framework and ecosystem.

0 0 285 Java
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you 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.
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
/**
* @fileoverview Defines an {@linkplain cmd.Executor command executor} that
* communicates with a remote end using HTTP + JSON.
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
*/
2020-08-03 17:56:31 +03:00
'use strict'
const http = require('node:http')
const https = require('node:https')
const url = require('node:url')
2020-08-03 17:56:31 +03:00
const httpLib = require('../lib/http')
/**
* @typedef {{protocol: (?string|undefined),
* auth: (?string|undefined),
* hostname: (?string|undefined),
* host: (?string|undefined),
* port: (?string|undefined),
* path: (?string|undefined),
* pathname: (?string|undefined)}}
*/
let RequestOptions // eslint-disable-line
/**
* @param {string} aUrl The request URL to parse.
* @return {RequestOptions} The request options.
* @throws {Error} if the URL does not include a hostname.
*/
function getRequestOptions(aUrl) {
// eslint-disable-next-line n/no-deprecated-api
2020-08-03 17:56:31 +03:00
let options = url.parse(aUrl)
if (!options.hostname) {
2020-08-03 17:56:31 +03:00
throw new Error('Invalid URL: ' + aUrl)
}
// Delete the search and has portions as they are not used.
2020-08-03 17:56:31 +03:00
options.search = null
options.hash = null
options.path = options.pathname
options.hostname = options.hostname === 'localhost' ? '127.0.0.1' : options.hostname // To support Node 17 and above. Refer https://github.com/nodejs/node/issues/40702 for details.
2020-08-03 17:56:31 +03:00
return options
}
2018-03-30 20:05:04 -07:00
/** @const {string} */
2020-08-03 17:56:31 +03:00
const USER_AGENT = (function () {
const version = require('../package.json').version
const platform = { darwin: 'mac', win32: 'windows' }[process.platform] || 'linux'
2020-08-03 17:56:31 +03:00
return `selenium/${version} (js ${platform})`
})()
2018-03-30 20:05:04 -07:00
/**
* A basic HTTP client used to send messages to a remote end.
*
* @implements {httpLib.Client}
*/
class HttpClient {
/**
* @param {string} serverUrl URL for the WebDriver server to send commands to.
* @param {http.Agent=} opt_agent The agent to use for each request.
* Defaults to `http.globalAgent`.
* @param {?string=} opt_proxy The proxy to use for the connection to the
* server. Default is to use no proxy.
* @param {?Object.<string,Object>} client_options
*/
constructor(serverUrl, opt_agent, opt_proxy, client_options = {}) {
/** @private {http.Agent} */
2020-08-03 17:56:31 +03:00
this.agent_ = opt_agent || null
/**
* Base options for each request.
* @private {RequestOptions}
*/
2020-08-03 17:56:31 +03:00
this.options_ = getRequestOptions(serverUrl)
/**
* client options, header overrides
*/
this.client_options = client_options
/**
* sets keep-alive for the agent
* see https://stackoverflow.com/a/58332910
*/
this.keepAlive = this.client_options['keep-alive']
/** @private {?RequestOptions} */
2020-08-03 17:56:31 +03:00
this.proxyOptions_ = opt_proxy ? getRequestOptions(opt_proxy) : null
}
get keepAlive() {
return this.agent_.keepAlive
}
set keepAlive(value) {
if (value === 'true' || value === true) {
this.agent_.keepAlive = true
}
}
/** @override */
send(httpRequest) {
2020-08-03 17:56:31 +03:00
let data
2020-08-03 17:56:31 +03:00
let headers = {}
if (httpRequest.headers) {
2020-08-03 17:56:31 +03:00
httpRequest.headers.forEach(function (value, name) {
headers[name] = value
})
}
headers['User-Agent'] = this.client_options['user-agent'] || USER_AGENT
2020-08-03 17:56:31 +03:00
headers['Content-Length'] = 0
if (httpRequest.method == 'POST' || httpRequest.method == 'PUT') {
2020-08-03 17:56:31 +03:00
data = JSON.stringify(httpRequest.data)
headers['Content-Length'] = Buffer.byteLength(data, 'utf8')
headers['Content-Type'] = 'application/json;charset=UTF-8'
}
2020-08-03 17:56:31 +03:00
let path = this.options_.path
if (path.endsWith('/') && httpRequest.path.startsWith('/')) {
2020-08-03 17:56:31 +03:00
path += httpRequest.path.substring(1)
} else {
2020-08-03 17:56:31 +03:00
path += httpRequest.path
}
// eslint-disable-next-line n/no-deprecated-api
2020-08-03 17:56:31 +03:00
let parsedPath = url.parse(path)
let options = {
agent: this.agent_ || null,
method: httpRequest.method,
auth: this.options_.auth,
hostname: this.options_.hostname,
port: this.options_.port,
protocol: this.options_.protocol,
path: parsedPath.path,
pathname: parsedPath.pathname,
search: parsedPath.search,
hash: parsedPath.hash,
headers,
2020-08-03 17:56:31 +03:00
}
return new Promise((fulfill, reject) => {
2020-08-03 17:56:31 +03:00
sendRequest(options, fulfill, reject, data, this.proxyOptions_)
})
}
}
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
/**
* Sends a single HTTP request.
* @param {!Object} options The request options.
* @param {function(!httpLib.Response)} onOk The function to call if the
* request succeeds.
* @param {function(!Error)} onError The function to call if the request fails.
* @param {?string=} opt_data The data to send with the request.
* @param {?RequestOptions=} opt_proxy The proxy server to use for the request.
* @param {number=} opt_retries The current number of retries.
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
*/
function sendRequest(options, onOk, onError, opt_data, opt_proxy, opt_retries) {
2020-08-03 17:56:31 +03:00
var hostname = options.hostname
var port = options.port
if (opt_proxy) {
2020-08-03 17:56:31 +03:00
let proxy = /** @type {RequestOptions} */ (opt_proxy)
// RFC 2616, section 5.1.2:
// The absoluteURI form is REQUIRED when the request is being made to a
// proxy.
2020-08-03 17:56:31 +03:00
let absoluteUri = url.format(options)
// RFC 2616, section 14.23:
// An HTTP/1.1 proxy MUST ensure that any request message it forwards does
// contain an appropriate Host header field that identifies the service
// being requested by the proxy.
2020-08-03 17:56:31 +03:00
let targetHost = options.hostname
if (options.port) {
2020-08-03 17:56:31 +03:00
targetHost += ':' + options.port
}
// Update the request options with our proxy info.
2020-08-03 17:56:31 +03:00
options.headers['Host'] = targetHost
options.path = absoluteUri
options.host = proxy.host
options.hostname = proxy.hostname
options.port = proxy.port
// Update the protocol to avoid EPROTO errors when the webdriver proxy
// uses a different protocol from the remote selenium server.
2020-08-03 17:56:31 +03:00
options.protocol = opt_proxy.protocol
if (proxy.auth) {
options.headers['Proxy-Authorization'] = 'Basic ' + Buffer.from(proxy.auth).toString('base64')
}
}
2020-08-03 17:56:31 +03:00
let requestFn = options.protocol === 'https:' ? https.request : http.request
var request = requestFn(options, function onResponse(response) {
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
if (response.statusCode == 302 || response.statusCode == 303) {
let location
try {
// eslint-disable-next-line n/no-deprecated-api
location = url.parse(response.headers['location'])
} catch (ex) {
2020-08-03 17:56:31 +03:00
onError(
Error(
'Failed to parse "Location" header for server redirect: ' +
2020-08-03 17:56:31 +03:00
ex.message +
'\nResponse was: \n' +
new httpLib.Response(response.statusCode, response.headers, ''),
),
2020-08-03 17:56:31 +03:00
)
return
}
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
if (!location.hostname) {
2020-08-03 17:56:31 +03:00
location.hostname = hostname
location.port = port
location.auth = options.auth
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
}
request.destroy()
2020-08-03 17:56:31 +03:00
sendRequest(
{
method: 'GET',
protocol: location.protocol || options.protocol,
hostname: location.hostname,
port: location.port,
path: location.path,
auth: location.auth,
pathname: location.pathname,
search: location.search,
hash: location.hash,
headers: {
Accept: 'application/json; charset=utf-8',
'User-Agent': options.headers['User-Agent'] || USER_AGENT,
2020-08-03 17:56:31 +03:00
},
},
onOk,
onError,
undefined,
opt_proxy,
2020-08-03 17:56:31 +03:00
)
return
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
}
const body = []
2020-08-03 17:56:31 +03:00
response.on('data', body.push.bind(body))
response.on('end', function () {
const resp = new httpLib.Response(
2020-08-03 17:56:31 +03:00
/** @type {number} */ (response.statusCode),
/** @type {!Object<string>} */ (response.headers),
Buffer.concat(body).toString('utf8').replace(/\0/g, ''),
2020-08-03 17:56:31 +03:00
)
onOk(resp)
})
})
request.on('error', function (e) {
if (typeof opt_retries === 'undefined') {
2020-08-03 17:56:31 +03:00
opt_retries = 0
}
if (shouldRetryRequest(opt_retries, e)) {
2020-08-03 17:56:31 +03:00
opt_retries += 1
setTimeout(function () {
sendRequest(options, onOk, onError, opt_data, opt_proxy, opt_retries)
}, 15)
} else {
let message = e.message
if (e.code) {
2020-08-03 17:56:31 +03:00
message = e.code + ' ' + message
}
2020-08-03 17:56:31 +03:00
onError(new Error(message))
}
2020-08-03 17:56:31 +03:00
})
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
if (opt_data) {
2020-08-03 17:56:31 +03:00
request.write(opt_data)
JasonLeyba: The return of the WebDriver JSAPI. This initial version supports Firefox, Chrome, IE, and Opera through the Java Selenium server. For the browsers that support CORS (currently Firefox + webkit), a cross-domain XHR is used to communicate with the WebDriver server. For the other browsers, we have to use JSONP. While IE technically supports CORS, it does not support sending DELETE requests via CORS. Since there are quite a few DELETE commands in the wire protocol, we have to use JSONP for IE too (yay, IE). To create a deployable webdriver.js, run $./go webdriverjs The generated file (build/javascript/webdriver-jsapi/webdriver.js) can be used in either the browser or with node. WebDriverJS may only be used in a browser already under WebDriver's control. Furthermore, the WebDriver server URL and session ID must be passed to the script via the wdurl and wdsid query parameters, respectively. To help with debugging, this change includes a simple Node app: $ ./go webdriverjs build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ java -jar build/java/server/src/org/openqa/selenium/server/server-standalone.jar $ node javascript/webdriver-jsapi/node/demo.js --help To manually run the browser demo tests: $ ./go debug-server $ node javascript/webdriver-jsapi/node/demo.js \ --browser=chrome \ --wdUrl=http://localhost:4444/wd/hub \ --url=http://localhost:2310/javascript/webdriver-jsapi/test/e2e/example_test.html There's still a lot to do: - Fix the :webdriverjs build task - Wiki/design documentation - Improve the debug story (as in, write one) - Write a pure-JS command executor using the atoms. This could theoretically be used to replace Selenium Core - Better Node integration r14327
2011-10-22 01:15:11 +00:00
}
2020-08-03 17:56:31 +03:00
request.end()
}
2020-08-03 17:56:31 +03:00
const MAX_RETRIES = 3
/**
* A retry is sometimes needed on Windows where we may quickly run out of
* ephemeral ports. A more robust solution is bumping the MaxUserPort setting
* as described here: http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
*
* @param {!number} retries
* @param {!Error} err
* @return {boolean}
*/
function shouldRetryRequest(retries, err) {
2020-08-03 17:56:31 +03:00
return retries < MAX_RETRIES && isRetryableNetworkError(err)
}
/**
* @param {!Error} err
* @return {boolean}
*/
function isRetryableNetworkError(err) {
if (err && err.code) {
2020-08-03 17:56:31 +03:00
return (
err.code === 'ECONNABORTED' ||
err.code === 'ECONNRESET' ||
err.code === 'ECONNREFUSED' ||
err.code === 'EADDRINUSE' ||
err.code === 'EPIPE' ||
err.code === 'ETIMEDOUT'
)
}
2020-08-03 17:56:31 +03:00
return false
}
// PUBLIC API
module.exports.Agent = http.Agent
module.exports.Executor = httpLib.Executor
module.exports.HttpClient = HttpClient
module.exports.Request = httpLib.Request
module.exports.Response = httpLib.Response