webdriver 7.16.13 → 7.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,198 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RequestLibError = void 0;
7
- const events_1 = require("events");
8
- const path_1 = __importDefault(require("path"));
9
- const factory_1 = require("./factory");
10
- const logger_1 = __importDefault(require("@wdio/logger"));
11
- const utils_1 = require("@wdio/utils");
12
- const utils_2 = require("../utils");
13
- const pkg = require('../../package.json');
14
- class RequestLibError extends Error {
15
- }
16
- exports.RequestLibError = RequestLibError;
17
- const DEFAULT_HEADERS = {
18
- 'Content-Type': 'application/json; charset=utf-8',
19
- 'Connection': 'keep-alive',
20
- 'Accept': 'application/json',
21
- 'User-Agent': 'webdriver/' + pkg.version
22
- };
23
- const log = (0, logger_1.default)('webdriver');
24
- class WebDriverRequest extends events_1.EventEmitter {
25
- constructor(method, endpoint, body, isHubCommand = false) {
26
- super();
27
- this.defaultOptions = {
28
- retry: 0,
29
- followRedirect: true,
30
- responseType: 'json',
31
- throwHttpErrors: false
32
- };
33
- this.body = body;
34
- this.method = method;
35
- this.endpoint = endpoint;
36
- this.isHubCommand = isHubCommand;
37
- this.defaultAgents = null;
38
- this.requiresSessionId = Boolean(this.endpoint.match(/:sessionId/));
39
- }
40
- makeRequest(options, sessionId) {
41
- let fullRequestOptions = Object.assign({
42
- method: this.method
43
- }, this.defaultOptions, this._createOptions(options, sessionId));
44
- if (typeof options.transformRequest === 'function') {
45
- fullRequestOptions = options.transformRequest(fullRequestOptions);
46
- }
47
- this.emit('request', fullRequestOptions);
48
- return this._request(fullRequestOptions, options.transformResponse, options.connectionRetryCount, 0);
49
- }
50
- _createOptions(options, sessionId, isBrowser = false) {
51
- const agent = isBrowser ? undefined : (options.agent || this.defaultAgents);
52
- const searchParams = isBrowser ?
53
- undefined :
54
- (typeof options.queryParams === 'object' ? options.queryParams : {});
55
- const requestOptions = {
56
- https: {},
57
- agent,
58
- headers: {
59
- ...DEFAULT_HEADERS,
60
- ...(typeof options.headers === 'object' ? options.headers : {})
61
- },
62
- searchParams,
63
- timeout: options.connectionRetryTimeout
64
- };
65
- /**
66
- * only apply body property if existing
67
- */
68
- if (this.body && (Object.keys(this.body).length || this.method === 'POST')) {
69
- const contentLength = Buffer.byteLength(JSON.stringify(this.body), 'utf8');
70
- requestOptions.json = this.body;
71
- requestOptions.headers['Content-Length'] = `${contentLength}`;
72
- }
73
- /**
74
- * if we don't have a session id we set it here, unless we call commands that don't require session ids, for
75
- * example /sessions. The call to /sessions is not connected to a session itself and it therefore doesn't
76
- * require it
77
- */
78
- let endpoint = this.endpoint;
79
- if (this.requiresSessionId) {
80
- if (!sessionId) {
81
- throw new Error('A sessionId is required for this command');
82
- }
83
- endpoint = endpoint.replace(':sessionId', sessionId);
84
- }
85
- requestOptions.url = factory_1.URLFactory.getInstance(`${options.protocol}://` +
86
- `${options.hostname}:${options.port}` +
87
- (this.isHubCommand ? this.endpoint : path_1.default.join(options.path || '', endpoint)));
88
- /**
89
- * send authentication credentials only when creating new session
90
- */
91
- if (this.endpoint === '/session' && options.user && options.key) {
92
- requestOptions.username = options.user;
93
- requestOptions.password = options.key;
94
- }
95
- /**
96
- * if the environment variable "STRICT_SSL" is defined as "false", it doesn't require SSL certificates to be valid.
97
- * Or the requestOptions has strictSSL for an environment which cannot get the environment variable correctly like on an Electron app.
98
- */
99
- requestOptions.https.rejectUnauthorized = !(options.strictSSL === false ||
100
- process.env.STRICT_SSL === 'false' ||
101
- process.env.strict_ssl === 'false');
102
- return requestOptions;
103
- }
104
- async _libRequest(url, options) {
105
- throw new Error('This function must be implemented');
106
- }
107
- async _request(fullRequestOptions, transformResponse, totalRetryCount = 0, retryCount = 0) {
108
- log.info(`[${fullRequestOptions.method}] ${fullRequestOptions.url.href}`);
109
- if (fullRequestOptions.json && Object.keys(fullRequestOptions.json).length) {
110
- log.info('DATA', (0, utils_1.transformCommandLogResult)(fullRequestOptions.json));
111
- }
112
- const { url, ...requestLibOptions } = fullRequestOptions;
113
- let response = await this._libRequest(url, requestLibOptions)
114
- // @ts-ignore
115
- .catch((err) => {
116
- return err;
117
- });
118
- /**
119
- * handle retries for requests
120
- * @param {Error} error error object that causes the retry
121
- * @param {String} msg message that is being shown as warning to user
122
- */
123
- const retry = (error, msg) => {
124
- /**
125
- * stop retrying if totalRetryCount was exceeded or there is no reason to
126
- * retry, e.g. if sessionId is invalid
127
- */
128
- if (retryCount >= totalRetryCount || error.message.includes('invalid session id')) {
129
- log.error(`Request failed with status ${response.statusCode} due to ${error}`);
130
- this.emit('response', { error });
131
- throw error;
132
- }
133
- ++retryCount;
134
- this.emit('retry', { error, retryCount });
135
- log.warn(msg);
136
- log.info(`Retrying ${retryCount}/${totalRetryCount}`);
137
- return this._request(fullRequestOptions, transformResponse, totalRetryCount, retryCount);
138
- };
139
- /**
140
- * handle request errors
141
- */
142
- if (response instanceof Error) {
143
- /**
144
- * handle timeouts
145
- */
146
- if (response.code === 'ETIMEDOUT') {
147
- const error = (0, utils_2.getTimeoutError)(response, fullRequestOptions);
148
- return retry(error, 'Request timed out! Consider increasing the "connectionRetryTimeout" option.');
149
- }
150
- /**
151
- * throw if request error is unknown
152
- */
153
- throw response;
154
- }
155
- if (typeof transformResponse === 'function') {
156
- response = transformResponse(response, fullRequestOptions);
157
- }
158
- const error = (0, utils_2.getErrorFromResponseBody)(response.body);
159
- /**
160
- * retry connection refused errors
161
- */
162
- if (error.message === 'java.net.ConnectException: Connection refused: connect') {
163
- return retry(error, 'Connection to Selenium Standalone server was refused.');
164
- }
165
- /**
166
- * hub commands don't follow standard response formats
167
- * and can have empty bodies
168
- */
169
- if (this.isHubCommand) {
170
- /**
171
- * if body contains HTML the command was called on a node
172
- * directly without using a hub, therefore throw
173
- */
174
- if (typeof response.body === 'string' && response.body.startsWith('<!DOCTYPE html>')) {
175
- return Promise.reject(new Error('Command can only be called to a Selenium Hub'));
176
- }
177
- return { value: response.body || null };
178
- }
179
- /**
180
- * Resolve only if successful response
181
- */
182
- if ((0, utils_2.isSuccessfulResponse)(response.statusCode, response.body)) {
183
- this.emit('response', { result: response.body });
184
- return response.body;
185
- }
186
- /**
187
- * stop retrying as this will never be successful.
188
- * we will handle this at the elementErrorHandler
189
- */
190
- if (error.name === 'stale element reference') {
191
- log.warn('Request encountered a stale element - terminating request');
192
- this.emit('response', { error });
193
- throw error;
194
- }
195
- return retry(error, `Request failed with status ${response.statusCode} due to ${error.message}`);
196
- }
197
- }
198
- exports.default = WebDriverRequest;
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- import type { URL } from 'url';
3
- import { Options } from '@wdio/types';
4
- import WebDriverRequest from './index';
5
- export default class NodeJSRequest extends WebDriverRequest {
6
- constructor(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean);
7
- protected _libRequest(url: URL, opts: Options.RequestLibOptions): Promise<Options.RequestLibResponse>;
8
- }
9
- //# sourceMappingURL=node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/request/node.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,gBAAqC,MAAM,SAAS,CAAA;AAO3D,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,gBAAgB;gBAC1C,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAE,OAAe;cAK5F,WAAW,CAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,iBAAiB;CAUzE"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const http_1 = __importDefault(require("http"));
26
- const https_1 = __importDefault(require("https"));
27
- const got = __importStar(require("got"));
28
- const index_1 = __importStar(require("./index"));
29
- const agents = {
30
- http: new http_1.default.Agent({ keepAlive: true }),
31
- https: new https_1.default.Agent({ keepAlive: true })
32
- };
33
- class NodeJSRequest extends index_1.default {
34
- constructor(method, endpoint, body, isHubCommand = false) {
35
- super(method, endpoint, body, isHubCommand);
36
- this.defaultAgents = agents;
37
- }
38
- async _libRequest(url, opts) {
39
- try {
40
- return (await got.default(url, opts));
41
- }
42
- catch (err) {
43
- if (!(err instanceof Error)) {
44
- throw new index_1.RequestLibError(err.message || err);
45
- }
46
- throw err;
47
- }
48
- }
49
- }
50
- exports.default = NodeJSRequest;
package/build/types.d.ts DELETED
@@ -1,36 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import type { Options, Capabilities } from '@wdio/types';
4
- import type { ProtocolCommands, ProtocolCommandsAsync } from '@wdio/protocols';
5
- export interface JSONWPCommandError extends Error {
6
- code?: string;
7
- statusCode?: string;
8
- statusMessage?: string;
9
- }
10
- export interface SessionFlags {
11
- isW3C: boolean;
12
- isChrome: boolean;
13
- isFirefox: boolean;
14
- isAndroid: boolean;
15
- isMobile: boolean;
16
- isIOS: boolean;
17
- isSauce: boolean;
18
- isSeleniumStandalone: boolean;
19
- isDevTools: boolean;
20
- }
21
- export interface BaseClient extends EventEmitter, SessionFlags {
22
- sessionId: string;
23
- capabilities: Capabilities.DesiredCapabilities | Capabilities.W3CCapabilities;
24
- requestedCapabilities: Capabilities.DesiredCapabilities | Capabilities.W3CCapabilities;
25
- options: Options.WebDriver;
26
- }
27
- export interface Client extends BaseClient, ProtocolCommandsAsync {
28
- }
29
- export interface ClientSync extends BaseClient, ProtocolCommands {
30
- }
31
- export interface AttachOptions extends Partial<SessionFlags>, Partial<Options.WebDriver> {
32
- sessionId: string;
33
- capabilities?: Capabilities.DesiredCapabilities | Capabilities.W3CCapabilities;
34
- isW3C?: boolean;
35
- }
36
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAE9E,MAAM,WAAW,kBAAmB,SAAQ,KAAK;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,oBAAoB,EAAE,OAAO,CAAA;IAC7B,UAAU,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,YAAY;IAE1D,SAAS,EAAE,MAAM,CAAA;IAEjB,YAAY,EAAE,YAAY,CAAC,mBAAmB,GAAG,YAAY,CAAC,eAAe,CAAA;IAE7E,qBAAqB,EAAE,YAAY,CAAC,mBAAmB,GAAG,YAAY,CAAC,eAAe,CAAA;IAEtF,OAAO,EAAE,OAAO,CAAC,SAAS,CAAA;CAC7B;AAED,MAAM,WAAW,MAAO,SAAQ,UAAU,EAAE,qBAAqB;CAAG;AACpE,MAAM,WAAW,UAAW,SAAQ,UAAU,EAAE,gBAAgB;CAAG;AAEnE,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;IACpF,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,YAAY,CAAC,mBAAmB,GAAG,YAAY,CAAC,eAAe,CAAA;IAC9E,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB"}
package/build/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/build/utils.d.ts DELETED
@@ -1,72 +0,0 @@
1
- import { Options, Capabilities } from '@wdio/types';
2
- import { WebDriverResponse } from './request';
3
- import type { JSONWPCommandError, SessionFlags } from './types';
4
- /**
5
- * start browser session with WebDriver protocol
6
- */
7
- export declare function startWebDriverSession(params: Options.WebDriver): Promise<{
8
- sessionId: string;
9
- capabilities: Capabilities.DesiredCapabilities;
10
- }>;
11
- /**
12
- * check if WebDriver requests was successful
13
- * @param {Number} statusCode status code of request
14
- * @param {Object} body body payload of response
15
- * @return {Boolean} true if request was successful
16
- */
17
- export declare function isSuccessfulResponse(statusCode?: number, body?: WebDriverResponse): boolean;
18
- /**
19
- * creates the base prototype for the webdriver monad
20
- */
21
- export declare function getPrototype({ isW3C, isChrome, isFirefox, isMobile, isSauce, isSeleniumStandalone }: Partial<SessionFlags>): Record<string, PropertyDescriptor>;
22
- /**
23
- * helper method to determine the error from webdriver response
24
- * @param {Object} body body object
25
- * @return {Object} error
26
- */
27
- export declare function getErrorFromResponseBody(body: any): Error;
28
- export declare class CustomRequestError extends Error {
29
- constructor(body: WebDriverResponse);
30
- }
31
- /**
32
- * return all supported flags and return them in a format so we can attach them
33
- * to the instance protocol
34
- * @param {Object} options driver instance or option object containing these flags
35
- * @return {Object} prototype object
36
- */
37
- export declare function getEnvironmentVars({ isW3C, isMobile, isIOS, isAndroid, isChrome, isFirefox, isSauce, isSeleniumStandalone }: Partial<SessionFlags>): {
38
- isW3C: {
39
- value: boolean | undefined;
40
- };
41
- isMobile: {
42
- value: boolean | undefined;
43
- };
44
- isIOS: {
45
- value: boolean | undefined;
46
- };
47
- isAndroid: {
48
- value: boolean | undefined;
49
- };
50
- isFirefox: {
51
- value: boolean | undefined;
52
- };
53
- isChrome: {
54
- value: boolean | undefined;
55
- };
56
- isSauce: {
57
- value: boolean | undefined;
58
- };
59
- isSeleniumStandalone: {
60
- value: boolean | undefined;
61
- };
62
- };
63
- /**
64
- * get human readable message from response error
65
- * @param {Error} err response error
66
- */
67
- export declare const getSessionError: (err: JSONWPCommandError, params?: Partial<Options.WebDriver>) => string;
68
- /**
69
- * return timeout error with information about the executing command on which the test hangs
70
- */
71
- export declare const getTimeoutError: (error: Error, requestOptions: Options.RequestLibOptions) => Error;
72
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAI7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAW/D;;GAEG;AACH,wBAAsB,qBAAqB,CAAE,MAAM,EAAE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,YAAY,CAAC,mBAAmB,CAAA;CAAE,CAAC,CAmEtJ;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAE,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,WA4DlF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,YAAY,CAAC,sCAyC3H;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAE,IAAI,EAAE,GAAG,SAclD;AAGD,qBAAa,kBAAmB,SAAQ,KAAK;gBAC7B,IAAI,EAAE,iBAAiB;CAetC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;EAWlJ;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAS,kBAAkB,WAAU,QAAQ,iBAAiB,CAAC,WAmD1F,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,UAAW,KAAK,kBAAkB,QAAQ,iBAAiB,KAAG,KASzF,CAAA"}