2015-04-04 09:53:59 -07:00
// 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
2014-11-12 19:33:37 +00:00
//
2015-04-04 09:53:59 -07:00
// http://www.apache.org/licenses/LICENSE-2.0
2014-11-12 19:33:37 +00:00
//
2015-04-04 09:53:59 -07:00
// 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
/**
2016-01-20 15:19:04 -08: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'
2016-01-19 16:28:32 -08:00
2024-04-16 01:50:58 +05:30
const http = require ( 'node:http' )
const https = require ( 'node:https' )
const url = require ( 'node:url' )
2016-02-21 14:31:06 -08:00
2020-08-03 17:56:31 +03:00
const httpLib = require ( '../lib/http' )
2016-02-21 14:31:06 -08:00
2016-06-21 13:26:43 -07:00
/**
* @typedef {{protocol: (?string|undefined),
* auth: (?string|undefined),
* hostname: (?string|undefined),
* host: (?string|undefined),
* port: (?string|undefined),
* path: (?string|undefined),
* pathname: (?string|undefined)}}
*/
2021-11-05 09:39:45 -04:00
let RequestOptions // eslint-disable-line
2016-06-21 13:26:43 -07:00
/**
* @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 ) {
2024-04-16 01:50:58 +05:30
// eslint-disable-next-line n/no-deprecated-api
2020-08-03 17:56:31 +03:00
let options = url . parse ( aUrl )
2016-06-21 13:26:43 -07:00
if ( ! options . hostname ) {
2020-08-03 17:56:31 +03:00
throw new Error ( 'Invalid URL: ' + aUrl )
2016-06-21 13:26:43 -07:00
}
// 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
2024-02-07 16:07:24 +00:00
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
2016-06-21 13:26:43 -07:00
}
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
2024-02-07 16:07:24 +00:00
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
2016-01-19 16:28:32 -08:00
/**
* A basic HTTP client used to send messages to a remote end.
2016-05-15 11:47:21 -07:00
*
* @implements {httpLib.Client}
2016-01-19 16:28:32 -08:00
*/
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`.
2016-02-08 21:43:09 -08:00
* @param {?string=} opt_proxy The proxy to use for the connection to the
2016-01-19 16:28:32 -08:00
* server. Default is to use no proxy.
2021-07-15 23:22:43 +05:30
* @param {?Object.<string,Object>} client_options
2016-01-19 16:28:32 -08:00
*/
2021-07-15 23:22:43 +05:30
constructor ( serverUrl , opt _agent , opt _proxy , client _options = { } ) {
2016-01-19 16:28:32 -08:00
/** @private {http.Agent} */
2020-08-03 17:56:31 +03:00
this . agent _ = opt _agent || null
2016-01-19 16:28:32 -08:00
/**
* Base options for each request.
2016-06-21 13:26:43 -07:00
* @private {RequestOptions}
2016-01-19 16:28:32 -08:00
*/
2020-08-03 17:56:31 +03:00
this . options _ = getRequestOptions ( serverUrl )
2016-06-21 13:26:43 -07:00
2021-07-15 23:22:43 +05:30
/**
* 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' ]
2021-11-05 09:39:45 -04:00
/** @private {?RequestOptions} */
2020-08-03 17:56:31 +03:00
this . proxyOptions _ = opt _proxy ? getRequestOptions ( opt _proxy ) : null
2014-07-17 14:52:56 -07:00
}
2014-11-04 09:38:15 +01:00
2021-07-15 23:22:43 +05:30
get keepAlive ( ) {
return this . agent _ . keepAlive
}
set keepAlive ( value ) {
if ( value === 'true' || value === true ) {
this . agent _ . keepAlive = true
}
}
2016-05-15 11:47:21 -07:00
/** @override */
2016-01-19 16:28:32 -08:00
send ( httpRequest ) {
2020-08-03 17:56:31 +03:00
let data
2016-02-08 21:43:09 -08:00
2020-08-03 17:56:31 +03:00
let headers = { }
2019-01-25 12:56:25 +05:30
if ( httpRequest . headers ) {
2020-08-03 17:56:31 +03:00
httpRequest . headers . forEach ( function ( value , name ) {
headers [ name ] = value
} )
2019-01-25 12:56:25 +05:30
}
2016-02-08 21:43:09 -08:00
2021-07-15 23:22:43 +05:30
headers [ 'User-Agent' ] = this . client _options [ 'user-agent' ] || USER _AGENT
2020-08-03 17:56:31 +03:00
headers [ 'Content-Length' ] = 0
2016-01-19 16:28:32 -08:00
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'
2016-01-19 16:28:32 -08:00
}
2020-08-03 17:56:31 +03:00
let path = this . options _ . path
2016-06-21 13:26:43 -07:00
if ( path . endsWith ( '/' ) && httpRequest . path . startsWith ( '/' ) ) {
2020-08-03 17:56:31 +03:00
path += httpRequest . path . substring ( 1 )
2016-01-19 16:28:32 -08:00
} else {
2020-08-03 17:56:31 +03:00
path += httpRequest . path
2016-01-19 16:28:32 -08:00
}
2024-04-16 01:50:58 +05:30
// eslint-disable-next-line n/no-deprecated-api
2020-08-03 17:56:31 +03:00
let parsedPath = url . parse ( path )
2016-01-19 16:28:32 -08:00
2016-06-21 13:26:43 -07:00
let options = {
agent : this . agent _ || null ,
2016-01-19 16:28:32 -08:00
method : httpRequest . method ,
2016-06-21 13:26:43 -07:00
2016-01-19 16:28:32 -08:00
auth : this . options _ . auth ,
2016-06-21 13:26:43 -07:00
hostname : this . options _ . hostname ,
2016-01-19 16:28:32 -08:00
port : this . options _ . port ,
2016-04-01 17:19:59 -07:00
protocol : this . options _ . protocol ,
2016-01-19 16:28:32 -08:00
2016-06-21 13:26:43 -07:00
path : parsedPath . path ,
pathname : parsedPath . pathname ,
search : parsedPath . search ,
hash : parsedPath . hash ,
2016-01-19 16:28:32 -08:00
2016-06-21 13:26:43 -07:00
headers ,
2020-08-03 17:56:31 +03:00
}
2016-06-21 13:26:43 -07:00
return new Promise ( ( fulfill , reject ) => {
2020-08-03 17:56:31 +03:00
sendRequest ( options , fulfill , reject , data , this . proxyOptions _ )
} )
2016-01-19 16:28:32 -08: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
/**
* Sends a single HTTP request.
* @param {!Object} options The request options.
2016-05-15 11:47:21 -07:00
* @param {function(!httpLib.Response)} onOk The function to call if the
2015-11-13 14:12:26 -08:00
* request succeeds.
* @param {function(!Error)} onError The function to call if the request fails.
2016-02-08 21:43:09 -08:00
* @param {?string=} opt_data The data to send with the request.
2016-06-21 13:26:43 -07:00
* @param {?RequestOptions=} opt_proxy The proxy server to use for the request.
2017-10-29 13:57:44 -04:00
* @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
*/
2017-10-29 13:57:44 -04: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
2014-11-04 09:38:15 +01:00
if ( opt _proxy ) {
2020-08-03 17:56:31 +03:00
let proxy = /** @type {RequestOptions} */ ( opt _proxy )
2016-06-21 13:26:43 -07:00
// 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 )
2016-06-21 13:26:43 -07:00
// 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
2016-06-21 13:26:43 -07:00
if ( options . port ) {
2020-08-03 17:56:31 +03:00
targetHost += ':' + options . port
2016-06-21 13:26:43 -07:00
}
2014-11-04 09:38:15 +01:00
2016-06-21 13:26:43 -07:00
// 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
2014-11-04 09:38:15 +01:00
2019-09-10 12:53:16 +02:00
// 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
2019-09-10 12:53:16 +02:00
2014-11-04 09:38:15 +01:00
if ( proxy . auth ) {
2024-02-07 16:07:24 +00:00
options . headers [ 'Proxy-Authorization' ] = 'Basic ' + Buffer . from ( proxy . auth ) . toString ( 'base64' )
2014-11-04 09:38:15 +01:00
}
}
2020-08-03 17:56:31 +03:00
let requestFn = options . protocol === 'https:' ? https . request : http . request
2016-04-01 17:19:59 -07:00
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 ) {
2021-11-05 09:39:45 -04:00
let location
2014-05-23 12:54:07 -07:00
try {
2024-04-16 01:50:58 +05:30
// eslint-disable-next-line n/no-deprecated-api
2021-11-05 09:39:45 -04:00
location = url . parse ( response . headers [ 'location' ] )
2014-05-23 12:54:07 -07:00
} catch ( ex ) {
2020-08-03 17:56:31 +03:00
onError (
Error (
2014-05-23 12:54:07 -07:00
'Failed to parse "Location" header for server redirect: ' +
2020-08-03 17:56:31 +03:00
ex . message +
'\nResponse was: \n' +
2024-02-07 16:07:24 +00:00
new httpLib . Response ( response . statusCode , response . headers , '' ) ,
) ,
2020-08-03 17:56:31 +03:00
)
return
2014-05-23 12:54:07 -07: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 ( ! 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
}
2021-11-05 09:39:45 -04: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' ,
2021-07-15 23:22:43 +05:30
'User-Agent' : options . headers [ 'User-Agent' ] || USER _AGENT ,
2020-08-03 17:56:31 +03:00
} ,
} ,
onOk ,
onError ,
undefined ,
2024-02-07 16:07:24 +00:00
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
}
2021-11-05 09:39:45 -04:00
const body = [ ]
2020-08-03 17:56:31 +03:00
response . on ( 'data' , body . push . bind ( body ) )
response . on ( 'end' , function ( ) {
2021-11-05 09:39:45 -04:00
const resp = new httpLib . Response (
2020-08-03 17:56:31 +03:00
/** @type {number} */ ( response . statusCode ) ,
/** @type {!Object<string>} */ ( response . headers ) ,
2024-02-07 16:07:24 +00:00
Buffer . concat ( body ) . toString ( 'utf8' ) . replace ( /\0/g , '' ) ,
2020-08-03 17:56:31 +03:00
)
onOk ( resp )
} )
} )
request . on ( 'error' , function ( e ) {
2017-10-29 13:57:44 -04:00
if ( typeof opt _retries === 'undefined' ) {
2020-08-03 17:56:31 +03:00
opt _retries = 0
2017-10-29 13:57:44 -04:00
}
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 )
Update WebDriverJS to support parallel flows. Documentation to follow in a future
update to the WebDriverJs wiki page.
This change renames several low-level classes and functions in the promise module:
promise.Application -> promise.ControlFlow
#schedule(string, function) -> #execute(function, [string])
#scheduleTimeout(string, number) -> #timeout(number, [string])
#scheduleWait(string, function, number, [string]) -> #wait(function, number, [string])
The old schedule* functions are still present, but will print a warning message if called.
They will be removed in 2.31.
This change also renames the //javascript/node:webdriver target to
//javascript/node:selenium-webdriver. We will soon publish the module to npm as
"selenium-webdriver".
Fixes issue 4640.
2013-01-27 15:00:18 -08:00
} else {
2021-11-05 09:39:45 -04:00
let message = e . message
Update WebDriverJS to support parallel flows. Documentation to follow in a future
update to the WebDriverJs wiki page.
This change renames several low-level classes and functions in the promise module:
promise.Application -> promise.ControlFlow
#schedule(string, function) -> #execute(function, [string])
#scheduleTimeout(string, number) -> #timeout(number, [string])
#scheduleWait(string, function, number, [string]) -> #wait(function, number, [string])
The old schedule* functions are still present, but will print a warning message if called.
They will be removed in 2.31.
This change also renames the //javascript/node:webdriver target to
//javascript/node:selenium-webdriver. We will soon publish the module to npm as
"selenium-webdriver".
Fixes issue 4640.
2013-01-27 15:00:18 -08:00
if ( e . code ) {
2020-08-03 17:56:31 +03:00
message = e . code + ' ' + message
Update WebDriverJS to support parallel flows. Documentation to follow in a future
update to the WebDriverJs wiki page.
This change renames several low-level classes and functions in the promise module:
promise.Application -> promise.ControlFlow
#schedule(string, function) -> #execute(function, [string])
#scheduleTimeout(string, number) -> #timeout(number, [string])
#scheduleWait(string, function, number, [string]) -> #wait(function, number, [string])
The old schedule* functions are still present, but will print a warning message if called.
They will be removed in 2.31.
This change also renames the //javascript/node:webdriver target to
//javascript/node:selenium-webdriver. We will soon publish the module to npm as
"selenium-webdriver".
Fixes issue 4640.
2013-01-27 15:00:18 -08:00
}
2020-08-03 17:56:31 +03:00
onError ( new Error ( message ) )
Update WebDriverJS to support parallel flows. Documentation to follow in a future
update to the WebDriverJs wiki page.
This change renames several low-level classes and functions in the promise module:
promise.Application -> promise.ControlFlow
#schedule(string, function) -> #execute(function, [string])
#scheduleTimeout(string, number) -> #timeout(number, [string])
#scheduleWait(string, function, number, [string]) -> #wait(function, number, [string])
The old schedule* functions are still present, but will print a warning message if called.
They will be removed in 2.31.
This change also renames the //javascript/node:webdriver target to
//javascript/node:selenium-webdriver. We will soon publish the module to npm as
"selenium-webdriver".
Fixes issue 4640.
2013-01-27 15:00:18 -08:00
}
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 ( )
2016-01-19 16:28:32 -08:00
}
2013-02-19 20:10:39 -08:00
2020-08-03 17:56:31 +03:00
const MAX _RETRIES = 3
2017-10-29 13:57:44 -04:00
/**
* 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 )
2017-10-29 13:57:44 -04:00
}
/**
* @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'
)
2017-10-29 13:57:44 -04:00
}
2020-08-03 17:56:31 +03:00
return false
2017-10-29 13:57:44 -04:00
}
2016-01-19 16:28:32 -08:00
// PUBLIC API
2014-02-02 18:56:15 -08:00
2021-11-05 09:39:45 -04:00
module . exports . Agent = http . Agent
module . exports . Executor = httpLib . Executor
module . exports . HttpClient = HttpClient
module . exports . Request = httpLib . Request
module . exports . Response = httpLib . Response