@appium/base-driver 8.1.1 → 8.2.2
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/lib/basedriver/capabilities.js +6 -6
- package/build/lib/basedriver/commands/find.js +1 -1
- package/build/lib/basedriver/commands/index.js +2 -4
- package/build/lib/basedriver/commands/log.js +1 -1
- package/build/lib/basedriver/commands/session.js +1 -1
- package/build/lib/basedriver/commands/timeout.js +1 -1
- package/build/lib/basedriver/desired-caps.js +1 -1
- package/build/lib/basedriver/device-settings.js +1 -1
- package/build/lib/basedriver/driver.js +5 -7
- package/build/lib/basedriver/helpers.js +5 -3
- package/build/lib/constants.js +1 -1
- package/build/lib/express/crash.js +1 -1
- package/build/lib/express/middleware.js +3 -3
- package/build/lib/express/server.js +1 -1
- package/build/lib/express/static.js +2 -2
- package/build/lib/express/websocket.js +3 -3
- package/build/lib/index.js +124 -0
- package/build/lib/jsonwp-status/status.js +1 -1
- package/build/lib/protocol/errors.js +6 -5
- package/build/lib/protocol/helpers.js +3 -3
- package/build/lib/protocol/index.js +31 -19
- package/build/lib/protocol/protocol.js +22 -11
- package/build/lib/protocol/routes.js +6 -12
- package/build/test/basedriver/capability-specs.js +10 -10
- package/build/test/basedriver/commands/event-specs.js +10 -10
- package/build/test/basedriver/driver-e2e-specs.js +3 -3
- package/build/test/basedriver/driver-e2e-tests.js +53 -256
- package/build/test/basedriver/driver-specs.js +3 -3
- package/build/test/basedriver/driver-tests.js +6 -6
- package/build/test/basedriver/helpers-e2e-specs.js +10 -4
- package/build/test/basedriver/index.js +4 -4
- package/build/test/basedriver/timeout-specs.js +7 -7
- package/build/test/basedriver/websockets-e2e-specs.js +11 -11
- package/build/test/express/server-e2e-specs.js +156 -0
- package/build/test/express/server-specs.js +151 -0
- package/build/test/express/static-specs.js +23 -0
- package/build/test/helpers.js +57 -0
- package/build/test/jsonwp-proxy/mock-request.js +93 -0
- package/build/test/jsonwp-proxy/protocol-converter-specs.js +173 -0
- package/build/test/jsonwp-proxy/proxy-e2e-specs.js +62 -0
- package/build/test/jsonwp-proxy/proxy-specs.js +299 -0
- package/build/test/jsonwp-proxy/url-specs.js +167 -0
- package/build/test/jsonwp-status/status-specs.js +36 -0
- package/build/test/protocol/errors-specs.js +388 -0
- package/build/test/protocol/fake-driver.js +168 -0
- package/build/test/protocol/helpers.js +27 -0
- package/build/test/protocol/protocol-e2e-specs.js +1242 -0
- package/build/test/protocol/routes-specs.js +82 -0
- package/build/test/protocol/validator-specs.js +151 -0
- package/index.d.ts +309 -44
- package/index.js +1 -62
- package/lib/basedriver/commands/index.js +0 -2
- package/lib/basedriver/driver.js +2 -22
- package/lib/basedriver/helpers.js +5 -4
- package/lib/index.js +62 -0
- package/lib/protocol/index.js +3 -1
- package/lib/protocol/protocol.js +18 -7
- package/lib/protocol/routes.js +1 -4
- package/package.json +8 -16
- package/test/basedriver/capability-specs.js +1 -1
- package/test/basedriver/commands/event-specs.js +1 -1
- package/test/basedriver/driver-e2e-specs.js +1 -1
- package/test/basedriver/driver-e2e-tests.js +66 -213
- package/test/basedriver/driver-specs.js +1 -1
- package/test/basedriver/driver-tests.js +3 -3
- package/test/basedriver/helpers-e2e-specs.js +9 -4
- package/test/basedriver/timeout-specs.js +1 -1
- package/test/basedriver/websockets-e2e-specs.js +7 -7
- package/build/index.js +0 -118
- package/build/lib/basedriver/commands/execute-child.js +0 -137
- package/build/lib/basedriver/commands/execute.js +0 -119
- package/build/test/basedriver/fixtures/custom-element-finder-bad.js +0 -12
- package/build/test/basedriver/fixtures/custom-element-finder.js +0 -36
- package/lib/basedriver/commands/execute-child.js +0 -132
- package/lib/basedriver/commands/execute.js +0 -126
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import cp from 'child_process';
|
|
4
|
-
import log from '../logger';
|
|
5
|
-
import B from 'bluebird';
|
|
6
|
-
|
|
7
|
-
const FEAT_FLAG = 'execute_driver_script';
|
|
8
|
-
const DEFAULT_SCRIPT_TIMEOUT = 1000 * 60 * 60; // default to 1 hour timeout
|
|
9
|
-
const SCRIPT_TYPE_WDIO = 'webdriverio';
|
|
10
|
-
// TODO add wd script type at some point
|
|
11
|
-
|
|
12
|
-
let commands = {};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* This method takes a string which is executed as javascript in the context of
|
|
16
|
-
* a new nodejs VM, and which has available a webdriverio driver object, having
|
|
17
|
-
* already been attached to the currently running session.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} script - the string representing the driver script to run
|
|
20
|
-
* @param {string} [scriptType='webdriverio'] - the name of the driver script
|
|
21
|
-
* library (currently only webdriverio is supported)
|
|
22
|
-
*
|
|
23
|
-
* @returns {Object} - a JSONifiable object representing the return value of
|
|
24
|
-
* the script
|
|
25
|
-
*/
|
|
26
|
-
commands.executeDriverScript = async function (script, scriptType = 'webdriverio',
|
|
27
|
-
timeout = DEFAULT_SCRIPT_TIMEOUT) {
|
|
28
|
-
|
|
29
|
-
if (!this.isFeatureEnabled(FEAT_FLAG)) {
|
|
30
|
-
throw new Error(`Execute driver script functionality is not available ` +
|
|
31
|
-
`unless server is started with --allow-insecure including ` +
|
|
32
|
-
`the '${FEAT_FLAG}' flag, e.g., --allow-insecure=${FEAT_FLAG}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (scriptType !== SCRIPT_TYPE_WDIO) {
|
|
36
|
-
throw new Error(`Only the '${SCRIPT_TYPE_WDIO}' script type is currently supported`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!this.opts.address || !this.opts.port) {
|
|
40
|
-
throw new Error('Address or port of running server were not defined; this ' +
|
|
41
|
-
'is required. This is probably a programming error in the driver');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!_.isNumber(timeout)) {
|
|
45
|
-
throw new Error('Timeout parameter must be a number');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const driverOpts = {
|
|
49
|
-
sessionId: this.sessionId,
|
|
50
|
-
protocol: 'http', // Appium won't ever be behind ssl locally
|
|
51
|
-
hostname: this.opts.address,
|
|
52
|
-
port: this.opts.port,
|
|
53
|
-
path: this.basePath,
|
|
54
|
-
isW3C: this.isW3CProtocol(),
|
|
55
|
-
isMobile: true,
|
|
56
|
-
capabilities: this.caps
|
|
57
|
-
};
|
|
58
|
-
log.info(`Constructed webdriverio driver options; W3C mode is ${driverOpts.isW3C ? 'on' : 'off'}`);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// fork the execution script as a child process
|
|
62
|
-
const childScript = path.join(__dirname, 'execute-child.js');
|
|
63
|
-
log.info(`Forking process to run webdriver script as child using ${childScript}`);
|
|
64
|
-
const scriptProc = cp.fork(childScript);
|
|
65
|
-
|
|
66
|
-
// keep track of whether we have canceled the script timeout, so we can stop
|
|
67
|
-
// waiting for it and allow this process to finish gracefully
|
|
68
|
-
let timeoutCanceled = false;
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const timeoutStart = Date.now();
|
|
72
|
-
|
|
73
|
-
// promise that deals with the result from the child process
|
|
74
|
-
const waitForResult = async function () {
|
|
75
|
-
const resPromise = new B((res) => {
|
|
76
|
-
scriptProc.on('message', res); // this is node IPC
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const res = await resPromise;
|
|
80
|
-
log.info('Received execute driver script result from child process, shutting it down');
|
|
81
|
-
|
|
82
|
-
if (res.error) {
|
|
83
|
-
throw new Error(res.error.message);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return res.success;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// promise that waits up to the timeout and throws an error if so, or does
|
|
90
|
-
// nothing if the timeout is canceled because we got a result from the
|
|
91
|
-
// child script
|
|
92
|
-
const waitForTimeout = async function () {
|
|
93
|
-
while (!timeoutCanceled && (Date.now() - timeoutStart) < timeout) {
|
|
94
|
-
await B.delay(500);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (timeoutCanceled) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
throw new Error(`Execute driver script timed out after ${timeout}ms. ` +
|
|
102
|
-
`You can adjust this with the 'timeout' parameter.`);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// now that the child script is alive, send it the data it needs to start
|
|
106
|
-
// running the driver script
|
|
107
|
-
log.info('Sending driver and script data to child');
|
|
108
|
-
scriptProc.send({driverOpts, script, timeout});
|
|
109
|
-
|
|
110
|
-
// and set up a race between the response from the child and the timeout
|
|
111
|
-
return await B.race([waitForResult(), waitForTimeout()]);
|
|
112
|
-
} catch (err) {
|
|
113
|
-
throw new Error(`Could not execute driver script. Original error was: ${err}`);
|
|
114
|
-
} finally {
|
|
115
|
-
// ensure we always cancel the timeout so that the timeout promise stops
|
|
116
|
-
// spinning and allows this process to die gracefully
|
|
117
|
-
timeoutCanceled = true;
|
|
118
|
-
|
|
119
|
-
log.info('Disconnecting from and killing driver script child proc');
|
|
120
|
-
scriptProc.disconnect();
|
|
121
|
-
scriptProc.kill();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export default commands;
|