Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
255
node_modules/selenium-webdriver/http/index.js
generated
vendored
Normal file
255
node_modules/selenium-webdriver/http/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Defines an {@linkplain cmd.Executor command executor} that
|
||||
* communicates with a remote end using HTTP + JSON.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const url = require('url');
|
||||
|
||||
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)}}
|
||||
*/
|
||||
var RequestOptions;
|
||||
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
let options = url.parse(aUrl);
|
||||
if (!options.hostname) {
|
||||
throw new Error('Invalid URL: ' + aUrl);
|
||||
}
|
||||
// Delete the search and has portions as they are not used.
|
||||
options.search = null;
|
||||
options.hash = null;
|
||||
options.path = options.pathname;
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
constructor(serverUrl, opt_agent, opt_proxy) {
|
||||
/** @private {http.Agent} */
|
||||
this.agent_ = opt_agent || null;
|
||||
|
||||
/**
|
||||
* Base options for each request.
|
||||
* @private {RequestOptions}
|
||||
*/
|
||||
this.options_ = getRequestOptions(serverUrl);
|
||||
|
||||
/**
|
||||
* @private {?RequestOptions}
|
||||
*/
|
||||
this.proxyOptions_ = opt_proxy ? getRequestOptions(opt_proxy) : null;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
send(httpRequest) {
|
||||
let data;
|
||||
|
||||
let headers = {};
|
||||
httpRequest.headers.forEach(function(value, name) {
|
||||
headers[name] = value;
|
||||
});
|
||||
|
||||
headers['Content-Length'] = 0;
|
||||
if (httpRequest.method == 'POST' || httpRequest.method == 'PUT') {
|
||||
data = JSON.stringify(httpRequest.data);
|
||||
headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
|
||||
headers['Content-Type'] = 'application/json;charset=UTF-8';
|
||||
}
|
||||
|
||||
let path = this.options_.path;
|
||||
if (path.endsWith('/') && httpRequest.path.startsWith('/')) {
|
||||
path += httpRequest.path.substring(1);
|
||||
} else {
|
||||
path += httpRequest.path;
|
||||
}
|
||||
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,
|
||||
};
|
||||
|
||||
return new Promise((fulfill, reject) => {
|
||||
sendRequest(options, fulfill, reject, data, this.proxyOptions_);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
|
||||
var hostname = options.hostname;
|
||||
var port = options.port;
|
||||
|
||||
if (opt_proxy) {
|
||||
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.
|
||||
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.
|
||||
let targetHost = options.hostname
|
||||
if (options.port) {
|
||||
targetHost += ':' + options.port;
|
||||
}
|
||||
|
||||
// Update the request options with our proxy info.
|
||||
options.headers['Host'] = targetHost;
|
||||
options.path = absoluteUri;
|
||||
options.host = proxy.host;
|
||||
options.hostname = proxy.hostname;
|
||||
options.port = proxy.port;
|
||||
|
||||
if (proxy.auth) {
|
||||
options.headers['Proxy-Authorization'] =
|
||||
'Basic ' + new Buffer(proxy.auth).toString('base64');
|
||||
}
|
||||
}
|
||||
|
||||
let requestFn = options.protocol === 'https:' ? https.request : http.request;
|
||||
var request = requestFn(options, function onResponse(response) {
|
||||
if (response.statusCode == 302 || response.statusCode == 303) {
|
||||
try {
|
||||
var location = url.parse(response.headers['location']);
|
||||
} catch (ex) {
|
||||
onError(Error(
|
||||
'Failed to parse "Location" header for server redirect: ' +
|
||||
ex.message + '\nResponse was: \n' +
|
||||
new httpLib.Response(response.statusCode, response.headers, '')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!location.hostname) {
|
||||
location.hostname = hostname;
|
||||
location.port = port;
|
||||
}
|
||||
|
||||
request.abort();
|
||||
sendRequest({
|
||||
method: 'GET',
|
||||
protocol: location.protocol || options.protocol,
|
||||
hostname: location.hostname,
|
||||
port: location.port,
|
||||
path: location.path,
|
||||
pathname: location.pathname,
|
||||
search: location.search,
|
||||
hash: location.hash,
|
||||
headers: {
|
||||
'Accept': 'application/json; charset=utf-8'
|
||||
}
|
||||
}, onOk, onError, undefined, opt_proxy);
|
||||
return;
|
||||
}
|
||||
|
||||
var body = [];
|
||||
response.on('data', body.push.bind(body));
|
||||
response.on('end', function() {
|
||||
var resp = new httpLib.Response(
|
||||
/** @type {number} */(response.statusCode),
|
||||
/** @type {!Object<string>} */(response.headers),
|
||||
body.join('').replace(/\0/g, ''));
|
||||
onOk(resp);
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', function(e) {
|
||||
if (e.code === 'ECONNRESET') {
|
||||
setTimeout(function() {
|
||||
sendRequest(options, onOk, onError, opt_data, opt_proxy);
|
||||
}, 15);
|
||||
} else {
|
||||
var message = e.message;
|
||||
if (e.code) {
|
||||
message = e.code + ' ' + message;
|
||||
}
|
||||
onError(new Error(message));
|
||||
}
|
||||
});
|
||||
|
||||
if (opt_data) {
|
||||
request.write(opt_data);
|
||||
}
|
||||
|
||||
request.end();
|
||||
}
|
||||
|
||||
|
||||
// PUBLIC API
|
||||
|
||||
exports.Executor = httpLib.Executor;
|
||||
exports.HttpClient = HttpClient;
|
||||
exports.Request = httpLib.Request;
|
||||
exports.Response = httpLib.Response;
|
||||
175
node_modules/selenium-webdriver/http/util.js
generated
vendored
Normal file
175
node_modules/selenium-webdriver/http/util.js
generated
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
// 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.
|
||||
|
||||
/**
|
||||
* @fileoverview Various HTTP utilities.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Executor = require('./index').Executor,
|
||||
HttpClient = require('./index').HttpClient,
|
||||
HttpRequest = require('./index').Request,
|
||||
Command = require('../lib/command').Command,
|
||||
CommandName = require('../lib/command').Name,
|
||||
error = require('../lib/error'),
|
||||
promise = require('../lib/promise');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Queries a WebDriver server for its current status.
|
||||
* @param {string} url Base URL of the server to query.
|
||||
* @return {!Promise<!Object>} A promise that resolves with
|
||||
* a hash of the server status.
|
||||
*/
|
||||
function getStatus(url) {
|
||||
var client = new HttpClient(url);
|
||||
var executor = new Executor(client);
|
||||
var command = new Command(CommandName.GET_SERVER_STATUS);
|
||||
return executor.execute(command);
|
||||
}
|
||||
|
||||
|
||||
// PUBLIC API
|
||||
|
||||
|
||||
/**
|
||||
* Queries a WebDriver server for its current status.
|
||||
* @param {string} url Base URL of the server to query.
|
||||
* @return {!Promise<!Object>} A promise that resolves with
|
||||
* a hash of the server status.
|
||||
*/
|
||||
exports.getStatus = getStatus;
|
||||
|
||||
|
||||
/**
|
||||
* Waits for a WebDriver server to be healthy and accepting requests.
|
||||
* @param {string} url Base URL of the server to query.
|
||||
* @param {number} timeout How long to wait for the server.
|
||||
* @param {Promise=} opt_cancelToken A promise used as a cancellation signal:
|
||||
* if resolved before the server is ready, the wait will be terminated
|
||||
* early with a {@link promise.CancellationError}.
|
||||
* @return {!Promise} A promise that will resolve when the server is ready, or
|
||||
* if the wait is cancelled.
|
||||
*/
|
||||
exports.waitForServer = function(url, timeout, opt_cancelToken) {
|
||||
return new Promise((onResolve, onReject) => {
|
||||
let start = Date.now();
|
||||
|
||||
let done = false;
|
||||
let resolve = (status) => {
|
||||
done = true;
|
||||
onResolve(status);
|
||||
};
|
||||
let reject = (err) => {
|
||||
done = true;
|
||||
onReject(err);
|
||||
};
|
||||
|
||||
if (opt_cancelToken) {
|
||||
opt_cancelToken.then(_ => reject(new promise.CancellationError));
|
||||
}
|
||||
|
||||
checkServerStatus();
|
||||
function checkServerStatus() {
|
||||
return getStatus(url).then(status => resolve(status), onError);
|
||||
}
|
||||
|
||||
function onError(e) {
|
||||
// Some servers don't support the status command. If they are able to
|
||||
// response with an error, then can consider the server ready.
|
||||
if (e instanceof error.UnsupportedOperationError) {
|
||||
resolve({});
|
||||
return;
|
||||
}
|
||||
|
||||
if (Date.now() - start > timeout) {
|
||||
reject(Error('Timed out waiting for the WebDriver server at ' + url));
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
if (!done) {
|
||||
checkServerStatus();
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Polls a URL with GET requests until it returns a 2xx response or the
|
||||
* timeout expires.
|
||||
* @param {string} url The URL to poll.
|
||||
* @param {number} timeout How long to wait, in milliseconds.
|
||||
* @param {Promise=} opt_cancelToken A promise used as a cancellation signal:
|
||||
* if resolved before the a 2xx response is received, the wait will be
|
||||
* terminated early with a {@link promise.CancellationError}.
|
||||
* @return {!Promise} A promise that will resolve when a 2xx is received from
|
||||
* the given URL, or if the wait is cancelled.
|
||||
*/
|
||||
exports.waitForUrl = function(url, timeout, opt_cancelToken) {
|
||||
return new Promise((onResolve, onReject) => {
|
||||
let client = new HttpClient(url);
|
||||
let request = new HttpRequest('GET', '');
|
||||
let start = Date.now();
|
||||
|
||||
let done = false;
|
||||
let resolve = () => {
|
||||
done = true;
|
||||
onResolve();
|
||||
};
|
||||
let reject = (err) => {
|
||||
done = true;
|
||||
onReject(err);
|
||||
};
|
||||
|
||||
if (opt_cancelToken) {
|
||||
opt_cancelToken.then(_ => reject(new promise.CancellationError));
|
||||
}
|
||||
|
||||
testUrl();
|
||||
|
||||
function testUrl() {
|
||||
client.send(request).then(onResponse, onError);
|
||||
}
|
||||
|
||||
function onError() {
|
||||
if (Date.now() - start > timeout) {
|
||||
reject(Error('Timed out waiting for the URL to return 2xx: ' + url));
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
if (!done) {
|
||||
testUrl();
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
function onResponse(response) {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
if (response.status > 199 && response.status < 300) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
onError();
|
||||
}
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue