@appium/base-driver 10.7.1 → 10.7.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/README.md +2 -2
- package/build/lib/basedriver/capabilities.d.ts +1 -1
- package/build/lib/basedriver/capabilities.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +4 -8
- package/build/lib/basedriver/capabilities.js.map +1 -1
- package/build/lib/basedriver/commands/bidi.d.ts.map +1 -1
- package/build/lib/basedriver/commands/bidi.js +1 -3
- package/build/lib/basedriver/commands/bidi.js.map +1 -1
- package/build/lib/basedriver/commands/event.d.ts.map +1 -1
- package/build/lib/basedriver/commands/event.js.map +1 -1
- package/build/lib/basedriver/commands/execute.d.ts.map +1 -1
- package/build/lib/basedriver/commands/execute.js +1 -1
- package/build/lib/basedriver/commands/execute.js.map +1 -1
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.js.map +1 -1
- package/build/lib/basedriver/commands/log.d.ts.map +1 -1
- package/build/lib/basedriver/commands/log.js +1 -2
- package/build/lib/basedriver/commands/log.js.map +1 -1
- package/build/lib/basedriver/commands/mixin.d.ts.map +1 -1
- package/build/lib/basedriver/commands/mixin.js.map +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/commands/timeout.js.map +1 -1
- package/build/lib/basedriver/core.d.ts +1 -2
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +6 -10
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/device-settings.d.ts +1 -1
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js +2 -3
- package/build/lib/basedriver/device-settings.js.map +1 -1
- package/build/lib/basedriver/driver.d.ts +1 -2
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +6 -11
- package/build/lib/basedriver/driver.js.map +1 -1
- package/build/lib/basedriver/extension-core.d.ts.map +1 -1
- package/build/lib/basedriver/extension-core.js +1 -1
- package/build/lib/basedriver/extension-core.js.map +1 -1
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +6 -11
- package/build/lib/basedriver/helpers.js.map +1 -1
- package/build/lib/basedriver/ipc.d.ts +1 -1
- package/build/lib/basedriver/ipc.d.ts.map +1 -1
- package/build/lib/basedriver/ipc.js +3 -5
- package/build/lib/basedriver/ipc.js.map +1 -1
- package/build/lib/basedriver/validation.d.ts.map +1 -1
- package/build/lib/basedriver/validation.js +1 -2
- package/build/lib/basedriver/validation.js.map +1 -1
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +4 -2
- package/build/lib/express/express-logging.js.map +1 -1
- package/build/lib/express/idempotency.d.ts +1 -1
- package/build/lib/express/idempotency.d.ts.map +1 -1
- package/build/lib/express/idempotency.js +6 -9
- package/build/lib/express/idempotency.js.map +1 -1
- package/build/lib/express/middleware.d.ts +1 -1
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +1 -1
- package/build/lib/express/middleware.js.map +1 -1
- package/build/lib/express/server.d.ts +2 -2
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +8 -9
- package/build/lib/express/server.js.map +1 -1
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js.map +1 -1
- package/build/lib/helpers/capabilities.d.ts +1 -1
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js.map +1 -1
- package/build/lib/helpers/extension-command-name.d.ts.map +1 -1
- package/build/lib/helpers/extension-command-name.js.map +1 -1
- package/build/lib/helpers/levenshtein-match.d.ts.map +1 -1
- package/build/lib/helpers/levenshtein-match.js +1 -4
- package/build/lib/helpers/levenshtein-match.js.map +1 -1
- package/build/lib/index.d.ts +21 -18
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +9 -12
- package/build/lib/index.js.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.js +6 -15
- package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts +3 -3
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +17 -19
- package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
- package/build/lib/jsonwp-status/status.d.ts.map +1 -1
- package/build/lib/jsonwp-status/status.js.map +1 -1
- package/build/lib/protocol/errors.d.ts +1 -1
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +11 -28
- package/build/lib/protocol/errors.js.map +1 -1
- package/build/lib/protocol/helpers.d.ts.map +1 -1
- package/build/lib/protocol/helpers.js.map +1 -1
- package/build/lib/protocol/index.d.ts +4 -4
- package/build/lib/protocol/index.d.ts.map +1 -1
- package/build/lib/protocol/index.js +12 -12
- package/build/lib/protocol/index.js.map +1 -1
- package/build/lib/protocol/protocol.d.ts +1 -1
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +16 -30
- package/build/lib/protocol/protocol.js.map +1 -1
- package/build/lib/protocol/routes.d.ts +1 -1
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +5 -15
- package/build/lib/protocol/routes.js.map +1 -1
- package/build/lib/test-pages/handlers.d.ts.map +1 -1
- package/build/lib/test-pages/handlers.js +2 -2
- package/build/lib/test-pages/handlers.js.map +1 -1
- package/build/lib/test-pages/index.d.ts +1 -1
- package/build/lib/test-pages/index.d.ts.map +1 -1
- package/build/lib/test-pages/index.js +4 -4
- package/build/lib/test-pages/index.js.map +1 -1
- package/build/lib/test-pages/static-dir.d.ts.map +1 -1
- package/build/lib/test-pages/static-dir.js +5 -6
- package/build/lib/test-pages/static-dir.js.map +1 -1
- package/build/lib/test-pages/template.d.ts.map +1 -1
- package/build/lib/test-pages/template.js.map +1 -1
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js.map +1 -1
- package/lib/basedriver/capabilities.ts +14 -37
- package/lib/basedriver/commands/bidi.ts +4 -14
- package/lib/basedriver/commands/event.ts +9 -15
- package/lib/basedriver/commands/execute.ts +5 -14
- package/lib/basedriver/commands/find.ts +3 -10
- package/lib/basedriver/commands/log.ts +2 -2
- package/lib/basedriver/commands/mixin.ts +1 -0
- package/lib/basedriver/commands/timeout.ts +5 -9
- package/lib/basedriver/core.ts +9 -15
- package/lib/basedriver/device-settings.ts +6 -9
- package/lib/basedriver/driver.ts +24 -48
- package/lib/basedriver/extension-core.ts +7 -12
- package/lib/basedriver/helpers.ts +18 -45
- package/lib/basedriver/ipc.ts +13 -18
- package/lib/basedriver/validation.ts +6 -16
- package/lib/express/express-logging.ts +11 -11
- package/lib/express/idempotency.ts +10 -19
- package/lib/express/middleware.ts +10 -18
- package/lib/express/server.ts +29 -38
- package/lib/express/websocket.ts +7 -13
- package/lib/helpers/capabilities.ts +2 -3
- package/lib/helpers/extension-command-name.ts +2 -4
- package/lib/helpers/levenshtein-match.ts +2 -7
- package/lib/{index.js → index.ts} +7 -9
- package/lib/jsonwp-proxy/protocol-converter.ts +24 -88
- package/lib/jsonwp-proxy/proxy.ts +34 -62
- package/lib/jsonwp-status/status.ts +5 -10
- package/lib/protocol/errors.ts +24 -70
- package/lib/protocol/helpers.ts +1 -0
- package/lib/protocol/index.ts +20 -26
- package/lib/protocol/protocol.ts +38 -82
- package/lib/protocol/routes.ts +8 -21
- package/lib/test-pages/handlers.ts +4 -2
- package/lib/test-pages/index.ts +5 -3
- package/lib/test-pages/static-dir.ts +6 -6
- package/lib/test-pages/template.ts +1 -3
- package/lib/utils.ts +1 -4
- package/package.json +29 -32
- package/tsconfig.json +14 -9
- package/LICENSE +0 -201
- package/index.js +0 -1
package/lib/protocol/protocol.ts
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {logger, util} from '@appium/support';
|
|
2
|
+
import type {AppiumLogger, Core, Driver, DriverMethodDef, MethodMap, PayloadParams} from '@appium/types';
|
|
3
|
+
import type {Application, Request, Response} from 'express';
|
|
4
|
+
import type {MultidimensionalReadonlyArray} from 'type-fest';
|
|
5
|
+
|
|
6
|
+
import type {BaseDriver} from '../basedriver/driver';
|
|
7
|
+
import {generateDriverLogPrefix} from '../basedriver/helpers';
|
|
8
|
+
import {log} from '../basedriver/logger';
|
|
9
|
+
import {DEFAULT_BASE_PATH, MAX_LOG_BODY_LENGTH, PROTOCOLS} from '../constants';
|
|
10
|
+
import type {RouteConfiguringFunction} from '../express/server';
|
|
11
|
+
import {isW3cCaps} from '../helpers/capabilities';
|
|
12
|
+
import {omitKeys} from '../utils';
|
|
3
13
|
import {
|
|
4
|
-
|
|
5
|
-
isErrorType,
|
|
6
|
-
getResponseForW3CError,
|
|
14
|
+
BadParametersError,
|
|
7
15
|
errorFromMJSONWPStatusCode,
|
|
8
16
|
errorFromW3CJsonCode,
|
|
9
|
-
|
|
17
|
+
errors,
|
|
18
|
+
getResponseForW3CError,
|
|
19
|
+
isErrorType,
|
|
10
20
|
} from './errors';
|
|
21
|
+
import {ensureW3cResponse, formatResponseValue} from './helpers';
|
|
11
22
|
import {METHOD_MAP, NO_SESSION_ID_COMMANDS} from './routes';
|
|
12
|
-
import {
|
|
13
|
-
import {MAX_LOG_BODY_LENGTH, PROTOCOLS, DEFAULT_BASE_PATH} from '../constants';
|
|
14
|
-
import {isW3cCaps} from '../helpers/capabilities';
|
|
15
|
-
import {log} from '../basedriver/logger';
|
|
16
|
-
import {omitKeys} from '../utils';
|
|
17
|
-
import {generateDriverLogPrefix} from '../basedriver/helpers';
|
|
18
|
-
import type {
|
|
19
|
-
Core,
|
|
20
|
-
AppiumLogger,
|
|
21
|
-
PayloadParams,
|
|
22
|
-
MethodMap,
|
|
23
|
-
Driver,
|
|
24
|
-
DriverMethodDef,
|
|
25
|
-
} from '@appium/types';
|
|
26
|
-
import type {BaseDriver} from '../basedriver/driver';
|
|
27
|
-
import type {Request, Response, Application} from 'express';
|
|
28
|
-
import type {MultidimensionalReadonlyArray} from 'type-fest';
|
|
29
|
-
import type {RouteConfiguringFunction} from '../express/server';
|
|
23
|
+
import {validators} from './validators';
|
|
30
24
|
|
|
31
25
|
export const CREATE_SESSION_COMMAND = 'createSession';
|
|
32
26
|
export const DELETE_SESSION_COMMAND = 'deleteSession';
|
|
@@ -100,9 +94,7 @@ export function checkParams(
|
|
|
100
94
|
// we might have an array of parameters,
|
|
101
95
|
// or an array of arrays of parameters, so standardize
|
|
102
96
|
requiredParams = structuredClone(
|
|
103
|
-
(hasMultipleRequiredParamSets(paramSpec.required)
|
|
104
|
-
? paramSpec.required
|
|
105
|
-
: [paramSpec.required]) as string[][],
|
|
97
|
+
(hasMultipleRequiredParamSets(paramSpec.required) ? paramSpec.required : [paramSpec.required]) as string[][],
|
|
106
98
|
);
|
|
107
99
|
}
|
|
108
100
|
// optional parameters are just an array
|
|
@@ -151,9 +143,7 @@ export function checkParams(
|
|
|
151
143
|
if (requiredParamsSet.every((name) => actualParamNames.includes(name))) {
|
|
152
144
|
return pickKnownParams(
|
|
153
145
|
args,
|
|
154
|
-
actualParamNames.filter(
|
|
155
|
-
(name) => !requiredParamsSet.includes(name) && !optionalParams.includes(name),
|
|
156
|
-
),
|
|
146
|
+
actualParamNames.filter((name) => !requiredParamsSet.includes(name) && !optionalParams.includes(name)),
|
|
157
147
|
);
|
|
158
148
|
}
|
|
159
149
|
if (!util.isEmpty(requiredParamsSet) && util.isEmpty(matchedReqParamSet)) {
|
|
@@ -320,14 +310,9 @@ export function driverShouldDoJwpProxy(driver: Core<any>, req: Request, command:
|
|
|
320
310
|
return true;
|
|
321
311
|
}
|
|
322
312
|
|
|
323
|
-
function extractProtocol(
|
|
324
|
-
driver: Core<any>,
|
|
325
|
-
sessionId: string | null = null,
|
|
326
|
-
): keyof typeof PROTOCOLS {
|
|
313
|
+
function extractProtocol(driver: Core<any>, sessionId: string | null = null): keyof typeof PROTOCOLS {
|
|
327
314
|
const dstDriver =
|
|
328
|
-
typeof driver.driverForSession === 'function' && sessionId
|
|
329
|
-
? driver.driverForSession(sessionId)
|
|
330
|
-
: driver;
|
|
315
|
+
typeof driver.driverForSession === 'function' && sessionId ? driver.driverForSession(sessionId) : driver;
|
|
331
316
|
if (dstDriver === driver) {
|
|
332
317
|
// Shortcircuit if the driver instance is not an umbrella driver
|
|
333
318
|
// or it is Fake driver instance, where `driver.driverForSession`
|
|
@@ -359,8 +344,7 @@ function wrapParams<T>(paramSets: PayloadParams, jsonObj: T): T | Record<string,
|
|
|
359
344
|
* The wrap option in the spec enforce wrapping before validation, so that all params are wrapped at
|
|
360
345
|
* the time they are validated and later passed to the commands.
|
|
361
346
|
*/
|
|
362
|
-
return (Array.isArray(jsonObj) || typeof jsonObj !== 'object' || jsonObj === null) &&
|
|
363
|
-
paramSets.wrap
|
|
347
|
+
return (Array.isArray(jsonObj) || typeof jsonObj !== 'object' || jsonObj === null) && paramSets.wrap
|
|
364
348
|
? {[paramSets.wrap]: jsonObj}
|
|
365
349
|
: jsonObj;
|
|
366
350
|
}
|
|
@@ -432,12 +416,7 @@ function buildHandler(
|
|
|
432
416
|
// commands and generally would not want that command to be proxied instead of handled by the
|
|
433
417
|
// plugin)
|
|
434
418
|
let didPluginOverrideProxy = false;
|
|
435
|
-
if (
|
|
436
|
-
isSessCmd &&
|
|
437
|
-
!spec.neverProxy &&
|
|
438
|
-
spec.command &&
|
|
439
|
-
driverShouldDoJwpProxy(driver, req, spec.command)
|
|
440
|
-
) {
|
|
419
|
+
if (isSessCmd && !spec.neverProxy && spec.command && driverShouldDoJwpProxy(driver, req, spec.command)) {
|
|
441
420
|
if (
|
|
442
421
|
!('pluginsToHandleCmd' in driver) ||
|
|
443
422
|
typeof driver.pluginsToHandleCmd !== 'function' ||
|
|
@@ -473,9 +452,7 @@ function buildHandler(
|
|
|
473
452
|
if (spec.command === CREATE_SESSION_COMMAND) {
|
|
474
453
|
// try to determine protocol by session creation args, so we can throw a
|
|
475
454
|
// properly formatted error if arguments validation fails
|
|
476
|
-
currentProtocol = determineProtocol(
|
|
477
|
-
makeArgs(req.params, jsonObj, spec.payloadParams || {}),
|
|
478
|
-
);
|
|
455
|
+
currentProtocol = determineProtocol(makeArgs(req.params, jsonObj, spec.payloadParams || {}));
|
|
479
456
|
}
|
|
480
457
|
|
|
481
458
|
// ensure that the json payload conforms to the spec
|
|
@@ -488,9 +465,7 @@ function buildHandler(
|
|
|
488
465
|
const args = makeArgs(req.params, jsonObj, spec.payloadParams || {});
|
|
489
466
|
let driverRes: any;
|
|
490
467
|
// validate command args according to MJSONWP
|
|
491
|
-
const validator = (
|
|
492
|
-
validators as Record<string, ((...validatorArgs: any[]) => void) | undefined>
|
|
493
|
-
)[spec.command];
|
|
468
|
+
const validator = (validators as Record<string, ((...validatorArgs: any[]) => void) | undefined>)[spec.command];
|
|
494
469
|
if (validator) {
|
|
495
470
|
validator(...args);
|
|
496
471
|
}
|
|
@@ -500,9 +475,7 @@ function buildHandler(
|
|
|
500
475
|
`Calling %s.%s() with args: %s`,
|
|
501
476
|
driver.constructor.name,
|
|
502
477
|
spec.command,
|
|
503
|
-
logger.markSensitive(
|
|
504
|
-
util.truncateString(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH}),
|
|
505
|
-
),
|
|
478
|
+
logger.markSensitive(util.truncateString(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH})),
|
|
506
479
|
);
|
|
507
480
|
|
|
508
481
|
if (didPluginOverrideProxy) {
|
|
@@ -520,8 +493,7 @@ function buildHandler(
|
|
|
520
493
|
// If `executeCommand` was overridden and the method returns an object
|
|
521
494
|
// with a protocol and value/error property, re-assign the protocol
|
|
522
495
|
if (util.isPlainObject(driverRes) && Object.hasOwn(driverRes, 'protocol')) {
|
|
523
|
-
currentProtocol =
|
|
524
|
-
(driverRes as {protocol?: keyof typeof PROTOCOLS}).protocol || currentProtocol;
|
|
496
|
+
currentProtocol = (driverRes as {protocol?: keyof typeof PROTOCOLS}).protocol || currentProtocol;
|
|
525
497
|
if (driverRes.error) {
|
|
526
498
|
throw driverRes.error;
|
|
527
499
|
}
|
|
@@ -558,30 +530,19 @@ function buildHandler(
|
|
|
558
530
|
|
|
559
531
|
// if the status is not 0, throw the appropriate error for status code.
|
|
560
532
|
if (util.hasValue(driverRes)) {
|
|
561
|
-
if (
|
|
562
|
-
util.hasValue(driverRes.status) &&
|
|
563
|
-
!isNaN(driverRes.status) &&
|
|
564
|
-
parseInt(driverRes.status, 10) !== 0
|
|
565
|
-
) {
|
|
533
|
+
if (util.hasValue(driverRes.status) && !isNaN(driverRes.status) && parseInt(driverRes.status, 10) !== 0) {
|
|
566
534
|
throw errorFromMJSONWPStatusCode(driverRes.status, driverRes.value);
|
|
567
535
|
} else if (util.isPlainObject(driverRes.value) && driverRes.value.error) {
|
|
568
|
-
throw errorFromW3CJsonCode(
|
|
569
|
-
driverRes.value.error,
|
|
570
|
-
driverRes.value.message,
|
|
571
|
-
driverRes.value.stacktrace,
|
|
572
|
-
);
|
|
536
|
+
throw errorFromW3CJsonCode(driverRes.value.error, driverRes.value.message, driverRes.value.stacktrace);
|
|
573
537
|
}
|
|
574
538
|
}
|
|
575
539
|
|
|
576
540
|
httpResBody.value = driverRes;
|
|
577
541
|
getLogger(driver, sessionId || newSessionId).debug(
|
|
578
542
|
`Responding ` +
|
|
579
|
-
`to client with driver.${spec.command}() result: ${util.truncateString(
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
length: MAX_LOG_BODY_LENGTH,
|
|
583
|
-
},
|
|
584
|
-
)}`,
|
|
543
|
+
`to client with driver.${spec.command}() result: ${util.truncateString(JSON.stringify(driverRes), {
|
|
544
|
+
length: MAX_LOG_BODY_LENGTH,
|
|
545
|
+
})}`,
|
|
585
546
|
);
|
|
586
547
|
} catch (err) {
|
|
587
548
|
// if anything goes wrong, figure out what our response should be
|
|
@@ -616,9 +577,7 @@ function buildHandler(
|
|
|
616
577
|
if (isErrorType(err, errors.ProxyRequestError)) {
|
|
617
578
|
actualErr = err.getActualError();
|
|
618
579
|
} else {
|
|
619
|
-
getLogger(driver, sessionId || newSessionId).debug(
|
|
620
|
-
`Encountered internal error running command: ${errMsg}`,
|
|
621
|
-
);
|
|
580
|
+
getLogger(driver, sessionId || newSessionId).debug(`Encountered internal error running command: ${errMsg}`);
|
|
622
581
|
}
|
|
623
582
|
|
|
624
583
|
[httpStatus, httpResBody] = getResponseForW3CError(actualErr);
|
|
@@ -626,10 +585,7 @@ function buildHandler(
|
|
|
626
585
|
|
|
627
586
|
// decode the response, which is either a string or json
|
|
628
587
|
if (typeof httpResBody === 'string') {
|
|
629
|
-
res
|
|
630
|
-
.status(httpStatus)
|
|
631
|
-
.setHeader('content-type', 'application/json; charset=utf-8')
|
|
632
|
-
.send(httpResBody);
|
|
588
|
+
res.status(httpStatus).setHeader('content-type', 'application/json; charset=utf-8').send(httpResBody);
|
|
633
589
|
} else {
|
|
634
590
|
if (newSessionId && currentProtocol === PROTOCOLS.W3C) {
|
|
635
591
|
httpResBody.value.sessionId = newSessionId;
|
|
@@ -638,9 +594,9 @@ function buildHandler(
|
|
|
638
594
|
}
|
|
639
595
|
};
|
|
640
596
|
// add the method to the app
|
|
641
|
-
const registerRoute = (
|
|
642
|
-
|
|
643
|
-
|
|
597
|
+
const registerRoute = (app as Application & Record<string, (routePath: string, ...handlers: any[]) => void>)[
|
|
598
|
+
method.toLowerCase()
|
|
599
|
+
].bind(app);
|
|
644
600
|
registerRoute(path, (req: Request, res: Response) => {
|
|
645
601
|
void asyncHandler(req, res);
|
|
646
602
|
});
|
package/lib/protocol/routes.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {Driver, DriverMethodDef, HTTPMethod, MethodMap} from '@appium/types';
|
|
2
1
|
import {util} from '@appium/support';
|
|
3
|
-
import {
|
|
4
|
-
import {match} from 'path-to-regexp';
|
|
2
|
+
import type {Driver, DriverMethodDef, HTTPMethod, MethodMap} from '@appium/types';
|
|
5
3
|
import {LRUCache} from 'lru-cache';
|
|
4
|
+
import {match} from 'path-to-regexp';
|
|
5
|
+
|
|
6
|
+
import {DEFAULT_BASE_PATH} from '../constants';
|
|
6
7
|
|
|
7
8
|
const COMMAND_NAMES_CACHE = new LRUCache<string, string>({
|
|
8
9
|
max: 1024,
|
|
@@ -234,15 +235,7 @@ export const METHOD_MAP = {
|
|
|
234
235
|
POST: {
|
|
235
236
|
command: 'printPage',
|
|
236
237
|
payloadParams: {
|
|
237
|
-
optional: [
|
|
238
|
-
'orientation',
|
|
239
|
-
'scale',
|
|
240
|
-
'background',
|
|
241
|
-
'page',
|
|
242
|
-
'margin',
|
|
243
|
-
'shrinkToFit',
|
|
244
|
-
'pageRanges',
|
|
245
|
-
],
|
|
238
|
+
optional: ['orientation', 'scale', 'background', 'page', 'margin', 'shrinkToFit', 'pageRanges'],
|
|
246
239
|
},
|
|
247
240
|
},
|
|
248
241
|
},
|
|
@@ -470,7 +463,7 @@ export const METHOD_MAP = {
|
|
|
470
463
|
},
|
|
471
464
|
},
|
|
472
465
|
},
|
|
473
|
-
'/session/:sessionId/
|
|
466
|
+
'/session/:sessionId/sensor/:sensorType': {
|
|
474
467
|
GET: {command: 'getVirtualSensorInfo'},
|
|
475
468
|
POST: {command: 'updateVirtualSensorReading', payloadParams: {required: ['reading']}},
|
|
476
469
|
DELETE: {command: 'deleteVirtualSensor'},
|
|
@@ -588,11 +581,7 @@ export const ALL_COMMANDS = Object.values(METHOD_MAP)
|
|
|
588
581
|
* @param method - HTTP method (used when one path maps to multiple commands)
|
|
589
582
|
* @param basePath - Optional base path prefix to strip before matching
|
|
590
583
|
*/
|
|
591
|
-
export function routeToCommandName(
|
|
592
|
-
endpoint: string,
|
|
593
|
-
method?: HTTPMethod,
|
|
594
|
-
basePath?: string,
|
|
595
|
-
): string | undefined {
|
|
584
|
+
export function routeToCommandName(endpoint: string, method?: HTTPMethod, basePath?: string): string | undefined {
|
|
596
585
|
const resolvedBasePath = basePath ?? DEFAULT_BASE_PATH;
|
|
597
586
|
let normalizedEndpoint = resolvedBasePath
|
|
598
587
|
? endpoint.replace(new RegExp(`^${util.escapeRegExp(resolvedBasePath)}`), '')
|
|
@@ -624,9 +613,7 @@ export function routeToCommandName(
|
|
|
624
613
|
if (possiblePathnames.some((pp) => routeMatcher(pp))) {
|
|
625
614
|
const spec = routeSpec as Record<string, DriverMethodDef<Driver>>;
|
|
626
615
|
const commandForAnyMethod = () => Object.keys(spec).map((key) => spec[key]?.command)[0];
|
|
627
|
-
const commandName = normalizedMethod
|
|
628
|
-
? spec[normalizedMethod]?.command
|
|
629
|
-
: commandForAnyMethod();
|
|
616
|
+
const commandName = normalizedMethod ? spec[normalizedMethod]?.command : commandForAnyMethod();
|
|
630
617
|
if (commandName) {
|
|
631
618
|
COMMAND_NAMES_CACHE.set(cacheKey, commandName);
|
|
632
619
|
return commandName;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import {fs} from '@appium/support';
|
|
4
4
|
import {sleep} from 'asyncbox';
|
|
5
5
|
import type {Request, Response} from 'express';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
import {log} from '../express/logger';
|
|
7
8
|
import {TEST_FIXTURES_DIR} from './static-dir';
|
|
9
|
+
import {compileLodashTemplate} from './template';
|
|
8
10
|
|
|
9
11
|
type TemplateParams = Record<string, unknown>;
|
|
10
12
|
|
package/lib/test-pages/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
|
|
2
3
|
import express from 'express';
|
|
3
4
|
import type {Express} from 'express';
|
|
4
5
|
import favicon from 'serve-favicon';
|
|
5
|
-
|
|
6
|
-
import {
|
|
6
|
+
|
|
7
|
+
import {produceCrash, produceError} from './crash';
|
|
8
|
+
import {guineaPig, guineaPigAppBanner, guineaPigScrollable, welcome} from './handlers';
|
|
7
9
|
import {TEST_FIXTURES_DIR} from './static-dir';
|
|
8
10
|
|
|
9
11
|
export interface RegisterTestPagesOpts {
|
|
@@ -30,5 +32,5 @@ export function registerTestPages(app: Express, {basePath}: RegisterTestPagesOpt
|
|
|
30
32
|
app.all('/test/guinea-pig-app-banner', guineaPigAppBanner);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export {TEST_FIXTURES_DIR} from './static-dir';
|
|
34
35
|
export {isLegacyTestPagesEnabled} from './env';
|
|
36
|
+
export {TEST_FIXTURES_DIR} from './static-dir';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
|
+
import {node} from '@appium/support';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Absolute path to bundled legacy test fixture static files.
|
|
5
7
|
*
|
|
@@ -9,11 +11,9 @@ import path from 'node:path';
|
|
|
9
11
|
export const TEST_FIXTURES_DIR = resolveTestFixturesDir();
|
|
10
12
|
|
|
11
13
|
function resolveTestFixturesDir(): string {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (baseDriverIndex < 0) {
|
|
16
|
-
throw new Error(`Could not find the module root folder in the path: ${fromDir}`);
|
|
14
|
+
const packageRoot = node.getModuleRootSync('@appium/base-driver', __filename);
|
|
15
|
+
if (!packageRoot) {
|
|
16
|
+
throw new Error(`Could not find the module root folder for @appium/base-driver from ${__filename}`);
|
|
17
17
|
}
|
|
18
|
-
return path.join(
|
|
18
|
+
return path.join(packageRoot, 'test-fixtures', 'static');
|
|
19
19
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/** Compile a lodash-style template string (`<%= expression %>`) into a render function. */
|
|
2
|
-
export function compileLodashTemplate(
|
|
3
|
-
template: string,
|
|
4
|
-
): (params: Record<string, unknown>) => string {
|
|
2
|
+
export function compileLodashTemplate(template: string): (params: Record<string, unknown>) => string {
|
|
5
3
|
const parts: string[] = [];
|
|
6
4
|
let lastIndex = 0;
|
|
7
5
|
const re = /<%=\s*([\s\S]+?)\s*%>/g;
|
package/lib/utils.ts
CHANGED
|
@@ -46,10 +46,7 @@ export function omitKeys<T extends Record<string, unknown>>(obj: T, keys: readon
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** Return a shallow copy of `obj` containing only listed keys. */
|
|
49
|
-
export function pick<T extends Record<string, unknown>>(
|
|
50
|
-
obj: T,
|
|
51
|
-
keys: readonly string[],
|
|
52
|
-
): Partial<T> {
|
|
49
|
+
export function pick<T extends Record<string, unknown>>(obj: T, keys: readonly string[]): Partial<T> {
|
|
53
50
|
const keysToPick = new Set(keys);
|
|
54
51
|
return Object.fromEntries(Object.entries(obj).filter(([k]) => keysToPick.has(k))) as Partial<T>;
|
|
55
52
|
}
|
package/package.json
CHANGED
|
@@ -1,78 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-driver",
|
|
3
|
-
"version": "10.7.
|
|
3
|
+
"version": "10.7.2",
|
|
4
|
+
"gitHead": "f7b20335eab4022e5cbbb627ec86866a994444f8",
|
|
4
5
|
"description": "Base driver class for Appium drivers",
|
|
5
6
|
"keywords": [
|
|
7
|
+
"android",
|
|
6
8
|
"automation",
|
|
9
|
+
"firefoxos",
|
|
10
|
+
"ios",
|
|
7
11
|
"javascript",
|
|
8
12
|
"selenium",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"android",
|
|
12
|
-
"firefoxos",
|
|
13
|
-
"testing"
|
|
13
|
+
"testing",
|
|
14
|
+
"webdriver"
|
|
14
15
|
],
|
|
15
16
|
"homepage": "https://appium.io",
|
|
16
17
|
"bugs": {
|
|
17
18
|
"url": "https://github.com/appium/appium/issues"
|
|
18
19
|
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"author": "https://github.com/appium",
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
|
21
24
|
"url": "https://github.com/appium/appium.git",
|
|
22
25
|
"directory": "packages/base-driver"
|
|
23
26
|
},
|
|
24
|
-
"license": "Apache-2.0",
|
|
25
|
-
"author": "https://github.com/appium",
|
|
26
|
-
"types": "./build/lib/index.d.ts",
|
|
27
27
|
"directories": {
|
|
28
28
|
"lib": "lib"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
"index.js",
|
|
32
|
-
"index.d.ts",
|
|
33
31
|
"lib",
|
|
32
|
+
"build/lib",
|
|
34
33
|
"test-fixtures",
|
|
35
|
-
"
|
|
36
|
-
"tsconfig.json",
|
|
37
|
-
"!build/tsconfig.tsbuildinfo",
|
|
38
|
-
"!build/test"
|
|
34
|
+
"tsconfig.json"
|
|
39
35
|
],
|
|
36
|
+
"main": "./build/lib/index.js",
|
|
37
|
+
"types": "./build/lib/index.d.ts",
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"test": "run-p test:unit test:types",
|
|
42
|
-
"test:e2e": "
|
|
43
|
-
"test:smoke": "node ./index.js",
|
|
44
|
-
"test:unit": "
|
|
43
|
+
"test:e2e": "node --test --enable-source-maps --test-force-exit --test-concurrency=1 --test-timeout=20000 \"./build/test/e2e/**/*.spec.js\"",
|
|
44
|
+
"test:smoke": "node ./build/lib/index.js",
|
|
45
|
+
"test:unit": "node --test --enable-source-maps --test-timeout=10000 \"./build/test/unit/**/*.spec.js\"",
|
|
45
46
|
"test:types": "tsd"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@appium/support": "7.2.
|
|
49
|
-
"@appium/types": "1.
|
|
49
|
+
"@appium/support": "7.2.6",
|
|
50
|
+
"@appium/types": "1.6.0",
|
|
50
51
|
"async-lock": "1.4.1",
|
|
51
|
-
"asyncbox": "6.3.
|
|
52
|
-
"axios": "1.18.
|
|
53
|
-
"body-parser": "2.
|
|
52
|
+
"asyncbox": "6.3.5",
|
|
53
|
+
"axios": "1.18.1",
|
|
54
|
+
"body-parser": "2.3.0",
|
|
54
55
|
"express": "5.2.1",
|
|
55
56
|
"fastest-levenshtein": "1.0.16",
|
|
56
57
|
"http-status-codes": "2.3.0",
|
|
57
|
-
"lru-cache": "11.5.
|
|
58
|
+
"lru-cache": "11.5.2",
|
|
58
59
|
"method-override": "3.0.0",
|
|
59
60
|
"morgan": "1.11.0",
|
|
60
61
|
"path-to-regexp": "8.4.2",
|
|
61
62
|
"serve-favicon": "2.5.1",
|
|
62
|
-
"type-fest": "5.
|
|
63
|
+
"type-fest": "5.8.0"
|
|
63
64
|
},
|
|
64
65
|
"optionalDependencies": {
|
|
65
66
|
"spdy": "4.0.2"
|
|
66
67
|
},
|
|
68
|
+
"tsd": {
|
|
69
|
+
"directory": "test/types"
|
|
70
|
+
},
|
|
67
71
|
"engines": {
|
|
68
72
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0",
|
|
69
73
|
"npm": ">=10"
|
|
70
|
-
},
|
|
71
|
-
"publishConfig": {
|
|
72
|
-
"access": "public"
|
|
73
|
-
},
|
|
74
|
-
"gitHead": "e6b583a2094f7919ef27b0dc28ebf42b3184852b",
|
|
75
|
-
"tsd": {
|
|
76
|
-
"directory": "test/types"
|
|
77
74
|
}
|
|
78
75
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@appium/tsconfig/tsconfig.json",
|
|
3
|
-
"ts-node": {
|
|
4
|
-
"transpileOnly": true,
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"rootDir": "."
|
|
7
|
-
}
|
|
8
|
-
},
|
|
9
3
|
"compilerOptions": {
|
|
10
4
|
"strict": true,
|
|
5
|
+
"rootDir": ".",
|
|
11
6
|
"outDir": "build",
|
|
12
7
|
"paths": {
|
|
13
8
|
"@appium/support": ["../support"],
|
|
@@ -15,9 +10,19 @@
|
|
|
15
10
|
"@appium/driver-test-support": ["../driver-test-support"]
|
|
16
11
|
},
|
|
17
12
|
"checkJs": true,
|
|
18
|
-
"types": ["node"
|
|
13
|
+
"types": ["node"]
|
|
19
14
|
},
|
|
20
|
-
"include": ["lib"],
|
|
15
|
+
"include": ["lib", "test"],
|
|
21
16
|
"exclude": ["build"],
|
|
22
|
-
"references": [
|
|
17
|
+
"references": [
|
|
18
|
+
{
|
|
19
|
+
"path": "../support"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"path": "../types"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"path": "../driver-test-support"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
23
28
|
}
|