@appium/base-driver 8.5.3 → 8.5.4
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.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +1 -1
- package/build/lib/basedriver/commands/event.js +1 -1
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.js +1 -1
- package/build/lib/basedriver/commands/index.js +1 -1
- package/build/lib/basedriver/commands/log.d.ts.map +1 -1
- package/build/lib/basedriver/commands/log.js +1 -1
- package/build/lib/basedriver/commands/session.js +1 -1
- package/build/lib/basedriver/commands/settings.d.ts.map +1 -1
- package/build/lib/basedriver/commands/settings.js +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +1 -1
- package/build/lib/basedriver/core.d.ts +120 -139
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +1 -49
- package/build/lib/basedriver/desired-caps.d.ts +5 -2
- package/build/lib/basedriver/desired-caps.d.ts.map +1 -1
- package/build/lib/basedriver/desired-caps.js +14 -18
- package/build/lib/basedriver/device-settings.d.ts +9 -9
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js +4 -4
- package/build/lib/basedriver/driver.d.ts +43 -38
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +58 -11
- package/build/lib/basedriver/helpers.d.ts +8 -3
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +4 -6
- package/build/lib/basedriver/logger.d.ts +1 -1
- package/build/lib/basedriver/logger.d.ts.map +1 -1
- package/build/lib/basedriver/logger.js +1 -1
- package/build/lib/constants.js +1 -1
- package/build/lib/express/crash.d.ts.map +1 -1
- package/build/lib/express/crash.js +1 -1
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +1 -1
- package/build/lib/express/idempotency.js +1 -1
- package/build/lib/express/logger.d.ts +1 -1
- package/build/lib/express/logger.d.ts.map +1 -1
- package/build/lib/express/logger.js +1 -1
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +1 -1
- package/build/lib/express/server.d.ts +21 -0
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +4 -9
- package/build/lib/express/static.d.ts.map +1 -1
- package/build/lib/express/static.js +2 -2
- package/build/lib/express/websocket.d.ts +14 -11
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js +2 -2
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.js +7 -1
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.js +2 -2
- package/build/lib/jsonwp-proxy/proxy.d.ts +30 -5
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +20 -4
- package/build/lib/jsonwp-status/status.d.ts.map +1 -1
- package/build/lib/jsonwp-status/status.js +2 -2
- package/build/lib/protocol/errors.d.ts +17 -8
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +9 -5
- package/build/lib/protocol/helpers.js +1 -1
- package/build/lib/protocol/index.js +1 -1
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +1 -1
- package/build/lib/protocol/routes.d.ts +17 -3
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +1 -1
- package/build/lib/protocol/validators.js +1 -1
- package/build/test/basedriver/driver-e2e-tests.js +1 -1
- package/build/test/basedriver/driver-tests.js +1 -1
- package/build/test/basedriver/index.js +1 -1
- package/build/test/e2e/basedriver/driver.e2e.spec.js +1 -1
- package/build/test/e2e/basedriver/helpers.e2e.spec.js +1 -1
- package/build/test/e2e/basedriver/websockets.e2e.spec.js +1 -1
- package/build/test/e2e/express/server.e2e.spec.js +1 -1
- package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +1 -1
- package/build/test/e2e/protocol/fake-driver.js +1 -1
- package/build/test/e2e/protocol/helpers.js +1 -1
- package/build/test/e2e/protocol/protocol.e2e.spec.js +13 -13
- package/build/test/helpers.js +1 -1
- package/build/test/unit/basedriver/capabilities.spec.js +12 -12
- package/build/test/unit/basedriver/capability.spec.js +15 -15
- package/build/test/unit/basedriver/commands/event.spec.js +1 -1
- package/build/test/unit/basedriver/commands/log.spec.js +1 -1
- package/build/test/unit/basedriver/device-settings.spec.js +1 -1
- package/build/test/unit/basedriver/driver.spec.js +1 -1
- package/build/test/unit/basedriver/helpers.spec.js +33 -33
- package/build/test/unit/basedriver/timeout.spec.js +1 -1
- package/build/test/unit/express/server.spec.js +1 -1
- package/build/test/unit/express/static.spec.js +2 -2
- package/build/test/unit/jsonwp-proxy/mock-request.js +1 -1
- package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +1 -1
- package/build/test/unit/jsonwp-proxy/proxy.spec.js +2 -2
- package/build/test/unit/jsonwp-proxy/url.spec.js +1 -1
- package/build/test/unit/jsonwp-status/status.spec.js +1 -1
- package/build/test/unit/protocol/errors.spec.js +1 -1
- package/build/test/unit/protocol/routes.spec.js +1 -1
- package/build/test/unit/protocol/validator.spec.js +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/basedriver/capabilities.js +95 -47
- package/lib/basedriver/commands/event.js +4 -4
- package/lib/basedriver/commands/find.js +12 -26
- package/lib/basedriver/commands/index.js +7 -7
- package/lib/basedriver/commands/log.js +5 -7
- package/lib/basedriver/commands/session.js +3 -3
- package/lib/basedriver/commands/settings.js +3 -5
- package/lib/basedriver/commands/timeout.js +18 -23
- package/lib/basedriver/core.js +150 -229
- package/lib/basedriver/desired-caps.js +30 -29
- package/lib/basedriver/device-settings.js +21 -20
- package/lib/basedriver/driver.js +131 -96
- package/lib/basedriver/helpers.js +124 -81
- package/lib/basedriver/logger.js +1 -1
- package/lib/constants.js +2 -6
- package/lib/express/crash.js +4 -6
- package/lib/express/express-logging.js +26 -24
- package/lib/express/idempotency.js +16 -16
- package/lib/express/logger.js +1 -1
- package/lib/express/middleware.js +49 -33
- package/lib/express/server.js +68 -44
- package/lib/express/static.js +11 -12
- package/lib/express/websocket.js +26 -16
- package/lib/helpers/capabilities.js +11 -16
- package/lib/index.js +50 -33
- package/lib/jsonwp-proxy/protocol-converter.js +85 -69
- package/lib/jsonwp-proxy/proxy.js +116 -53
- package/lib/jsonwp-status/status.js +36 -29
- package/lib/protocol/errors.js +469 -292
- package/lib/protocol/helpers.js +5 -8
- package/lib/protocol/index.js +22 -15
- package/lib/protocol/protocol.js +103 -55
- package/lib/protocol/routes.js +430 -273
- package/lib/protocol/validators.js +5 -5
- package/package.json +7 -6
- package/test/basedriver/driver-e2e-tests.js +92 -66
- package/test/basedriver/driver-tests.js +90 -33
- package/test/basedriver/index.js +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
|
|
3
|
-
function isNumber
|
|
3
|
+
function isNumber(o) {
|
|
4
4
|
return _.isNumber(o) || !_.isNaN(parseInt(o, 10)) || !_.isNaN(parseFloat(o));
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function msValidator
|
|
7
|
+
function msValidator(ms) {
|
|
8
8
|
if (!_.isNumber(ms) || ms < 0) {
|
|
9
9
|
throw new Error('Wait ms must be a number equal to 0 or greater');
|
|
10
10
|
}
|
|
@@ -24,7 +24,7 @@ const validators = {
|
|
|
24
24
|
msValidator(ms);
|
|
25
25
|
},
|
|
26
26
|
clickCurrent: (button) => {
|
|
27
|
-
if (!(isNumber(button) || _.isUndefined(button)) ||
|
|
27
|
+
if (!(isNumber(button) || _.isUndefined(button)) || button < 0 || button > 2) {
|
|
28
28
|
throw new Error('Click button must be 0, 1, or 2');
|
|
29
29
|
}
|
|
30
30
|
},
|
|
@@ -32,7 +32,7 @@ const validators = {
|
|
|
32
32
|
if (!isNumber(type) || [0, 1, 2, 4, 6].indexOf(type) === -1) {
|
|
33
33
|
throw new Error('Network type must be one of 0, 1, 2, 4, 6');
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export {
|
|
38
|
+
export {validators};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-driver",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.4",
|
|
4
4
|
"description": "Base driver class for Appium drivers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -43,13 +43,14 @@
|
|
|
43
43
|
"dev": "run-p \"build:distfiles -- --watch\" \"build:test -- --watch\"",
|
|
44
44
|
"fix": "npm run lint -- --fix",
|
|
45
45
|
"lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
|
|
46
|
+
"prepare": "npm run build",
|
|
46
47
|
"test": "npm run test:unit",
|
|
47
48
|
"test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
|
|
48
49
|
"test:unit": "mocha \"./test/unit/**/*.spec.js\""
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@appium/support": "^2.
|
|
52
|
-
"@babel/runtime": "7.
|
|
52
|
+
"@appium/support": "^2.59.0",
|
|
53
|
+
"@babel/runtime": "7.18.3",
|
|
53
54
|
"@colors/colors": "1.5.0",
|
|
54
55
|
"async-lock": "1.3.1",
|
|
55
56
|
"asyncbox": "2.9.2",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"express": "4.18.1",
|
|
61
62
|
"http-status-codes": "2.2.0",
|
|
62
63
|
"lodash": "4.17.21",
|
|
63
|
-
"lru-cache": "7.
|
|
64
|
+
"lru-cache": "7.10.1",
|
|
64
65
|
"method-override": "3.0.0",
|
|
65
66
|
"morgan": "1.10.0",
|
|
66
67
|
"serve-favicon": "2.5.0",
|
|
@@ -68,12 +69,12 @@
|
|
|
68
69
|
"validate.js": "0.13.1"
|
|
69
70
|
},
|
|
70
71
|
"engines": {
|
|
71
|
-
"node": ">=
|
|
72
|
+
"node": ">=14",
|
|
72
73
|
"npm": ">=6"
|
|
73
74
|
},
|
|
74
75
|
"publishConfig": {
|
|
75
76
|
"access": "public"
|
|
76
77
|
},
|
|
77
78
|
"types": "./build/lib/index.d.ts",
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "5c7af8ee73078018e4ec52fccf19fe3f77249d72"
|
|
79
80
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import {
|
|
2
|
+
import {BaseDriver, server, routeConfiguringFunction, DeviceSettings} from '../../lib';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import B from 'bluebird';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import {TEST_HOST, getTestPort, createAppiumURL, METHODS} from '../helpers';
|
|
6
|
+
import {PREFIXED_APPIUM_OPTS_CAP} from '../../lib/basedriver/capabilities';
|
|
7
7
|
const {POST, DELETE} = METHODS;
|
|
8
8
|
|
|
9
|
-
function baseDriverE2ETests
|
|
9
|
+
function baseDriverE2ETests(DriverClass, defaultCaps = {}) {
|
|
10
10
|
let address = defaultCaps['appium:address'] ?? TEST_HOST;
|
|
11
11
|
let port = defaultCaps['appium:port'];
|
|
12
12
|
const className = DriverClass.name || '(unknown driver)';
|
|
@@ -14,9 +14,9 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
14
14
|
describe(`BaseDriver E2E (as ${className})`, function () {
|
|
15
15
|
let baseServer, d;
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
* This URL creates a new session
|
|
18
|
+
* @type {string}
|
|
19
|
+
**/
|
|
20
20
|
let newSessionURL;
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -33,13 +33,13 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
33
33
|
let createSessionURL;
|
|
34
34
|
|
|
35
35
|
before(async function () {
|
|
36
|
-
port = port ?? await getTestPort();
|
|
36
|
+
port = port ?? (await getTestPort());
|
|
37
37
|
defaultCaps = {...defaultCaps, 'appium:port': port};
|
|
38
38
|
d = new DriverClass({port, address});
|
|
39
39
|
baseServer = await server({
|
|
40
40
|
routeConfiguringFunction: routeConfiguringFunction(d),
|
|
41
41
|
port,
|
|
42
|
-
hostname: TEST_HOST
|
|
42
|
+
hostname: TEST_HOST,
|
|
43
43
|
});
|
|
44
44
|
createAppiumTestURL = createAppiumURL(address, port);
|
|
45
45
|
newSessionURL = createAppiumTestURL('', 'session');
|
|
@@ -50,26 +50,32 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
50
50
|
await baseServer.close();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
async function startSession
|
|
54
|
-
return (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
async function startSession(caps) {
|
|
54
|
+
return (
|
|
55
|
+
await axios({
|
|
56
|
+
url: newSessionURL,
|
|
57
|
+
method: POST,
|
|
58
|
+
data: {capabilities: {alwaysMatch: caps, firstMatch: [{}]}},
|
|
59
|
+
})
|
|
60
|
+
).data.value;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
async function endSession
|
|
62
|
-
return (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
async function endSession(id) {
|
|
64
|
+
return (
|
|
65
|
+
await axios({
|
|
66
|
+
url: createSessionURL(id),
|
|
67
|
+
method: DELETE,
|
|
68
|
+
validateStatus: null,
|
|
69
|
+
})
|
|
70
|
+
).data.value;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
async function getSession
|
|
70
|
-
return (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
async function getSession(id) {
|
|
74
|
+
return (
|
|
75
|
+
await axios({
|
|
76
|
+
url: createSessionURL(id),
|
|
77
|
+
})
|
|
78
|
+
).data.value;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
describe('session handling', function () {
|
|
@@ -77,16 +83,20 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
77
83
|
const sessionIds = [];
|
|
78
84
|
let times = 0;
|
|
79
85
|
do {
|
|
80
|
-
const {sessionId} = (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
const {sessionId} = (
|
|
87
|
+
await axios({
|
|
88
|
+
url: newSessionURL,
|
|
89
|
+
headers: {
|
|
90
|
+
'X-Idempotency-Key': '123456',
|
|
91
|
+
},
|
|
92
|
+
method: POST,
|
|
93
|
+
data: {
|
|
94
|
+
capabilities: {alwaysMatch: defaultCaps, firstMatch: [{}]},
|
|
95
|
+
},
|
|
96
|
+
simple: false,
|
|
97
|
+
resolveWithFullResponse: true,
|
|
98
|
+
})
|
|
99
|
+
).data.value;
|
|
90
100
|
|
|
91
101
|
sessionIds.push(sessionId);
|
|
92
102
|
times++;
|
|
@@ -105,14 +115,18 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
105
115
|
const reqs = [];
|
|
106
116
|
let times = 0;
|
|
107
117
|
do {
|
|
108
|
-
reqs.push(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
reqs.push(
|
|
119
|
+
axios({
|
|
120
|
+
url: newSessionURL,
|
|
121
|
+
headers: {
|
|
122
|
+
'X-Idempotency-Key': '12345',
|
|
123
|
+
},
|
|
124
|
+
method: POST,
|
|
125
|
+
data: {
|
|
126
|
+
capabilities: {alwaysMatch: defaultCaps, firstMatch: [{}]},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
);
|
|
116
130
|
times++;
|
|
117
131
|
} while (times < 2);
|
|
118
132
|
const sessionIds = (await B.all(reqs)).map((x) => x.data.value.sessionId);
|
|
@@ -149,13 +163,12 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
149
163
|
});
|
|
150
164
|
});
|
|
151
165
|
|
|
152
|
-
it.skip('should throw NYI for commands not implemented', async function () {
|
|
153
|
-
});
|
|
166
|
+
it.skip('should throw NYI for commands not implemented', async function () {});
|
|
154
167
|
|
|
155
168
|
describe('command timeouts', function () {
|
|
156
169
|
let originalFindElement, originalFindElements;
|
|
157
170
|
|
|
158
|
-
async function startTimeoutSession
|
|
171
|
+
async function startTimeoutSession(timeout) {
|
|
159
172
|
const caps = _.cloneDeep(defaultCaps);
|
|
160
173
|
caps['appium:newCommandTimeout'] = timeout;
|
|
161
174
|
return await startSession(caps);
|
|
@@ -179,7 +192,6 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
179
192
|
d.findElements = originalFindElements;
|
|
180
193
|
});
|
|
181
194
|
|
|
182
|
-
|
|
183
195
|
it('should set a default commandTimeout', async function () {
|
|
184
196
|
let newSession = await startTimeoutSession();
|
|
185
197
|
d.newCommandTimeoutMs.should.be.above(0);
|
|
@@ -210,11 +222,13 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
210
222
|
it('should not timeout with commandTimeout of false', async function () {
|
|
211
223
|
let newSession = await startTimeoutSession(0.1);
|
|
212
224
|
let start = Date.now();
|
|
213
|
-
const {value} = (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
225
|
+
const {value} = (
|
|
226
|
+
await axios({
|
|
227
|
+
url: createAppiumTestURL(d.sessionId, 'elements'),
|
|
228
|
+
method: POST,
|
|
229
|
+
data: {using: 'name', value: 'foo'},
|
|
230
|
+
})
|
|
231
|
+
).data;
|
|
218
232
|
(Date.now() - start).should.be.above(150);
|
|
219
233
|
value.should.eql(['foo']);
|
|
220
234
|
await endSession(newSession.sessionId);
|
|
@@ -230,9 +244,11 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
230
244
|
data: {using: 'name', value: 'foo'},
|
|
231
245
|
});
|
|
232
246
|
await B.delay(400);
|
|
233
|
-
const {value} = (
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
const {value} = (
|
|
248
|
+
await axios({
|
|
249
|
+
url: createSessionURL(d.sessionId),
|
|
250
|
+
})
|
|
251
|
+
).data;
|
|
236
252
|
value.platformName.should.equal(defaultCaps.platformName);
|
|
237
253
|
const resp = await endSession(newSession.sessionId);
|
|
238
254
|
should.equal(resp, null);
|
|
@@ -251,10 +267,12 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
251
267
|
data: {using: 'name', value: 'foo'},
|
|
252
268
|
});
|
|
253
269
|
await B.delay(400);
|
|
254
|
-
const {value} = (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
270
|
+
const {value} = (
|
|
271
|
+
await axios({
|
|
272
|
+
url: sessionURL,
|
|
273
|
+
validateStatus: null,
|
|
274
|
+
})
|
|
275
|
+
).data;
|
|
258
276
|
value.error.should.equal('invalid session id');
|
|
259
277
|
should.equal(d.sessionId, null);
|
|
260
278
|
const resp = await endSession(newSession.sessionId);
|
|
@@ -269,7 +287,6 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
269
287
|
await endSession(newSession.sessionId);
|
|
270
288
|
should.not.exist(d.noCommandTimer);
|
|
271
289
|
});
|
|
272
|
-
|
|
273
290
|
});
|
|
274
291
|
|
|
275
292
|
describe('settings api', function () {
|
|
@@ -283,8 +300,7 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
283
300
|
await d.settings.update({ignoreUnimportantViews: true}).should.not.be.rejected;
|
|
284
301
|
});
|
|
285
302
|
it('should reject for invalid update object', async function () {
|
|
286
|
-
await d.settings.update('invalid json').should.eventually
|
|
287
|
-
.be.rejectedWith('JSON');
|
|
303
|
+
await d.settings.update('invalid json').should.eventually.be.rejectedWith('JSON');
|
|
288
304
|
});
|
|
289
305
|
});
|
|
290
306
|
|
|
@@ -302,7 +318,15 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
302
318
|
// make sure that the request gets to the server before our shutdown
|
|
303
319
|
await B.delay(100);
|
|
304
320
|
const shutdownEventPromise = new B((resolve, reject) => {
|
|
305
|
-
setTimeout(
|
|
321
|
+
setTimeout(
|
|
322
|
+
() =>
|
|
323
|
+
reject(
|
|
324
|
+
new Error(
|
|
325
|
+
'onUnexpectedShutdown event is expected to be fired within 5 seconds timeout'
|
|
326
|
+
)
|
|
327
|
+
),
|
|
328
|
+
5000
|
|
329
|
+
);
|
|
306
330
|
d.onUnexpectedShutdown(resolve);
|
|
307
331
|
});
|
|
308
332
|
d.startUnexpectedShutdown(new Error('Crashytimes'));
|
|
@@ -323,9 +347,11 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
323
347
|
await endSession(session.sessionId);
|
|
324
348
|
});
|
|
325
349
|
it('should add start session timings', async function () {
|
|
326
|
-
const caps = Object.assign({}, defaultCaps, {
|
|
350
|
+
const caps = Object.assign({}, defaultCaps, {
|
|
351
|
+
'appium:eventTimings': true,
|
|
352
|
+
});
|
|
327
353
|
const session = await startSession(caps);
|
|
328
|
-
const res =
|
|
354
|
+
const res = await getSession(session.sessionId);
|
|
329
355
|
should.exist(res.events);
|
|
330
356
|
should.exist(res.events.newSessionRequested);
|
|
331
357
|
should.exist(res.events.newSessionStarted);
|
|
@@ -346,7 +372,7 @@ function baseDriverE2ETests (DriverClass, defaultCaps = {}) {
|
|
|
346
372
|
[PREFIXED_APPIUM_OPTS_CAP]: {
|
|
347
373
|
platformVersion: '11.4',
|
|
348
374
|
'appium:deviceName': 'iPhone 11',
|
|
349
|
-
}
|
|
375
|
+
},
|
|
350
376
|
});
|
|
351
377
|
d.opts.platformVersion.should.eql('11.4');
|
|
352
378
|
d.opts.deviceName.should.eql('iPhone 11');
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import B from 'bluebird';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import {DeviceSettings} from '../../lib';
|
|
4
|
+
import {createSandbox} from 'sinon';
|
|
6
5
|
|
|
7
6
|
// wrap these tests in a function so we can export the tests and re-use them
|
|
8
7
|
// for actual driver implementations
|
|
9
|
-
function baseDriverUnitTests
|
|
8
|
+
function baseDriverUnitTests(DriverClass, defaultCaps = {}) {
|
|
10
9
|
// to display the driver under test in report
|
|
11
10
|
const className = DriverClass.name || '(unknown driver)';
|
|
12
11
|
|
|
@@ -19,7 +18,6 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
19
18
|
});
|
|
20
19
|
|
|
21
20
|
describe('Log prefix', function () {
|
|
22
|
-
|
|
23
21
|
it('should setup log prefix', async function () {
|
|
24
22
|
const d = new DriverClass();
|
|
25
23
|
const previousPrefix = d.log.prefix;
|
|
@@ -37,7 +35,6 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
37
35
|
previousPrefix.should.eql(d.log.prefix);
|
|
38
36
|
}
|
|
39
37
|
});
|
|
40
|
-
|
|
41
38
|
});
|
|
42
39
|
|
|
43
40
|
describe(`BaseDriver (as ${className})`, function () {
|
|
@@ -79,7 +76,9 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
79
76
|
|
|
80
77
|
it('should not be able to start two sessions without closing the first', async function () {
|
|
81
78
|
await d.createSession(null, null, _.cloneDeep(w3cCaps));
|
|
82
|
-
await d
|
|
79
|
+
await d
|
|
80
|
+
.createSession(null, null, _.cloneDeep(w3cCaps))
|
|
81
|
+
.should.eventually.be.rejectedWith('session');
|
|
83
82
|
});
|
|
84
83
|
|
|
85
84
|
it('should be able to delete a session', async function () {
|
|
@@ -108,11 +107,11 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
108
107
|
|
|
109
108
|
sessions.length.should.equal(1);
|
|
110
109
|
sessions[0].should.include({
|
|
111
|
-
id: d.sessionId
|
|
110
|
+
id: d.sessionId,
|
|
112
111
|
});
|
|
113
112
|
sessions[0].capabilities.should.include({
|
|
114
113
|
deviceName: 'Commodore 64',
|
|
115
|
-
platformName: 'Fake'
|
|
114
|
+
platformName: 'Fake',
|
|
116
115
|
});
|
|
117
116
|
});
|
|
118
117
|
|
|
@@ -125,7 +124,15 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
125
124
|
let cmdPromise = d.executeCommand('getStatus');
|
|
126
125
|
await B.delay(10);
|
|
127
126
|
const p = new B((resolve, reject) => {
|
|
128
|
-
setTimeout(
|
|
127
|
+
setTimeout(
|
|
128
|
+
() =>
|
|
129
|
+
reject(
|
|
130
|
+
new Error(
|
|
131
|
+
'onUnexpectedShutdown event is expected to be fired within 5 seconds timeout'
|
|
132
|
+
)
|
|
133
|
+
),
|
|
134
|
+
5000
|
|
135
|
+
);
|
|
129
136
|
d.onUnexpectedShutdown(resolve);
|
|
130
137
|
});
|
|
131
138
|
d.startUnexpectedShutdown(new Error('We crashed'));
|
|
@@ -142,7 +149,15 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
142
149
|
}.bind(d);
|
|
143
150
|
await d.createSession(null, null, w3cCaps);
|
|
144
151
|
const p = new B((resolve, reject) => {
|
|
145
|
-
setTimeout(
|
|
152
|
+
setTimeout(
|
|
153
|
+
() =>
|
|
154
|
+
reject(
|
|
155
|
+
new Error(
|
|
156
|
+
'onUnexpectedShutdown event is expected to be fired within 5 seconds timeout'
|
|
157
|
+
)
|
|
158
|
+
),
|
|
159
|
+
5000
|
|
160
|
+
);
|
|
146
161
|
d.onUnexpectedShutdown(resolve);
|
|
147
162
|
});
|
|
148
163
|
d.startUnexpectedShutdown(new Error('We crashed'));
|
|
@@ -160,7 +175,15 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
160
175
|
|
|
161
176
|
await d.createSession(null, null, _.cloneDeep(w3cCaps));
|
|
162
177
|
const p = new B((resolve, reject) => {
|
|
163
|
-
setTimeout(
|
|
178
|
+
setTimeout(
|
|
179
|
+
() =>
|
|
180
|
+
reject(
|
|
181
|
+
new Error(
|
|
182
|
+
'onUnexpectedShutdown event is expected to be fired within 5 seconds timeout'
|
|
183
|
+
)
|
|
184
|
+
),
|
|
185
|
+
5000
|
|
186
|
+
);
|
|
164
187
|
d.onUnexpectedShutdown(resolve);
|
|
165
188
|
});
|
|
166
189
|
d.startUnexpectedShutdown(new Error('We crashed'));
|
|
@@ -188,7 +211,10 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
188
211
|
|
|
189
212
|
describe('protocol detection', function () {
|
|
190
213
|
it('should use W3C if only W3C caps are provided', async function () {
|
|
191
|
-
await d.createSession(null, null, {
|
|
214
|
+
await d.createSession(null, null, {
|
|
215
|
+
alwaysMatch: _.clone(defaultCaps),
|
|
216
|
+
firstMatch: [{}],
|
|
217
|
+
});
|
|
192
218
|
d.protocol.should.equal('W3C');
|
|
193
219
|
});
|
|
194
220
|
});
|
|
@@ -328,11 +354,12 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
328
354
|
platformName: 'Fake',
|
|
329
355
|
'appium:deviceName': 'Commodore 64',
|
|
330
356
|
'appium:fullReset': true,
|
|
331
|
-
'appium:noReset': true
|
|
357
|
+
'appium:noReset': true,
|
|
332
358
|
}),
|
|
333
359
|
};
|
|
334
|
-
await d
|
|
335
|
-
|
|
360
|
+
await d
|
|
361
|
+
.createSession(null, null, newCaps)
|
|
362
|
+
.should.eventually.be.rejectedWith(/noReset.+fullReset/);
|
|
336
363
|
});
|
|
337
364
|
});
|
|
338
365
|
|
|
@@ -349,7 +376,9 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
349
376
|
d.proxyActive(sessId).should.be.false;
|
|
350
377
|
});
|
|
351
378
|
it('should throw an error when sessionId is wrong', function () {
|
|
352
|
-
(() => {
|
|
379
|
+
(() => {
|
|
380
|
+
d.proxyActive('aaa');
|
|
381
|
+
}).should.throw;
|
|
353
382
|
});
|
|
354
383
|
});
|
|
355
384
|
|
|
@@ -361,7 +390,9 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
361
390
|
d.getProxyAvoidList(sessId).should.be.an.instanceof(Array);
|
|
362
391
|
});
|
|
363
392
|
it('should throw an error when sessionId is wrong', function () {
|
|
364
|
-
(() => {
|
|
393
|
+
(() => {
|
|
394
|
+
d.getProxyAvoidList('aaa');
|
|
395
|
+
}).should.throw;
|
|
365
396
|
});
|
|
366
397
|
});
|
|
367
398
|
|
|
@@ -373,7 +404,9 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
373
404
|
d.canProxy(sessId).should.be.a('boolean');
|
|
374
405
|
});
|
|
375
406
|
it('should throw an error when sessionId is wrong', function () {
|
|
376
|
-
(() => {
|
|
407
|
+
(() => {
|
|
408
|
+
d.canProxy();
|
|
409
|
+
}).should.throw;
|
|
377
410
|
});
|
|
378
411
|
});
|
|
379
412
|
|
|
@@ -381,21 +414,38 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
381
414
|
it('should validate form of avoidance list', function () {
|
|
382
415
|
const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
|
|
383
416
|
avoidStub.returns([['POST', /\/foo/], ['GET']]);
|
|
384
|
-
(() => {
|
|
385
|
-
|
|
386
|
-
|
|
417
|
+
(() => {
|
|
418
|
+
d.proxyRouteIsAvoided();
|
|
419
|
+
}).should.throw;
|
|
420
|
+
avoidStub.returns([
|
|
421
|
+
['POST', /\/foo/],
|
|
422
|
+
['GET', /^foo/, 'bar'],
|
|
423
|
+
]);
|
|
424
|
+
(() => {
|
|
425
|
+
d.proxyRouteIsAvoided();
|
|
426
|
+
}).should.throw;
|
|
387
427
|
avoidStub.restore();
|
|
388
428
|
});
|
|
389
429
|
it('should reject bad http methods', function () {
|
|
390
430
|
const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
|
|
391
|
-
avoidStub.returns([
|
|
392
|
-
|
|
431
|
+
avoidStub.returns([
|
|
432
|
+
['POST', /^foo/],
|
|
433
|
+
['BAZETE', /^bar/],
|
|
434
|
+
]);
|
|
435
|
+
(() => {
|
|
436
|
+
d.proxyRouteIsAvoided();
|
|
437
|
+
}).should.throw;
|
|
393
438
|
avoidStub.restore();
|
|
394
439
|
});
|
|
395
440
|
it('should reject non-regex routes', function () {
|
|
396
441
|
const avoidStub = sandbox.stub(d, 'getProxyAvoidList');
|
|
397
|
-
avoidStub.returns([
|
|
398
|
-
|
|
442
|
+
avoidStub.returns([
|
|
443
|
+
['POST', /^foo/],
|
|
444
|
+
['GET', '/bar'],
|
|
445
|
+
]);
|
|
446
|
+
(() => {
|
|
447
|
+
d.proxyRouteIsAvoided();
|
|
448
|
+
}).should.throw;
|
|
399
449
|
avoidStub.restore();
|
|
400
450
|
});
|
|
401
451
|
it('should return true for routes in the avoid list', function () {
|
|
@@ -425,7 +475,10 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
425
475
|
beforeEach(async function () {
|
|
426
476
|
beforeStartTime = Date.now();
|
|
427
477
|
d.shouldValidateCaps = false;
|
|
428
|
-
await d.executeCommand('createSession', null, null, {
|
|
478
|
+
await d.executeCommand('createSession', null, null, {
|
|
479
|
+
alwaysMatch: {...defaultCaps},
|
|
480
|
+
firstMatch: [{}],
|
|
481
|
+
});
|
|
429
482
|
});
|
|
430
483
|
describe('#eventHistory', function () {
|
|
431
484
|
it('should have an eventHistory property', function () {
|
|
@@ -492,12 +545,16 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
|
|
|
492
545
|
describe('.reset', function () {
|
|
493
546
|
it('should reset as W3C if the original session was W3C', async function () {
|
|
494
547
|
const caps = {
|
|
495
|
-
alwaysMatch: Object.assign(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
548
|
+
alwaysMatch: Object.assign(
|
|
549
|
+
{},
|
|
550
|
+
{
|
|
551
|
+
'appium:app': 'Fake',
|
|
552
|
+
'appium:deviceName': 'Fake',
|
|
553
|
+
'appium:automationName': 'Fake',
|
|
554
|
+
platformName: 'Fake',
|
|
555
|
+
},
|
|
556
|
+
defaultCaps
|
|
557
|
+
),
|
|
501
558
|
firstMatch: [{}],
|
|
502
559
|
};
|
|
503
560
|
await d.createSession(undefined, undefined, caps);
|
package/test/basedriver/index.js
CHANGED