webdriver 7.17.0 → 7.18.1
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.
- package/build/command.d.ts +5 -0
- package/build/command.d.ts.map +1 -0
- package/build/command.js +88 -0
- package/build/constants.d.ts +8 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +150 -0
- package/build/index.d.ts +27 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +110 -0
- package/build/request/browser.d.ts +14 -0
- package/build/request/browser.d.ts.map +1 -0
- package/build/request/browser.js +48 -0
- package/build/request/factory.d.ts +10 -0
- package/build/request/factory.d.ts.map +1 -0
- package/build/request/factory.js +29 -0
- package/build/request/index.d.ts +44 -0
- package/build/request/index.d.ts.map +1 -0
- package/build/request/index.js +198 -0
- package/build/request/node.d.ts +9 -0
- package/build/request/node.d.ts.map +1 -0
- package/build/request/node.js +54 -0
- package/build/types.d.ts +36 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/utils.d.ts +79 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +343 -0
- package/package.json +7 -7
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CommandEndpoint } from '@wdio/protocols';
|
|
2
|
+
import { WebDriverResponse } from './request';
|
|
3
|
+
import { BaseClient } from './types';
|
|
4
|
+
export default function (method: string, endpointUri: string, commandInfo: CommandEndpoint, doubleEncodeVariables?: boolean): (this: BaseClient, ...args: any[]) => Promise<WebDriverResponse>;
|
|
5
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIpC,MAAM,CAAC,OAAO,WACV,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,eAAe,EAC5B,qBAAqB,UAAQ,UAIU,UAAU,WAAW,GAAG,EAAE,KAAG,QAAQ,iBAAiB,CAAC,CA0FjG"}
|
package/build/command.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
7
|
+
const utils_1 = require("@wdio/utils");
|
|
8
|
+
const factory_1 = __importDefault(require("./request/factory"));
|
|
9
|
+
const log = (0, logger_1.default)('webdriver');
|
|
10
|
+
function default_1(method, endpointUri, commandInfo, doubleEncodeVariables = false) {
|
|
11
|
+
const { command, ref, parameters, variables = [], isHubCommand = false } = commandInfo;
|
|
12
|
+
return function protocolCommand(...args) {
|
|
13
|
+
let endpoint = endpointUri; // clone endpointUri in case we change it
|
|
14
|
+
const commandParams = [...variables.map((v) => Object.assign(v, {
|
|
15
|
+
/**
|
|
16
|
+
* url variables are:
|
|
17
|
+
*/
|
|
18
|
+
required: true,
|
|
19
|
+
type: 'string' // have to be always type of string
|
|
20
|
+
})), ...parameters];
|
|
21
|
+
const commandUsage = `${command}(${commandParams.map((p) => p.name).join(', ')})`;
|
|
22
|
+
const moreInfo = `\n\nFor more info see ${ref}\n`;
|
|
23
|
+
const body = {};
|
|
24
|
+
/**
|
|
25
|
+
* parameter check
|
|
26
|
+
*/
|
|
27
|
+
const minAllowedParams = commandParams.filter((param) => param.required).length;
|
|
28
|
+
if (args.length < minAllowedParams || args.length > commandParams.length) {
|
|
29
|
+
const parameterDescription = commandParams.length
|
|
30
|
+
? `\n\nProperty Description:\n${commandParams.map((p) => ` "${p.name}" (${p.type}): ${p.description}`).join('\n')}`
|
|
31
|
+
: '';
|
|
32
|
+
throw new Error(`Wrong parameters applied for ${command}\n` +
|
|
33
|
+
`Usage: ${commandUsage}` +
|
|
34
|
+
parameterDescription +
|
|
35
|
+
moreInfo);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* parameter type check
|
|
39
|
+
*/
|
|
40
|
+
for (const [it, arg] of Object.entries(args)) {
|
|
41
|
+
const i = parseInt(it, 10);
|
|
42
|
+
const commandParam = commandParams[i];
|
|
43
|
+
if (!(0, utils_1.isValidParameter)(arg, commandParam.type)) {
|
|
44
|
+
/**
|
|
45
|
+
* ignore if argument is not required
|
|
46
|
+
*/
|
|
47
|
+
if (typeof arg === 'undefined' && !commandParam.required) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const actual = commandParam.type.endsWith('[]')
|
|
51
|
+
? `(${(Array.isArray(arg) ? arg : [arg]).map((a) => (0, utils_1.getArgumentType)(a))})[]`
|
|
52
|
+
: (0, utils_1.getArgumentType)(arg);
|
|
53
|
+
throw new Error(`Malformed type for "${commandParam.name}" parameter of command ${command}\n` +
|
|
54
|
+
`Expected: ${commandParam.type}\n` +
|
|
55
|
+
`Actual: ${actual}` +
|
|
56
|
+
moreInfo);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* inject url variables
|
|
60
|
+
*/
|
|
61
|
+
if (i < variables.length) {
|
|
62
|
+
const encodedArg = doubleEncodeVariables ? encodeURIComponent(encodeURIComponent(arg)) : encodeURIComponent(arg);
|
|
63
|
+
endpoint = endpoint.replace(`:${commandParams[i].name}`, encodedArg);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* rest of args are part of body payload
|
|
68
|
+
*/
|
|
69
|
+
body[commandParams[i].name] = arg;
|
|
70
|
+
}
|
|
71
|
+
const request = factory_1.default.getInstance(method, endpoint, body, isHubCommand);
|
|
72
|
+
this.emit('command', { method, endpoint, body });
|
|
73
|
+
log.info('COMMAND', (0, utils_1.commandCallStructure)(command, args));
|
|
74
|
+
return request.makeRequest(this.options, this.sessionId).then((result) => {
|
|
75
|
+
if (result.value != null) {
|
|
76
|
+
log.info('RESULT', /screenshot|recording/i.test(command)
|
|
77
|
+
&& typeof result.value === 'string' && result.value.length > 64
|
|
78
|
+
? `${result.value.substr(0, 61)}...` : result.value);
|
|
79
|
+
}
|
|
80
|
+
this.emit('result', { method, endpoint, body, result });
|
|
81
|
+
if (command === 'deleteSession') {
|
|
82
|
+
logger_1.default.clearLogger();
|
|
83
|
+
}
|
|
84
|
+
return result.value;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Options } from '@wdio/types';
|
|
2
|
+
export declare const DEFAULTS: Options.Definition<Required<Options.WebDriver>>;
|
|
3
|
+
export declare const VALID_CAPS: string[];
|
|
4
|
+
export declare const REG_EXPS: {
|
|
5
|
+
commandName: RegExp;
|
|
6
|
+
execFn: RegExp;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CA0IpE,CAAA;AAED,eAAO,MAAM,UAAU,UAItB,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAGpB,CAAA"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REG_EXPS = exports.VALID_CAPS = exports.DEFAULTS = void 0;
|
|
4
|
+
exports.DEFAULTS = {
|
|
5
|
+
/**
|
|
6
|
+
* protocol of automation driver
|
|
7
|
+
*/
|
|
8
|
+
protocol: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
default: 'http',
|
|
11
|
+
match: /(http|https)/
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* hostname of automation driver
|
|
15
|
+
*/
|
|
16
|
+
hostname: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
default: 'localhost'
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* port of automation driver
|
|
22
|
+
*/
|
|
23
|
+
port: {
|
|
24
|
+
type: 'number',
|
|
25
|
+
default: 4444
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* path to WebDriver endpoints
|
|
29
|
+
*/
|
|
30
|
+
path: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
validate: (path) => {
|
|
33
|
+
if (!path.startsWith('/')) {
|
|
34
|
+
throw new TypeError('The option "path" needs to start with a "/"');
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
},
|
|
38
|
+
default: '/'
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* A key-value store of query parameters to be added to every selenium request
|
|
42
|
+
*/
|
|
43
|
+
queryParams: {
|
|
44
|
+
type: 'object'
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* cloud user if applicable
|
|
48
|
+
*/
|
|
49
|
+
user: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* access key to user
|
|
54
|
+
*/
|
|
55
|
+
key: {
|
|
56
|
+
type: 'string'
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* capability of WebDriver session
|
|
60
|
+
*/
|
|
61
|
+
capabilities: {
|
|
62
|
+
type: 'object',
|
|
63
|
+
required: true
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Level of logging verbosity
|
|
67
|
+
*/
|
|
68
|
+
logLevel: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
default: 'info',
|
|
71
|
+
match: /(trace|debug|info|warn|error|silent)/
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* directory for log files
|
|
75
|
+
*/
|
|
76
|
+
outputDir: {
|
|
77
|
+
type: 'string'
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Timeout for any WebDriver request to a driver or grid
|
|
81
|
+
*/
|
|
82
|
+
connectionRetryTimeout: {
|
|
83
|
+
type: 'number',
|
|
84
|
+
default: 120000
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Count of request retries to the Selenium server
|
|
88
|
+
*/
|
|
89
|
+
connectionRetryCount: {
|
|
90
|
+
type: 'number',
|
|
91
|
+
default: 3
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Override default agent
|
|
95
|
+
*/
|
|
96
|
+
agent: {
|
|
97
|
+
type: 'object'
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Override default agent
|
|
101
|
+
*/
|
|
102
|
+
logLevels: {
|
|
103
|
+
type: 'object'
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Pass custom headers
|
|
107
|
+
*/
|
|
108
|
+
headers: {
|
|
109
|
+
type: 'object'
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Function transforming the request options before the request is made
|
|
113
|
+
*/
|
|
114
|
+
transformRequest: {
|
|
115
|
+
type: 'function',
|
|
116
|
+
default: (requestOptions) => requestOptions
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Function transforming the response object after it is received
|
|
120
|
+
*/
|
|
121
|
+
transformResponse: {
|
|
122
|
+
type: 'function',
|
|
123
|
+
default: (response) => response
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* Appium direct connect options server (https://appiumpro.com/editions/86-connecting-directly-to-appium-hosts-in-distributed-environments)
|
|
127
|
+
* Whether to allow direct connect caps to adjust endpoint details (Appium only)
|
|
128
|
+
*/
|
|
129
|
+
enableDirectConnect: {
|
|
130
|
+
type: 'boolean',
|
|
131
|
+
default: true
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* Whether it requires SSL certificates to be valid in HTTP/s requests
|
|
135
|
+
* for an environment which cannot get process environment well.
|
|
136
|
+
*/
|
|
137
|
+
strictSSL: {
|
|
138
|
+
type: 'boolean',
|
|
139
|
+
default: true
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
exports.VALID_CAPS = [
|
|
143
|
+
'browserName', 'browserVersion', 'platformName', 'acceptInsecureCerts',
|
|
144
|
+
'pageLoadStrategy', 'proxy', 'setWindowRect', 'timeouts', 'strictFileInteractability',
|
|
145
|
+
'unhandledPromptBehavior'
|
|
146
|
+
];
|
|
147
|
+
exports.REG_EXPS = {
|
|
148
|
+
commandName: /.*\/session\/[0-9a-f-]+\/(.*)/,
|
|
149
|
+
execFn: /return \(([\s\S]*)\)\.apply\(null, arguments\)/
|
|
150
|
+
};
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Options } from '@wdio/types';
|
|
2
|
+
import command from './command';
|
|
3
|
+
import { DEFAULTS } from './constants';
|
|
4
|
+
import { getPrototype } from './utils';
|
|
5
|
+
import type { Client, AttachOptions } from './types';
|
|
6
|
+
export default class WebDriver {
|
|
7
|
+
static newSession(options: Options.WebDriver, modifier?: (...args: any[]) => any, userPrototype?: {}, customCommandWrapper?: (...args: any[]) => any): Promise<Client>;
|
|
8
|
+
/**
|
|
9
|
+
* allows user to attach to existing sessions
|
|
10
|
+
*/
|
|
11
|
+
static attachToSession(options?: AttachOptions, modifier?: (...args: any[]) => any, userPrototype?: {}, commandWrapper?: (...args: any[]) => any): Client;
|
|
12
|
+
/**
|
|
13
|
+
* Changes The instance session id and browser capabilities for the new session
|
|
14
|
+
* directly into the passed in browser object
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} instance the object we get from a new browser session.
|
|
17
|
+
* @returns {string} the new session id of the browser
|
|
18
|
+
*/
|
|
19
|
+
static reloadSession(instance: Client): Promise<string>;
|
|
20
|
+
static get WebDriver(): typeof WebDriver;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Helper methods consumed by webdriverio package
|
|
24
|
+
*/
|
|
25
|
+
export { getPrototype, DEFAULTS, command };
|
|
26
|
+
export * from './types';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAA;AAExD,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAyB,YAAY,EAA0C,MAAM,SAAS,CAAA;AACrG,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAgB,MAAM,SAAS,CAAA;AAIlE,MAAM,CAAC,OAAO,OAAO,SAAS;WACb,UAAU,CACnB,OAAO,EAAE,OAAO,CAAC,SAAS,EAC1B,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,aAAa,KAAK,EAClB,oBAAoB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAC/C,OAAO,CAAC,MAAM,CAAC;IA4ClB;;OAEG;IACH,MAAM,CAAC,eAAe,CAClB,OAAO,CAAC,EAAE,aAAa,EACvB,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,aAAa,KAAK,EAClB,cAAc,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GACzC,MAAM;IAwBT;;;;;;MAME;WACW,aAAa,CAAE,QAAQ,EAAE,MAAM;IAW5C,MAAM,KAAK,SAAS,qBAEnB;CACJ;AAED;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;AAC1C,cAAc,SAAS,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.command = exports.DEFAULTS = exports.getPrototype = void 0;
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
23
|
+
const utils_1 = require("@wdio/utils");
|
|
24
|
+
const config_1 = require("@wdio/config");
|
|
25
|
+
const command_1 = __importDefault(require("./command"));
|
|
26
|
+
exports.command = command_1.default;
|
|
27
|
+
const constants_1 = require("./constants");
|
|
28
|
+
Object.defineProperty(exports, "DEFAULTS", { enumerable: true, get: function () { return constants_1.DEFAULTS; } });
|
|
29
|
+
const utils_2 = require("./utils");
|
|
30
|
+
Object.defineProperty(exports, "getPrototype", { enumerable: true, get: function () { return utils_2.getPrototype; } });
|
|
31
|
+
const log = (0, logger_1.default)('webdriver');
|
|
32
|
+
class WebDriver {
|
|
33
|
+
static async newSession(options, modifier, userPrototype = {}, customCommandWrapper) {
|
|
34
|
+
const params = (0, config_1.validateConfig)(constants_1.DEFAULTS, options);
|
|
35
|
+
if (!options.logLevels || !options.logLevels.webdriver) {
|
|
36
|
+
logger_1.default.setLevel('webdriver', params.logLevel);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Store all log events in a file
|
|
40
|
+
*/
|
|
41
|
+
if (params.outputDir && !process.env.WDIO_LOG_PATH) {
|
|
42
|
+
process.env.WDIO_LOG_PATH = path_1.default.join(params.outputDir, 'wdio.log');
|
|
43
|
+
}
|
|
44
|
+
log.info('Initiate new session using the WebDriver protocol');
|
|
45
|
+
const requestedCapabilities = { ...params.capabilities };
|
|
46
|
+
const { sessionId, capabilities } = await (0, utils_2.startWebDriverSession)(params);
|
|
47
|
+
const environment = (0, utils_1.sessionEnvironmentDetector)({ capabilities, requestedCapabilities });
|
|
48
|
+
const environmentPrototype = (0, utils_2.getEnvironmentVars)(environment);
|
|
49
|
+
const protocolCommands = (0, utils_2.getPrototype)(environment);
|
|
50
|
+
const prototype = { ...protocolCommands, ...environmentPrototype, ...userPrototype };
|
|
51
|
+
const monad = (0, utils_1.webdriverMonad)({ ...params, requestedCapabilities }, modifier, prototype);
|
|
52
|
+
const client = monad(sessionId, customCommandWrapper);
|
|
53
|
+
/**
|
|
54
|
+
* if the server responded with direct connect information, update the
|
|
55
|
+
* client options to speak directly to the appium host instead of a load
|
|
56
|
+
* balancer (see https://github.com/appium/python-client#direct-connect-urls
|
|
57
|
+
* for example). But only do this if the user has enabled this
|
|
58
|
+
* behavior in the first place.
|
|
59
|
+
*/
|
|
60
|
+
if (params.enableDirectConnect) {
|
|
61
|
+
(0, utils_2.setupDirectConnect)(client);
|
|
62
|
+
}
|
|
63
|
+
return client;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* allows user to attach to existing sessions
|
|
67
|
+
*/
|
|
68
|
+
static attachToSession(options, modifier, userPrototype = {}, commandWrapper) {
|
|
69
|
+
if (!options || typeof options.sessionId !== 'string') {
|
|
70
|
+
throw new Error('sessionId is required to attach to existing session');
|
|
71
|
+
}
|
|
72
|
+
// logLevel can be undefined in watch mode when SIGINT is called
|
|
73
|
+
if (options.logLevel) {
|
|
74
|
+
logger_1.default.setLevel('webdriver', options.logLevel);
|
|
75
|
+
}
|
|
76
|
+
options.capabilities = options.capabilities || {};
|
|
77
|
+
options.isW3C = options.isW3C === false ? false : true;
|
|
78
|
+
options.protocol = options.protocol || constants_1.DEFAULTS.protocol.default;
|
|
79
|
+
options.hostname = options.hostname || constants_1.DEFAULTS.hostname.default;
|
|
80
|
+
options.port = options.port || constants_1.DEFAULTS.port.default;
|
|
81
|
+
options.path = options.path || constants_1.DEFAULTS.path.default;
|
|
82
|
+
const environmentPrototype = (0, utils_2.getEnvironmentVars)(options);
|
|
83
|
+
const protocolCommands = (0, utils_2.getPrototype)(options);
|
|
84
|
+
const prototype = { ...protocolCommands, ...environmentPrototype, ...userPrototype };
|
|
85
|
+
const monad = (0, utils_1.webdriverMonad)(options, modifier, prototype);
|
|
86
|
+
return monad(options.sessionId, commandWrapper);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Changes The instance session id and browser capabilities for the new session
|
|
90
|
+
* directly into the passed in browser object
|
|
91
|
+
*
|
|
92
|
+
* @param {Object} instance the object we get from a new browser session.
|
|
93
|
+
* @returns {string} the new session id of the browser
|
|
94
|
+
*/
|
|
95
|
+
static async reloadSession(instance) {
|
|
96
|
+
const params = {
|
|
97
|
+
...instance.options,
|
|
98
|
+
capabilities: instance.requestedCapabilities
|
|
99
|
+
};
|
|
100
|
+
const { sessionId, capabilities } = await (0, utils_2.startWebDriverSession)(params);
|
|
101
|
+
instance.sessionId = sessionId;
|
|
102
|
+
instance.capabilities = capabilities;
|
|
103
|
+
return sessionId;
|
|
104
|
+
}
|
|
105
|
+
static get WebDriver() {
|
|
106
|
+
return WebDriver;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.default = WebDriver;
|
|
110
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Options } from '@wdio/types';
|
|
2
|
+
import WebDriverRequest from './index';
|
|
3
|
+
declare type RequestLibOptions = Options.RequestLibOptions;
|
|
4
|
+
declare type RequestOptions = Omit<Options.WebDriver, 'capabilities'>;
|
|
5
|
+
export default class BrowserRequest extends WebDriverRequest {
|
|
6
|
+
constructor(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean);
|
|
7
|
+
protected _createOptions(options: RequestOptions, sessionId?: string): RequestLibOptions;
|
|
8
|
+
protected _libRequest(url: URL, options: RequestLibOptions): Promise<{
|
|
9
|
+
statusCode: number;
|
|
10
|
+
body: any;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/request/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,gBAAgB,MAAM,SAAS,CAAA;AAGtC,aAAK,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAA;AAClD,aAAK,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AAU7D,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,gBAAgB;gBAE3C,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAE,OAAe;IAI5G,SAAS,CAAC,cAAc,CAAE,OAAO,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB;cAIzE,WAAW,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB;;;;CA8BpE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
7
|
+
const index_1 = __importDefault(require("./index"));
|
|
8
|
+
const ky_1 = __importDefault(require("ky"));
|
|
9
|
+
const log = (0, logger_1.default)('webdriver');
|
|
10
|
+
const UNSUPPORTED_OPTS = [
|
|
11
|
+
'agent',
|
|
12
|
+
'responseType',
|
|
13
|
+
'searchParams',
|
|
14
|
+
];
|
|
15
|
+
class BrowserRequest extends index_1.default {
|
|
16
|
+
constructor(method, endpoint, body, isHubCommand = false) {
|
|
17
|
+
super(method, endpoint, body, isHubCommand);
|
|
18
|
+
}
|
|
19
|
+
_createOptions(options, sessionId) {
|
|
20
|
+
return super._createOptions(options, sessionId, true);
|
|
21
|
+
}
|
|
22
|
+
async _libRequest(url, options) {
|
|
23
|
+
const kyOptions = {};
|
|
24
|
+
for (const opt of Object.keys(options)) {
|
|
25
|
+
if (typeof options[opt] !== 'undefined' &&
|
|
26
|
+
UNSUPPORTED_OPTS.includes(opt) &&
|
|
27
|
+
options[opt] !== this.defaultOptions[opt]) {
|
|
28
|
+
log.info(`Browser-based webdriver does not support the '${String(opt)}' option; behavior may be unexpected`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
kyOptions[opt] = options[opt];
|
|
33
|
+
}
|
|
34
|
+
if (options.username && options.password) {
|
|
35
|
+
const encodedAuth = Buffer.from(`${options.username}:${options.password}`, 'utf8').toString('base64');
|
|
36
|
+
kyOptions.headers = {
|
|
37
|
+
...kyOptions.headers,
|
|
38
|
+
Authorization: `Basic ${encodedAuth}`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const res = await (0, ky_1.default)(url, kyOptions);
|
|
42
|
+
return {
|
|
43
|
+
statusCode: res.status,
|
|
44
|
+
body: await res.json(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = BrowserRequest;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebDriverRequest from './index';
|
|
3
|
+
import type { URL as URLType } from 'url';
|
|
4
|
+
export default class RequestFactory {
|
|
5
|
+
static getInstance(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean): WebDriverRequest;
|
|
6
|
+
}
|
|
7
|
+
export declare class URLFactory {
|
|
8
|
+
static getInstance(uri: string): URLType;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/request/factory.ts"],"names":[],"mappings":";AAAA,OAAO,gBAAgB,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,KAAK,CAAA;AAEzC,MAAM,CAAC,OAAO,OAAO,cAAc;IAC/B,MAAM,CAAC,WAAW,CACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,YAAY,GAAE,OAAe,GAC9B,gBAAgB;CAYtB;AAED,qBAAa,UAAU;IACnB,MAAM,CAAC,WAAW,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO;CAO5C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.URLFactory = void 0;
|
|
4
|
+
class RequestFactory {
|
|
5
|
+
static getInstance(method, endpoint, body, isHubCommand = false) {
|
|
6
|
+
var _a;
|
|
7
|
+
if ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) {
|
|
8
|
+
const reqModule = require('./node');
|
|
9
|
+
// we either need to get the default export explicitly in the prod case, or implicitly
|
|
10
|
+
// in the case of jest mocking
|
|
11
|
+
const NodeJSRequest = reqModule.default || reqModule;
|
|
12
|
+
return new NodeJSRequest(method, endpoint, body, isHubCommand);
|
|
13
|
+
}
|
|
14
|
+
const BrowserRequest = require('./browser').default;
|
|
15
|
+
return new BrowserRequest(method, endpoint, body, isHubCommand);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = RequestFactory;
|
|
19
|
+
class URLFactory {
|
|
20
|
+
static getInstance(uri) {
|
|
21
|
+
var _a;
|
|
22
|
+
if ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) {
|
|
23
|
+
const { URL } = require('url');
|
|
24
|
+
return new URL(uri);
|
|
25
|
+
}
|
|
26
|
+
return new window.URL(uri);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.URLFactory = URLFactory;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import type { URL } from 'url';
|
|
4
|
+
import type { Options } from '@wdio/types';
|
|
5
|
+
declare type Agents = Options.Agents;
|
|
6
|
+
declare type RequestLibOptions = Options.RequestLibOptions;
|
|
7
|
+
declare type RequestLibResponse = Options.RequestLibResponse;
|
|
8
|
+
declare type RequestOptions = Omit<Options.WebDriver, 'capabilities'>;
|
|
9
|
+
export declare class RequestLibError extends Error {
|
|
10
|
+
statusCode?: number;
|
|
11
|
+
body?: any;
|
|
12
|
+
code?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface WebDriverResponse {
|
|
15
|
+
value: any;
|
|
16
|
+
/**
|
|
17
|
+
* error case
|
|
18
|
+
* https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-an-error
|
|
19
|
+
*/
|
|
20
|
+
error?: string;
|
|
21
|
+
message?: string;
|
|
22
|
+
stacktrace?: string;
|
|
23
|
+
/**
|
|
24
|
+
* JSONWP property
|
|
25
|
+
*/
|
|
26
|
+
status?: number;
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
}
|
|
29
|
+
export default abstract class WebDriverRequest extends EventEmitter {
|
|
30
|
+
body?: Record<string, unknown>;
|
|
31
|
+
method: string;
|
|
32
|
+
endpoint: string;
|
|
33
|
+
isHubCommand: boolean;
|
|
34
|
+
requiresSessionId: boolean;
|
|
35
|
+
defaultAgents: Agents | null;
|
|
36
|
+
defaultOptions: RequestLibOptions;
|
|
37
|
+
constructor(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean);
|
|
38
|
+
makeRequest(options: RequestOptions, sessionId?: string): Promise<WebDriverResponse>;
|
|
39
|
+
protected _createOptions(options: RequestOptions, sessionId?: string, isBrowser?: boolean): RequestLibOptions;
|
|
40
|
+
protected _libRequest(url: URL, options: RequestLibOptions): Promise<RequestLibResponse>;
|
|
41
|
+
private _request;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAK9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAM1C,aAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;AAC5B,aAAK,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAA;AAClD,aAAK,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAA;AACpD,aAAK,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AAE7D,qBAAa,eAAgB,SAAQ,KAAK;IACtC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,GAAG,CAAA;IACV;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAWD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,gBAAiB,SAAQ,YAAY;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,cAAc,EAAE,iBAAiB,CAKhC;gBAEY,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAE,OAAe;IAU5G,WAAW,CAAE,OAAO,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM;IAYxD,SAAS,CAAC,cAAc,CAAE,OAAO,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe,GAAG,iBAAiB;cAiErG,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;YAIhF,QAAQ;CA8GzB"}
|