@appium/base-driver 8.5.5 → 8.6.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.
- package/build/lib/basedriver/capabilities.js +2 -2
- package/build/lib/basedriver/commands/log.js +2 -4
- package/build/lib/basedriver/core.d.ts +8 -0
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +5 -1
- package/build/lib/basedriver/helpers.js +2 -2
- package/build/lib/express/server.d.ts +69 -7
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +18 -16
- package/build/lib/express/websocket.d.ts +12 -30
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js +6 -4
- package/build/lib/index.d.ts +11 -180
- package/build/lib/index.js +107 -80
- package/build/lib/jsonwp-proxy/protocol-converter.js +2 -4
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +6 -7
- package/build/lib/protocol/protocol.d.ts +6 -4
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +5 -7
- package/build/lib/protocol/routes.js +2 -6
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/basedriver/core.js +11 -0
- package/lib/express/server.js +124 -36
- package/lib/express/websocket.js +13 -11
- package/lib/index.js +16 -62
- package/lib/jsonwp-proxy/proxy.js +17 -1
- package/lib/protocol/protocol.js +8 -1
- package/package.json +16 -14
- package/build/test/basedriver/README.md +0 -5
- package/build/test/basedriver/driver-e2e-tests.js +0 -413
- package/build/test/basedriver/driver-tests.js +0 -572
- package/build/test/basedriver/index.js +0 -26
- package/build/test/e2e/basedriver/driver.e2e.spec.js +0 -15
- package/build/test/e2e/basedriver/helpers.e2e.spec.js +0 -192
- package/build/test/e2e/basedriver/websockets.e2e.spec.js +0 -87
- package/build/test/e2e/express/server.e2e.spec.js +0 -159
- package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +0 -59
- package/build/test/e2e/protocol/fake-driver.js +0 -163
- package/build/test/e2e/protocol/helpers.js +0 -25
- package/build/test/e2e/protocol/protocol.e2e.spec.js +0 -1186
- package/build/test/helpers.js +0 -55
- package/build/test/unit/basedriver/capabilities.spec.js +0 -672
- package/build/test/unit/basedriver/capability.spec.js +0 -353
- package/build/test/unit/basedriver/commands/event.spec.js +0 -110
- package/build/test/unit/basedriver/commands/log.spec.js +0 -92
- package/build/test/unit/basedriver/device-settings.spec.js +0 -97
- package/build/test/unit/basedriver/driver.spec.js +0 -15
- package/build/test/unit/basedriver/helpers.spec.js +0 -151
- package/build/test/unit/basedriver/timeout.spec.js +0 -135
- package/build/test/unit/express/server.spec.js +0 -155
- package/build/test/unit/express/static.spec.js +0 -26
- package/build/test/unit/jsonwp-proxy/mock-request.js +0 -91
- package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +0 -171
- package/build/test/unit/jsonwp-proxy/proxy.spec.js +0 -292
- package/build/test/unit/jsonwp-proxy/url.spec.js +0 -165
- package/build/test/unit/jsonwp-status/status.spec.js +0 -34
- package/build/test/unit/protocol/errors.spec.js +0 -390
- package/build/test/unit/protocol/routes.spec.js +0 -80
- package/build/test/unit/protocol/validator.spec.js +0 -149
- package/test/basedriver/README.md +0 -5
- package/test/basedriver/driver-e2e-tests.js +0 -386
- package/test/basedriver/driver-tests.js +0 -624
- package/test/basedriver/index.js +0 -6
package/lib/express/server.js
CHANGED
|
@@ -30,11 +30,16 @@ import {EventEmitter} from 'events';
|
|
|
30
30
|
|
|
31
31
|
const KEEP_ALIVE_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {ServerOpts} opts
|
|
36
|
+
* @returns {Promise<AppiumServer>}
|
|
37
|
+
*/
|
|
38
|
+
async function server(opts) {
|
|
34
39
|
const {
|
|
35
40
|
routeConfiguringFunction,
|
|
36
41
|
port,
|
|
37
|
-
hostname
|
|
42
|
+
hostname,
|
|
38
43
|
allowCors = true,
|
|
39
44
|
basePath = DEFAULT_BASE_PATH,
|
|
40
45
|
extraMethodMap = {},
|
|
@@ -52,7 +57,11 @@ async function server(opts = {}) {
|
|
|
52
57
|
// way we resolve it is to use an async function here but to wrap all the inner logic in
|
|
53
58
|
// try/catch so any errors can be passed to reject.
|
|
54
59
|
try {
|
|
55
|
-
configureHttp({
|
|
60
|
+
const appiumServer = configureHttp({
|
|
61
|
+
httpServer,
|
|
62
|
+
reject,
|
|
63
|
+
keepAliveTimeout,
|
|
64
|
+
});
|
|
56
65
|
configureServer({
|
|
57
66
|
app,
|
|
58
67
|
addRoutes: routeConfiguringFunction,
|
|
@@ -62,7 +71,7 @@ async function server(opts = {}) {
|
|
|
62
71
|
});
|
|
63
72
|
// allow extensions to update the app and http server objects
|
|
64
73
|
for (const updater of serverUpdaters) {
|
|
65
|
-
await updater(app,
|
|
74
|
+
await updater(app, appiumServer);
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
// once all configurations and updaters have been applied, make sure to set up a catchall
|
|
@@ -71,13 +80,18 @@ async function server(opts = {}) {
|
|
|
71
80
|
app.all('*', catch404Handler);
|
|
72
81
|
|
|
73
82
|
await startServer({httpServer, hostname, port, keepAliveTimeout});
|
|
74
|
-
|
|
83
|
+
|
|
84
|
+
resolve(appiumServer);
|
|
75
85
|
} catch (err) {
|
|
76
86
|
reject(err);
|
|
77
87
|
}
|
|
78
88
|
});
|
|
79
89
|
}
|
|
80
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Sets up some Express middleware and stuff
|
|
93
|
+
* @param {ConfigureServerOpts} opts
|
|
94
|
+
*/
|
|
81
95
|
function configureServer({
|
|
82
96
|
app,
|
|
83
97
|
addRoutes,
|
|
@@ -125,20 +139,28 @@ function configureServer({
|
|
|
125
139
|
app.all('/test/guinea-pig-app-banner', guineaPigAppBanner);
|
|
126
140
|
}
|
|
127
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Monkeypatches the `http.Server` instance and returns a {@linkcode AppiumServer}.
|
|
144
|
+
* This function _mutates_ the `httpServer` parameter.
|
|
145
|
+
* @param {ConfigureHttpOpts} opts
|
|
146
|
+
* @returns {AppiumServer}
|
|
147
|
+
*/
|
|
128
148
|
function configureHttp({httpServer, reject, keepAliveTimeout}) {
|
|
129
149
|
const serverState = {
|
|
130
150
|
notifier: new EventEmitter(),
|
|
131
151
|
closed: false,
|
|
132
152
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
// TS does not love monkeypatching.
|
|
154
|
+
const appiumServer = /** @type {AppiumServer} */ (/** @type {unknown} */ (httpServer));
|
|
155
|
+
appiumServer.addWebSocketHandler = addWebSocketHandler;
|
|
156
|
+
appiumServer.removeWebSocketHandler = removeWebSocketHandler;
|
|
157
|
+
appiumServer.removeAllWebSocketHandlers = removeAllWebSocketHandlers;
|
|
158
|
+
appiumServer.getWebSocketHandlers = getWebSocketHandlers;
|
|
137
159
|
|
|
138
160
|
// http.Server.close() only stops new connections, but we need to wait until
|
|
139
161
|
// all connections are closed and the `close` event is emitted
|
|
140
|
-
const close =
|
|
141
|
-
|
|
162
|
+
const close = appiumServer.close.bind(appiumServer);
|
|
163
|
+
appiumServer.close = async () =>
|
|
142
164
|
await new B((resolve, reject) => {
|
|
143
165
|
// https://github.com/nodejs/node-v0.x-archive/issues/9066#issuecomment-124210576
|
|
144
166
|
serverState.closed = true;
|
|
@@ -153,35 +175,41 @@ function configureHttp({httpServer, reject, keepAliveTimeout}) {
|
|
|
153
175
|
});
|
|
154
176
|
});
|
|
155
177
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
'
|
|
166
|
-
|
|
178
|
+
appiumServer.on(
|
|
179
|
+
'error',
|
|
180
|
+
/** @param {NodeJS.ErrnoException} err */ (err) => {
|
|
181
|
+
if (err.code === 'EADDRNOTAVAIL') {
|
|
182
|
+
log.error(
|
|
183
|
+
'Could not start REST http interface listener. ' + 'Requested address is not available.'
|
|
184
|
+
);
|
|
185
|
+
} else {
|
|
186
|
+
log.error(
|
|
187
|
+
'Could not start REST http interface listener. The requested ' +
|
|
188
|
+
'port may already be in use. Please make sure there is no ' +
|
|
189
|
+
'other instance of this server running already.'
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
reject(err);
|
|
167
193
|
}
|
|
168
|
-
|
|
169
|
-
});
|
|
194
|
+
);
|
|
170
195
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
socket
|
|
196
|
+
appiumServer.on(
|
|
197
|
+
'connection',
|
|
198
|
+
/** @param {AppiumServerSocket} socket */ (socket) => {
|
|
199
|
+
socket.setTimeout(keepAliveTimeout);
|
|
200
|
+
socket.on('error', reject);
|
|
174
201
|
|
|
175
|
-
|
|
176
|
-
|
|
202
|
+
function destroy() {
|
|
203
|
+
socket.destroy();
|
|
204
|
+
}
|
|
205
|
+
socket._openReqCount = 0;
|
|
206
|
+
socket.once('close', () => serverState.notifier.removeListener('shutdown', destroy));
|
|
207
|
+
serverState.notifier.once('shutdown', destroy);
|
|
177
208
|
}
|
|
178
|
-
|
|
179
|
-
socket.once('close', () => serverState.notifier.removeListener('shutdown', destroy));
|
|
180
|
-
serverState.notifier.once('shutdown', destroy);
|
|
181
|
-
});
|
|
209
|
+
);
|
|
182
210
|
|
|
183
|
-
|
|
184
|
-
const socket = req.connection || req.socket;
|
|
211
|
+
appiumServer.on('request', function (req, res) {
|
|
212
|
+
const socket = /** @type {AppiumServerSocket} */ (req.connection || req.socket);
|
|
185
213
|
socket._openReqCount++;
|
|
186
214
|
res.on('finish', function () {
|
|
187
215
|
socket._openReqCount--;
|
|
@@ -190,11 +218,14 @@ function configureHttp({httpServer, reject, keepAliveTimeout}) {
|
|
|
190
218
|
}
|
|
191
219
|
});
|
|
192
220
|
});
|
|
221
|
+
|
|
222
|
+
return appiumServer;
|
|
193
223
|
}
|
|
194
224
|
|
|
195
225
|
/**
|
|
196
|
-
*
|
|
226
|
+
* Starts an {@linkcode AppiumServer}
|
|
197
227
|
* @param {StartServerOpts} opts
|
|
228
|
+
* @returns {Promise<void>}
|
|
198
229
|
*/
|
|
199
230
|
async function startServer({httpServer, port, hostname, keepAliveTimeout}) {
|
|
200
231
|
// If the hostname is omitted, the server will accept
|
|
@@ -208,6 +239,11 @@ async function startServer({httpServer, port, hostname, keepAliveTimeout}) {
|
|
|
208
239
|
await startPromise;
|
|
209
240
|
}
|
|
210
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Normalize base path string
|
|
244
|
+
* @param {string} basePath
|
|
245
|
+
* @returns {string}
|
|
246
|
+
*/
|
|
211
247
|
function normalizeBasePath(basePath) {
|
|
212
248
|
if (!_.isString(basePath)) {
|
|
213
249
|
throw new Error(`Invalid path prefix ${basePath}`);
|
|
@@ -236,3 +272,55 @@ export {server, configureServer, normalizeBasePath};
|
|
|
236
272
|
* @property {number} keepAliveTimeout - Keep-alive timeout in milliseconds
|
|
237
273
|
* @property {string} [hostname] - Optional hostname
|
|
238
274
|
*/
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @typedef {import('@appium/types').AppiumServer} AppiumServer
|
|
278
|
+
* @typedef {import('@appium/types').AppiumServerSocket} AppiumServerSocket
|
|
279
|
+
* @typedef {import('@appium/types').MethodMap} MethodMap
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Options for {@linkcode configureHttp}
|
|
284
|
+
* @typedef ConfigureHttpOpts
|
|
285
|
+
* @property {import('http').Server} httpServer - HTTP server instance
|
|
286
|
+
* @property {(error?: any) => void} reject - Rejection function from `Promise` constructor
|
|
287
|
+
* @property {number} keepAliveTimeout - Keep-alive timeout in milliseconds
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Options for {@linkcode server}
|
|
292
|
+
* @typedef ServerOpts
|
|
293
|
+
* @property {RouteConfiguringFunction} routeConfiguringFunction
|
|
294
|
+
* @property {number} port
|
|
295
|
+
* @property {string} [hostname]
|
|
296
|
+
* @property {boolean} [allowCors]
|
|
297
|
+
* @property {string} [basePath]
|
|
298
|
+
* @property {MethodMap} [extraMethodMap]
|
|
299
|
+
* @property {import('@appium/types').UpdateServerCallback[]} [serverUpdaters]
|
|
300
|
+
* @property {number} [keepAliveTimeout]
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* A function which configures routes
|
|
305
|
+
* @callback RouteConfiguringFunction
|
|
306
|
+
* @param {import('express').Express} app
|
|
307
|
+
* @param {RouteConfiguringFunctionOpts} [opts]
|
|
308
|
+
* @returns {void}
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Options for a {@linkcode RouteConfiguringFunction}
|
|
313
|
+
* @typedef RouteConfiguringFunctionOpts
|
|
314
|
+
* @property {string} [basePath]
|
|
315
|
+
* @property {MethodMap} [extraMethodMap]
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Options for {@linkcode configureServer}
|
|
320
|
+
* @typedef ConfigureServerOpts
|
|
321
|
+
* @property {import('express').Express} app
|
|
322
|
+
* @property {RouteConfiguringFunction} addRoutes
|
|
323
|
+
* @property {boolean} [allowCors]
|
|
324
|
+
* @property {string} [basePath]
|
|
325
|
+
* @property {MethodMap} [extraMethodMap]
|
|
326
|
+
*/
|
package/lib/express/websocket.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable require-await */
|
|
1
2
|
import _ from 'lodash';
|
|
2
3
|
import {URL} from 'url';
|
|
3
4
|
import B from 'bluebird';
|
|
@@ -9,20 +10,21 @@ const DEFAULT_WS_PATHNAME_PREFIX = '/ws';
|
|
|
9
10
|
* It is expected this function is called in Express
|
|
10
11
|
* server instance context.
|
|
11
12
|
*
|
|
12
|
-
* @this {
|
|
13
|
+
* @this {AppiumServer} - An instance of express HTTP server.
|
|
13
14
|
* @param {string} handlerPathname - Web socket endpoint path starting with
|
|
14
15
|
* a single slash character. It is recommended to always add
|
|
15
16
|
* DEFAULT_WS_PATHNAME_PREFIX to all web socket pathnames.
|
|
16
|
-
* @param {
|
|
17
|
+
* @param {import('ws').Server} handlerServer - WebSocket server instance. See
|
|
17
18
|
* https://github.com/websockets/ws/pull/885 for more details
|
|
18
19
|
* on how to configure the handler properly.
|
|
20
|
+
* @returns {Promise<void>}
|
|
19
21
|
*/
|
|
20
|
-
// eslint-disable-next-line require-await
|
|
21
22
|
async function addWebSocketHandler(handlerPathname, handlerServer) {
|
|
23
|
+
const server = /** @type {AppiumServer} */ (this);
|
|
22
24
|
if (_.isUndefined(this.webSocketsMapping)) {
|
|
23
|
-
|
|
25
|
+
server.webSocketsMapping = {};
|
|
24
26
|
// https://github.com/websockets/ws/pull/885
|
|
25
|
-
|
|
27
|
+
server.on('upgrade', (request, socket, head) => {
|
|
26
28
|
let currentPathname;
|
|
27
29
|
try {
|
|
28
30
|
// @ts-expect-error
|
|
@@ -30,7 +32,7 @@ async function addWebSocketHandler(handlerPathname, handlerServer) {
|
|
|
30
32
|
} catch {
|
|
31
33
|
currentPathname = request.url;
|
|
32
34
|
}
|
|
33
|
-
for (const [pathname, wsServer] of _.toPairs(
|
|
35
|
+
for (const [pathname, wsServer] of _.toPairs(server.webSocketsMapping)) {
|
|
34
36
|
if (currentPathname === pathname) {
|
|
35
37
|
wsServer.handleUpgrade(request, socket, head, (ws) => {
|
|
36
38
|
wsServer.emit('connection', ws, request);
|
|
@@ -50,10 +52,10 @@ async function addWebSocketHandler(handlerPathname, handlerServer) {
|
|
|
50
52
|
* It is expected this function is called in Express
|
|
51
53
|
* server instance context.
|
|
52
54
|
*
|
|
55
|
+
* @this {AppiumServer}
|
|
53
56
|
* @param {string?} [keysFilter] - Only include pathnames with given
|
|
54
57
|
* `keysFilter` value if set. All pairs will be included by default.
|
|
55
|
-
* @returns {Promise<
|
|
56
|
-
* matching the search criteria or an empty object otherwise.
|
|
58
|
+
* @returns {Promise<Record<string, import('ws').Server>>} pathnames to websocket server instances mapping matching the search criteria or an empty object otherwise.
|
|
57
59
|
*/
|
|
58
60
|
// eslint-disable-next-line require-await
|
|
59
61
|
async function getWebSocketHandlers(keysFilter = null) {
|
|
@@ -75,7 +77,7 @@ async function getWebSocketHandlers(keysFilter = null) {
|
|
|
75
77
|
* is not present in the handlers list.
|
|
76
78
|
* It is expected this function is called in Express
|
|
77
79
|
* server instance context.
|
|
78
|
-
*
|
|
80
|
+
* @this {AppiumServer}
|
|
79
81
|
* @param {string} handlerPathname - Websocket endpoint path.
|
|
80
82
|
* @returns {Promise<boolean>} true if the handlerPathname was found and deleted
|
|
81
83
|
*/
|
|
@@ -104,7 +106,7 @@ async function removeWebSocketHandler(handlerPathname) {
|
|
|
104
106
|
* Removes all existing websocket handler from express server instance.
|
|
105
107
|
* It is expected this function is called in Express
|
|
106
108
|
* server instance context.
|
|
107
|
-
*
|
|
109
|
+
* @this {AppiumServer}
|
|
108
110
|
* @returns {Promise<boolean>} true if at least one handler has been deleted
|
|
109
111
|
*/
|
|
110
112
|
async function removeAllWebSocketHandlers() {
|
|
@@ -128,5 +130,5 @@ export {
|
|
|
128
130
|
};
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
|
-
* @typedef {import('
|
|
133
|
+
* @typedef {import('@appium/types').AppiumServer} AppiumServer
|
|
132
134
|
*/
|
package/lib/index.js
CHANGED
|
@@ -7,79 +7,33 @@ B.config({
|
|
|
7
7
|
// BaseDriver exports
|
|
8
8
|
import {BaseDriver} from './basedriver/driver';
|
|
9
9
|
export {DriverCore} from './basedriver/core';
|
|
10
|
-
|
|
10
|
+
export {DeviceSettings} from './basedriver/device-settings';
|
|
11
11
|
|
|
12
|
-
export {BaseDriver
|
|
12
|
+
export {BaseDriver};
|
|
13
13
|
export default BaseDriver;
|
|
14
14
|
|
|
15
15
|
// MJSONWP exports
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
routeConfiguringFunction,
|
|
21
|
-
errors,
|
|
22
|
-
isErrorType,
|
|
23
|
-
errorFromMJSONWPStatusCode,
|
|
24
|
-
errorFromW3CJsonCode,
|
|
25
|
-
ALL_COMMANDS,
|
|
26
|
-
METHOD_MAP,
|
|
27
|
-
routeToCommandName,
|
|
28
|
-
NO_SESSION_ID_COMMANDS,
|
|
29
|
-
isSessionCommand,
|
|
30
|
-
determineProtocol,
|
|
31
|
-
CREATE_SESSION_COMMAND,
|
|
32
|
-
DELETE_SESSION_COMMAND,
|
|
33
|
-
GET_STATUS_COMMAND,
|
|
34
|
-
} = protocol;
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
routeConfiguringFunction,
|
|
38
|
-
errors,
|
|
39
|
-
isErrorType,
|
|
40
|
-
PROTOCOLS,
|
|
41
|
-
errorFromMJSONWPStatusCode,
|
|
42
|
-
errorFromW3CJsonCode,
|
|
43
|
-
determineProtocol,
|
|
44
|
-
errorFromMJSONWPStatusCode as errorFromCode,
|
|
45
|
-
ALL_COMMANDS,
|
|
46
|
-
METHOD_MAP,
|
|
47
|
-
routeToCommandName,
|
|
48
|
-
NO_SESSION_ID_COMMANDS,
|
|
49
|
-
isSessionCommand,
|
|
50
|
-
DEFAULT_BASE_PATH,
|
|
51
|
-
CREATE_SESSION_COMMAND,
|
|
52
|
-
DELETE_SESSION_COMMAND,
|
|
53
|
-
GET_STATUS_COMMAND,
|
|
54
|
-
};
|
|
16
|
+
export * from './protocol';
|
|
17
|
+
export {errorFromMJSONWPStatusCode as errorFromCode} from './protocol';
|
|
18
|
+
export {DEFAULT_BASE_PATH, PROTOCOLS} from './constants';
|
|
55
19
|
|
|
56
20
|
// Express exports
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export {STATIC_DIR};
|
|
60
|
-
|
|
61
|
-
import * as serverIndex from './express/server';
|
|
62
|
-
const {server, normalizeBasePath} = serverIndex;
|
|
63
|
-
export {server, normalizeBasePath};
|
|
21
|
+
export {STATIC_DIR} from './express/static';
|
|
22
|
+
export {server, normalizeBasePath} from './express/server';
|
|
64
23
|
|
|
65
24
|
// jsonwp-proxy exports
|
|
66
|
-
|
|
67
|
-
const {JWProxy} = proxyIndex;
|
|
68
|
-
export {JWProxy};
|
|
25
|
+
export {JWProxy} from './jsonwp-proxy/proxy';
|
|
69
26
|
|
|
70
27
|
// jsonwp-status exports
|
|
71
|
-
|
|
72
|
-
const {codes: statusCodes, getSummaryByCode} = statusIndex;
|
|
73
|
-
export {statusCodes, getSummaryByCode};
|
|
28
|
+
export {getSummaryByCode, codes as statusCodes} from './jsonwp-status/status';
|
|
74
29
|
|
|
75
30
|
// W3C capabilities parser
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
31
|
+
export {
|
|
32
|
+
PREFIXED_APPIUM_OPTS_CAP,
|
|
33
|
+
processCapabilities,
|
|
34
|
+
isStandardCap,
|
|
35
|
+
validateCaps,
|
|
36
|
+
} from './basedriver/capabilities';
|
|
79
37
|
|
|
80
38
|
// Web socket helpers
|
|
81
|
-
|
|
82
|
-
const {DEFAULT_WS_PATHNAME_PREFIX} = ws;
|
|
83
|
-
export {DEFAULT_WS_PATHNAME_PREFIX};
|
|
84
|
-
|
|
85
|
-
export {PREFIXED_APPIUM_OPTS_CAP} from './basedriver/capabilities';
|
|
39
|
+
export {DEFAULT_WS_PATHNAME_PREFIX} from './express/websocket';
|
|
@@ -22,6 +22,18 @@ const COMPACT_ERROR_PATTERNS = [/\bECONNREFUSED\b/, /socket hang up/];
|
|
|
22
22
|
|
|
23
23
|
const {MJSONWP, W3C} = PROTOCOLS;
|
|
24
24
|
|
|
25
|
+
const ALLOWED_OPTS = [
|
|
26
|
+
'scheme',
|
|
27
|
+
'server',
|
|
28
|
+
'port',
|
|
29
|
+
'base',
|
|
30
|
+
'reqBasePath',
|
|
31
|
+
'sessionId',
|
|
32
|
+
'timeout',
|
|
33
|
+
'log',
|
|
34
|
+
'keepAlive',
|
|
35
|
+
];
|
|
36
|
+
|
|
25
37
|
class JWProxy {
|
|
26
38
|
/** @type {string} */
|
|
27
39
|
scheme;
|
|
@@ -39,7 +51,11 @@ class JWProxy {
|
|
|
39
51
|
timeout;
|
|
40
52
|
|
|
41
53
|
constructor(opts = {}) {
|
|
42
|
-
|
|
54
|
+
opts = _.pick(opts, ALLOWED_OPTS);
|
|
55
|
+
|
|
56
|
+
// omit 'log' in the defaults assignment here because 'log' is a getter and we are going to set
|
|
57
|
+
// it to this._log (which lies behind the getter) further down
|
|
58
|
+
const options = _.defaults(_.omit(opts, 'log'), {
|
|
43
59
|
scheme: 'http',
|
|
44
60
|
server: 'localhost',
|
|
45
61
|
port: 4444,
|
package/lib/protocol/protocol.js
CHANGED
|
@@ -212,18 +212,25 @@ function makeArgs(requestParams, jsonObj, payloadParams, protocol) {
|
|
|
212
212
|
return args;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
* @param {import('@appium/types').Core} driver
|
|
218
|
+
* @returns {import('../express/server').RouteConfiguringFunction}
|
|
219
|
+
*/
|
|
215
220
|
function routeConfiguringFunction(driver) {
|
|
216
221
|
if (!driver.sessionExists) {
|
|
217
222
|
throw new Error('Drivers must implement `sessionExists` property');
|
|
218
223
|
}
|
|
219
224
|
|
|
225
|
+
// "execute" isn't defined anywhere
|
|
226
|
+
// @ts-expect-error
|
|
220
227
|
if (!(driver.executeCommand || driver.execute)) {
|
|
221
228
|
throw new Error('Drivers must implement `executeCommand` or `execute` method');
|
|
222
229
|
}
|
|
223
230
|
|
|
224
231
|
// return a function which will add all the routes to the driver. Here extraMethods might be
|
|
225
232
|
// passed in as defined by Appium plugins, so we need to add those to the default list
|
|
226
|
-
return function addRoutes(app, {basePath = DEFAULT_BASE_PATH, extraMethodMap = {}}) {
|
|
233
|
+
return function addRoutes(app, {basePath = DEFAULT_BASE_PATH, extraMethodMap = {}} = {}) {
|
|
227
234
|
// store basePath on the driver instance so it can use it if necessary
|
|
228
235
|
// for example in determining proxy avoidance
|
|
229
236
|
driver.basePath = basePath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-driver",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "Base driver class for Appium drivers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -31,28 +31,29 @@
|
|
|
31
31
|
"index.d.ts",
|
|
32
32
|
"lib",
|
|
33
33
|
"static",
|
|
34
|
-
"
|
|
35
|
-
"!test/e2e/fixtures",
|
|
36
|
-
"build",
|
|
37
|
-
"!build/test/e2e/fixtures"
|
|
34
|
+
"build"
|
|
38
35
|
],
|
|
39
36
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
42
|
-
"build:test": "babel test --root-mode=upward --out-dir=build/test --copy-files",
|
|
43
|
-
"dev": "run-p \"build:distfiles -- --watch\" \"build:test -- --watch\"",
|
|
37
|
+
"build": "babel lib --root-mode=upward --out-dir=build/lib",
|
|
38
|
+
"dev": "npm run build -- --watch",
|
|
44
39
|
"fix": "npm run lint -- --fix",
|
|
45
40
|
"lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
|
|
46
41
|
"prepare": "npm run build",
|
|
47
42
|
"test": "npm run test:unit",
|
|
48
43
|
"test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
|
|
44
|
+
"test:smoke": "node ./index.js",
|
|
49
45
|
"test:unit": "mocha \"./test/unit/**/*.spec.js\""
|
|
50
46
|
},
|
|
51
47
|
"dependencies": {
|
|
52
|
-
"@appium/support": "^2.59.
|
|
53
|
-
"@babel/runtime": "7.18.
|
|
48
|
+
"@appium/support": "^2.59.3",
|
|
49
|
+
"@babel/runtime": "7.18.9",
|
|
54
50
|
"@colors/colors": "1.5.0",
|
|
55
|
-
"async-lock": "1.
|
|
51
|
+
"@types/async-lock": "1.1.5",
|
|
52
|
+
"@types/bluebird": "3.5.36",
|
|
53
|
+
"@types/express": "4.17.13",
|
|
54
|
+
"@types/method-override": "0.0.32",
|
|
55
|
+
"@types/serve-favicon": "2.5.3",
|
|
56
|
+
"async-lock": "1.3.2",
|
|
56
57
|
"asyncbox": "2.9.2",
|
|
57
58
|
"axios": "0.27.2",
|
|
58
59
|
"bluebird": "3.7.2",
|
|
@@ -61,11 +62,12 @@
|
|
|
61
62
|
"express": "4.18.1",
|
|
62
63
|
"http-status-codes": "2.2.0",
|
|
63
64
|
"lodash": "4.17.21",
|
|
64
|
-
"lru-cache": "7.
|
|
65
|
+
"lru-cache": "7.13.1",
|
|
65
66
|
"method-override": "3.0.0",
|
|
66
67
|
"morgan": "1.10.0",
|
|
67
68
|
"serve-favicon": "2.5.0",
|
|
68
69
|
"source-map-support": "0.5.21",
|
|
70
|
+
"type-fest": "2.17.0",
|
|
69
71
|
"validate.js": "0.13.1"
|
|
70
72
|
},
|
|
71
73
|
"engines": {
|
|
@@ -76,5 +78,5 @@
|
|
|
76
78
|
"access": "public"
|
|
77
79
|
},
|
|
78
80
|
"types": "./build/lib/index.d.ts",
|
|
79
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "f6e6d7234e7fe92f989f4e37a71007044985dedf"
|
|
80
82
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Driver Test Helpers
|
|
2
|
-
|
|
3
|
-
This directory contains modules which expose test suites that an external driver can use to test against the base implementation. They are published in the `@appium/base-driver` package.
|
|
4
|
-
|
|
5
|
-
Drivers wanting to leverage these suites will want to add `@appium/base-driver` to their `devDependencies`.
|