@appium/base-driver 10.5.2 → 10.7.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.d.ts +1 -1
- package/build/lib/basedriver/capabilities.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +58 -50
- 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 +10 -14
- 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 +4 -7
- package/build/lib/basedriver/commands/event.js.map +1 -1
- package/build/lib/basedriver/commands/execute.js +3 -6
- 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 +2 -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 -5
- package/build/lib/basedriver/commands/log.js.map +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +9 -13
- package/build/lib/basedriver/commands/timeout.js.map +1 -1
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +17 -14
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js +3 -7
- package/build/lib/basedriver/device-settings.js.map +1 -1
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +34 -38
- package/build/lib/basedriver/driver.js.map +1 -1
- package/build/lib/basedriver/extension-core.d.ts +4 -1
- package/build/lib/basedriver/extension-core.d.ts.map +1 -1
- package/build/lib/basedriver/extension-core.js +37 -13
- 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 +47 -33
- package/build/lib/basedriver/helpers.js.map +1 -1
- package/build/lib/basedriver/ipc.d.ts +36 -0
- package/build/lib/basedriver/ipc.d.ts.map +1 -0
- package/build/lib/basedriver/ipc.js +157 -0
- package/build/lib/basedriver/ipc.js.map +1 -0
- package/build/lib/basedriver/validation.d.ts.map +1 -1
- package/build/lib/basedriver/validation.js +27 -29
- package/build/lib/basedriver/validation.js.map +1 -1
- package/build/lib/express/express-logging.d.ts +0 -1
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +11 -11
- package/build/lib/express/express-logging.js.map +1 -1
- package/build/lib/express/idempotency.js +3 -6
- package/build/lib/express/idempotency.js.map +1 -1
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +6 -10
- package/build/lib/express/middleware.js.map +1 -1
- package/build/lib/express/server.d.ts +1 -1
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +82 -73
- 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 +6 -9
- package/build/lib/express/websocket.js.map +1 -1
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js +14 -17
- package/build/lib/helpers/capabilities.js.map +1 -1
- package/build/lib/helpers/extension-command-name.js +2 -5
- 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 +6 -7
- package/build/lib/helpers/levenshtein-match.js.map +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +6 -16
- 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 +21 -18
- package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy-request.d.ts +2 -2
- package/build/lib/jsonwp-proxy/proxy-request.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy-request.js +25 -21
- package/build/lib/jsonwp-proxy/proxy-request.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +45 -36
- package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +33 -37
- 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 +9 -8
- package/build/lib/protocol/helpers.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 +73 -61
- 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 +16 -17
- package/build/lib/protocol/routes.js.map +1 -1
- package/build/lib/protocol/validators.d.ts.map +1 -1
- package/build/lib/protocol/validators.js +1 -5
- package/build/lib/protocol/validators.js.map +1 -1
- package/build/lib/test-pages/crash.d.ts.map +1 -0
- package/build/lib/test-pages/crash.js.map +1 -0
- package/build/lib/test-pages/env.d.ts +5 -0
- package/build/lib/test-pages/env.d.ts.map +1 -0
- package/build/lib/test-pages/env.js +12 -0
- package/build/lib/test-pages/env.js.map +1 -0
- package/build/lib/{express/static.d.ts → test-pages/handlers.d.ts} +1 -2
- package/build/lib/test-pages/handlers.d.ts.map +1 -0
- package/build/lib/{express/static.js → test-pages/handlers.js} +9 -12
- package/build/lib/test-pages/handlers.js.map +1 -0
- package/build/lib/test-pages/index.d.ts +6 -0
- package/build/lib/test-pages/index.d.ts.map +1 -0
- package/build/lib/test-pages/index.js +35 -0
- package/build/lib/test-pages/index.js.map +1 -0
- package/build/lib/test-pages/static-dir.d.ts +8 -0
- package/build/lib/test-pages/static-dir.d.ts.map +1 -0
- package/build/lib/test-pages/static-dir.js +24 -0
- package/build/lib/test-pages/static-dir.js.map +1 -0
- package/build/lib/test-pages/template.d.ts +3 -0
- package/build/lib/test-pages/template.d.ts.map +1 -0
- package/build/lib/test-pages/template.js +19 -0
- package/build/lib/test-pages/template.js.map +1 -0
- package/build/lib/utils.d.ts +14 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +55 -0
- package/build/lib/utils.js.map +1 -0
- package/lib/basedriver/capabilities.ts +126 -115
- package/lib/basedriver/commands/bidi.ts +11 -11
- package/lib/basedriver/commands/event.ts +17 -11
- package/lib/basedriver/commands/execute.ts +15 -12
- package/lib/basedriver/commands/find.ts +20 -12
- package/lib/basedriver/commands/log.ts +4 -3
- package/lib/basedriver/commands/timeout.ts +22 -14
- package/lib/basedriver/core.ts +26 -26
- package/lib/basedriver/device-settings.ts +7 -12
- package/lib/basedriver/driver.ts +62 -50
- package/lib/basedriver/extension-core.ts +60 -18
- package/lib/basedriver/helpers.ts +81 -52
- package/lib/basedriver/ipc.ts +198 -0
- package/lib/basedriver/validation.ts +37 -30
- package/lib/express/express-logging.ts +16 -20
- package/lib/express/idempotency.ts +9 -9
- package/lib/express/middleware.ts +14 -18
- package/lib/express/server.ts +118 -120
- package/lib/express/websocket.ts +11 -15
- package/lib/helpers/capabilities.ts +21 -16
- package/lib/helpers/extension-command-name.ts +3 -3
- package/lib/helpers/levenshtein-match.ts +20 -14
- package/lib/index.js +3 -12
- package/lib/jsonwp-proxy/protocol-converter.ts +58 -35
- package/lib/jsonwp-proxy/proxy-request.ts +26 -26
- package/lib/jsonwp-proxy/proxy.ts +74 -75
- package/lib/protocol/errors.ts +69 -88
- package/lib/protocol/helpers.ts +9 -5
- package/lib/protocol/protocol.ts +149 -107
- package/lib/protocol/routes.ts +17 -17
- package/lib/protocol/validators.ts +1 -3
- package/lib/test-pages/env.ts +9 -0
- package/lib/{express/static.ts → test-pages/handlers.ts} +10 -22
- package/lib/test-pages/index.ts +34 -0
- package/lib/test-pages/static-dir.ts +19 -0
- package/lib/test-pages/template.ts +17 -0
- package/lib/utils.ts +65 -0
- package/package.json +10 -13
- package/tsconfig.json +1 -0
- package/build/lib/express/crash.d.ts.map +0 -1
- package/build/lib/express/crash.js.map +0 -1
- package/build/lib/express/static.d.ts.map +0 -1
- package/build/lib/express/static.js.map +0 -1
- /package/build/lib/{express → test-pages}/crash.d.ts +0 -0
- /package/build/lib/{express → test-pages}/crash.js +0 -0
- /package/lib/{express → test-pages}/crash.ts +0 -0
- /package/{static → test-fixtures/static}/appium.png +0 -0
- /package/{static → test-fixtures/static}/favicon.ico +0 -0
- /package/{static → test-fixtures/static}/js/jquery.min.js +0 -0
- /package/{static → test-fixtures/static}/test/frameset.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig-app-banner.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig-scrollable.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig2.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig3.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig4.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig5.html +0 -0
- /package/{static → test-fixtures/static}/test/iframes.html +0 -0
- /package/{static → test-fixtures/static}/test/shadow-dom.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe1.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe2.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe3.html +0 -0
- /package/{static → test-fixtures/static}/test/touch.html +0 -0
- /package/{static → test-fixtures/static}/test/welcome.html +0 -0
|
@@ -5,7 +5,6 @@ import type {BaseDriver} from '../driver';
|
|
|
5
5
|
import {mixin} from './mixin';
|
|
6
6
|
|
|
7
7
|
declare module '../driver' {
|
|
8
|
-
|
|
9
8
|
interface BaseDriver<C extends Constraints> extends IFindCommands {}
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -14,21 +13,21 @@ async function findElOrEls<C extends Constraints>(
|
|
|
14
13
|
strategy: string,
|
|
15
14
|
selector: string,
|
|
16
15
|
mult: true,
|
|
17
|
-
context?: any
|
|
16
|
+
context?: any,
|
|
18
17
|
): Promise<Element[]>;
|
|
19
18
|
async function findElOrEls<C extends Constraints>(
|
|
20
19
|
this: BaseDriver<C>,
|
|
21
20
|
strategy: string,
|
|
22
21
|
selector: string,
|
|
23
22
|
mult: false,
|
|
24
|
-
context?: any
|
|
23
|
+
context?: any,
|
|
25
24
|
): Promise<Element>;
|
|
26
25
|
async function findElOrEls<C extends Constraints>(
|
|
27
26
|
this: BaseDriver<C>,
|
|
28
27
|
strategy: string,
|
|
29
28
|
selector: string,
|
|
30
29
|
mult: boolean,
|
|
31
|
-
context?: any
|
|
30
|
+
context?: any,
|
|
32
31
|
): Promise<Element[] | Element> {
|
|
33
32
|
throw new errors.NotImplementedError('Not implemented yet for find.');
|
|
34
33
|
}
|
|
@@ -38,21 +37,21 @@ async function findElOrElsWithProcessing<C extends Constraints>(
|
|
|
38
37
|
strategy: string,
|
|
39
38
|
selector: string,
|
|
40
39
|
mult: true,
|
|
41
|
-
context?: any
|
|
40
|
+
context?: any,
|
|
42
41
|
): Promise<Element[]>;
|
|
43
42
|
async function findElOrElsWithProcessing<C extends Constraints>(
|
|
44
43
|
this: BaseDriver<C>,
|
|
45
44
|
strategy: string,
|
|
46
45
|
selector: string,
|
|
47
46
|
mult: false,
|
|
48
|
-
context?: any
|
|
47
|
+
context?: any,
|
|
49
48
|
): Promise<Element>;
|
|
50
49
|
async function findElOrElsWithProcessing<C extends Constraints>(
|
|
51
50
|
this: BaseDriver<C>,
|
|
52
51
|
strategy: string,
|
|
53
52
|
selector: string,
|
|
54
53
|
mult: boolean,
|
|
55
|
-
context?: any
|
|
54
|
+
context?: any,
|
|
56
55
|
): Promise<Element[] | Element> {
|
|
57
56
|
this.validateLocatorStrategy(strategy);
|
|
58
57
|
try {
|
|
@@ -61,7 +60,8 @@ async function findElOrElsWithProcessing<C extends Constraints>(
|
|
|
61
60
|
} catch (err) {
|
|
62
61
|
if (this.opts.printPageSourceOnFindFailure) {
|
|
63
62
|
const src = await this.getPageSource();
|
|
64
|
-
|
|
63
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
64
|
+
this.log.debug(`Error finding element${mult ? 's' : ''}: ${message}`);
|
|
65
65
|
this.log.debug(`Page source requested through 'printPageSourceOnFindFailure':`);
|
|
66
66
|
this.log.debug(src);
|
|
67
67
|
}
|
|
@@ -71,11 +71,19 @@ async function findElOrElsWithProcessing<C extends Constraints>(
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
const FindCommands: IFindCommands = {
|
|
74
|
-
async findElement<C extends Constraints>(
|
|
74
|
+
async findElement<C extends Constraints>(
|
|
75
|
+
this: BaseDriver<C>,
|
|
76
|
+
strategy: string,
|
|
77
|
+
selector: string,
|
|
78
|
+
) {
|
|
75
79
|
return await this.findElOrElsWithProcessing(strategy, selector, false);
|
|
76
80
|
},
|
|
77
81
|
|
|
78
|
-
async findElements<C extends Constraints>(
|
|
82
|
+
async findElements<C extends Constraints>(
|
|
83
|
+
this: BaseDriver<C>,
|
|
84
|
+
strategy: string,
|
|
85
|
+
selector: string,
|
|
86
|
+
) {
|
|
79
87
|
return await this.findElOrElsWithProcessing(strategy, selector, true);
|
|
80
88
|
},
|
|
81
89
|
|
|
@@ -83,7 +91,7 @@ const FindCommands: IFindCommands = {
|
|
|
83
91
|
this: BaseDriver<C>,
|
|
84
92
|
strategy: string,
|
|
85
93
|
selector: string,
|
|
86
|
-
elementId: string
|
|
94
|
+
elementId: string,
|
|
87
95
|
) {
|
|
88
96
|
return await this.findElOrElsWithProcessing(strategy, selector, false, elementId);
|
|
89
97
|
},
|
|
@@ -92,7 +100,7 @@ const FindCommands: IFindCommands = {
|
|
|
92
100
|
this: BaseDriver<C>,
|
|
93
101
|
strategy: string,
|
|
94
102
|
selector: string,
|
|
95
|
-
elementId: string
|
|
103
|
+
elementId: string,
|
|
96
104
|
) {
|
|
97
105
|
return await this.findElOrElsWithProcessing(strategy, selector, true, elementId);
|
|
98
106
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {Constraints, Driver, ILogCommands} from '@appium/types';
|
|
2
|
-
import _ from 'lodash';
|
|
3
2
|
import type {BaseDriver} from '../driver';
|
|
4
3
|
import {mixin} from './mixin';
|
|
5
4
|
|
|
@@ -20,10 +19,12 @@ const LogCommands: ILogCommands = {
|
|
|
20
19
|
this.log.debug(`Retrieving '${String(logType)}' logs`);
|
|
21
20
|
|
|
22
21
|
if (!(logType in this.supportedLogTypes)) {
|
|
23
|
-
const logsTypesWithDescriptions =
|
|
22
|
+
const logsTypesWithDescriptions = Object.fromEntries(
|
|
23
|
+
Object.entries(this.supportedLogTypes).map(([key, value]) => [key, value.description]),
|
|
24
|
+
);
|
|
24
25
|
throw new Error(
|
|
25
26
|
`Unsupported log type '${String(logType)}'. ` +
|
|
26
|
-
`Supported types: ${JSON.stringify(logsTypesWithDescriptions)}
|
|
27
|
+
`Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`,
|
|
27
28
|
);
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {waitForCondition} from 'asyncbox';
|
|
2
|
-
import _ from 'lodash';
|
|
3
2
|
import {util} from '@appium/support';
|
|
4
3
|
import {errors} from '../../protocol';
|
|
5
4
|
import type {BaseDriver} from '../driver';
|
|
@@ -14,27 +13,36 @@ declare module '../driver' {
|
|
|
14
13
|
const MIN_TIMEOUT = 0;
|
|
15
14
|
|
|
16
15
|
const TimeoutCommands: ITimeoutCommands = {
|
|
17
|
-
async timeouts<C extends Constraints>(
|
|
18
|
-
|
|
16
|
+
async timeouts<C extends Constraints>(
|
|
17
|
+
this: BaseDriver<C>,
|
|
18
|
+
type?: string,
|
|
19
|
+
ms?: number | string,
|
|
20
|
+
script?: number,
|
|
21
|
+
pageLoad?: number,
|
|
22
|
+
implicit?: number,
|
|
23
|
+
) {
|
|
24
|
+
if (type && typeof type === 'string' && util.hasValue(ms)) {
|
|
19
25
|
// legacy stuff with some Appium-specific additions
|
|
20
26
|
this.log.debug(`Timeout arguments: ${JSON.stringify({type, ms})}}`);
|
|
21
27
|
switch (type) {
|
|
22
28
|
case 'command':
|
|
23
|
-
return void (await this.newCommandTimeout(ms));
|
|
29
|
+
return void (await this.newCommandTimeout(this.parseTimeoutArgument(ms)));
|
|
24
30
|
case 'implicit':
|
|
25
|
-
return void (await this.implicitWaitW3C(ms));
|
|
31
|
+
return void (await this.implicitWaitW3C(this.parseTimeoutArgument(ms)));
|
|
26
32
|
case 'page load':
|
|
27
|
-
return void (await this.pageLoadTimeoutW3C(ms));
|
|
33
|
+
return void (await this.pageLoadTimeoutW3C(this.parseTimeoutArgument(ms)));
|
|
28
34
|
case 'script':
|
|
29
|
-
return void (await this.scriptTimeoutW3C(ms));
|
|
35
|
+
return void (await this.scriptTimeoutW3C(this.parseTimeoutArgument(ms)));
|
|
30
36
|
default:
|
|
31
37
|
throw new Error(`'${type}' type is not supported for the timeout API`);
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
this.log.debug(`W3C timeout argument: ${JSON.stringify({script, pageLoad, implicit})}}`);
|
|
36
|
-
if ([script, pageLoad, implicit].every(
|
|
37
|
-
throw new errors.InvalidArgumentError(
|
|
42
|
+
if ([script, pageLoad, implicit].every((value) => value == null)) {
|
|
43
|
+
throw new errors.InvalidArgumentError(
|
|
44
|
+
'W3C protocol expects any of script, pageLoad or implicit to be set',
|
|
45
|
+
);
|
|
38
46
|
}
|
|
39
47
|
if (util.hasValue(script)) {
|
|
40
48
|
await this.scriptTimeoutW3C(script);
|
|
@@ -47,7 +55,7 @@ const TimeoutCommands: ITimeoutCommands = {
|
|
|
47
55
|
}
|
|
48
56
|
},
|
|
49
57
|
|
|
50
|
-
async getTimeouts() {
|
|
58
|
+
async getTimeouts<C extends Constraints>(this: BaseDriver<C>) {
|
|
51
59
|
return {
|
|
52
60
|
command: this.newCommandTimeoutMs,
|
|
53
61
|
implicit: this.implicitWaitMs,
|
|
@@ -82,7 +90,7 @@ const TimeoutCommands: ITimeoutCommands = {
|
|
|
82
90
|
if (this.managedDrivers?.length) {
|
|
83
91
|
this.log.debug('Setting implicit wait on managed drivers');
|
|
84
92
|
for (const driver of this.managedDrivers) {
|
|
85
|
-
if (
|
|
93
|
+
if (typeof driver.setImplicitWait === 'function') {
|
|
86
94
|
driver.setImplicitWait(ms);
|
|
87
95
|
}
|
|
88
96
|
}
|
|
@@ -95,7 +103,7 @@ const TimeoutCommands: ITimeoutCommands = {
|
|
|
95
103
|
if (this.managedDrivers?.length) {
|
|
96
104
|
this.log.debug('Setting new command timeout on managed drivers');
|
|
97
105
|
for (const driver of this.managedDrivers) {
|
|
98
|
-
if (
|
|
106
|
+
if (typeof driver.setNewCommandTimeout === 'function') {
|
|
99
107
|
driver.setNewCommandTimeout(ms);
|
|
100
108
|
}
|
|
101
109
|
}
|
|
@@ -104,7 +112,7 @@ const TimeoutCommands: ITimeoutCommands = {
|
|
|
104
112
|
|
|
105
113
|
async implicitWaitForCondition<C extends Constraints>(
|
|
106
114
|
this: BaseDriver<C>,
|
|
107
|
-
condFn: (...args: any[]) => Promise<any
|
|
115
|
+
condFn: (...args: any[]) => Promise<any>,
|
|
108
116
|
) {
|
|
109
117
|
this.log.debug(`Waiting up to ${this.implicitWaitMs} ms for condition`);
|
|
110
118
|
const wrappedCondFn = async (...args: any[]) => {
|
|
@@ -122,7 +130,7 @@ const TimeoutCommands: ITimeoutCommands = {
|
|
|
122
130
|
|
|
123
131
|
parseTimeoutArgument<C extends Constraints>(this: BaseDriver<C>, ms: number | string) {
|
|
124
132
|
const duration = parseInt(String(ms), 10);
|
|
125
|
-
if (
|
|
133
|
+
if (Number.isNaN(duration) || duration < MIN_TIMEOUT) {
|
|
126
134
|
throw new errors.UnknownError(`Invalid timeout value '${ms}'`);
|
|
127
135
|
}
|
|
128
136
|
return duration;
|
package/lib/basedriver/core.ts
CHANGED
|
@@ -12,12 +12,9 @@ import type {
|
|
|
12
12
|
StringRecord,
|
|
13
13
|
} from '@appium/types';
|
|
14
14
|
import AsyncLock from 'async-lock';
|
|
15
|
-
import
|
|
15
|
+
import {util} from '@appium/support';
|
|
16
16
|
import os from 'node:os';
|
|
17
|
-
import {
|
|
18
|
-
DEFAULT_BASE_PATH,
|
|
19
|
-
PROTOCOLS,
|
|
20
|
-
} from '../constants';
|
|
17
|
+
import {DEFAULT_BASE_PATH, PROTOCOLS} from '../constants';
|
|
21
18
|
import {errors} from '../protocol';
|
|
22
19
|
import {DeviceSettings} from './device-settings';
|
|
23
20
|
import * as helpers from './helpers';
|
|
@@ -31,7 +28,8 @@ const ALL_DRIVERS_MATCH = '*';
|
|
|
31
28
|
const FEATURE_NAME_SEPARATOR = ':';
|
|
32
29
|
|
|
33
30
|
export class DriverCore<const C extends Constraints, Settings extends StringRecord = StringRecord>
|
|
34
|
-
extends ExtensionCore
|
|
31
|
+
extends ExtensionCore
|
|
32
|
+
implements Core<C, Settings>
|
|
35
33
|
{
|
|
36
34
|
/**
|
|
37
35
|
* Make the basedriver version available so for any driver which inherits from this package, we
|
|
@@ -41,7 +39,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
41
39
|
|
|
42
40
|
sessionId: string | null;
|
|
43
41
|
|
|
44
|
-
sessionCreationTimestampMs
|
|
42
|
+
sessionCreationTimestampMs!: number;
|
|
45
43
|
|
|
46
44
|
opts: DriverOpts<C>;
|
|
47
45
|
|
|
@@ -104,7 +102,6 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
104
102
|
super();
|
|
105
103
|
this._log = this.log; // TODO: remove references to this._log and use this.log instead
|
|
106
104
|
|
|
107
|
-
|
|
108
105
|
// setup state
|
|
109
106
|
this.opts = opts as DriverOpts<C>;
|
|
110
107
|
|
|
@@ -116,7 +113,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
116
113
|
this.shouldValidateCaps = shouldValidateCaps;
|
|
117
114
|
|
|
118
115
|
// keeping track of initial opts
|
|
119
|
-
this.initialOpts =
|
|
116
|
+
this.initialOpts = structuredClone(opts);
|
|
120
117
|
|
|
121
118
|
this.sessionId = null;
|
|
122
119
|
this.helpers = helpers;
|
|
@@ -166,7 +163,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
166
163
|
* inadvertently change data outside of logEvent
|
|
167
164
|
*/
|
|
168
165
|
get eventHistory() {
|
|
169
|
-
return
|
|
166
|
+
return structuredClone(this._eventHistory);
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
/**
|
|
@@ -263,7 +260,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
263
260
|
isFeatureEnabled(name: string): boolean {
|
|
264
261
|
// automationName comparison is case-insensitive,
|
|
265
262
|
// while feature name is case-sensitive
|
|
266
|
-
const currentAutomationName =
|
|
263
|
+
const currentAutomationName = String(this.opts.automationName).toLowerCase();
|
|
267
264
|
|
|
268
265
|
const parseFullName = (fullName: string) => {
|
|
269
266
|
const separatorPos = fullName.indexOf(FEATURE_NAME_SEPARATOR);
|
|
@@ -273,27 +270,31 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
273
270
|
// but better be safe than sorry
|
|
274
271
|
throw new Error(
|
|
275
272
|
`The full feature name must include both the automation name ` +
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
273
|
+
`'${this.opts.automationName}' or the '${ALL_DRIVERS_MATCH}' ` +
|
|
274
|
+
`wildcard to apply the feature to all installed drivers, and ` +
|
|
275
|
+
`the feature name split by a colon. Got '${fullName}' instead`,
|
|
279
276
|
);
|
|
280
277
|
}
|
|
281
278
|
return [
|
|
282
|
-
|
|
283
|
-
fullName.substring(separatorPos + 1)
|
|
279
|
+
fullName.substring(0, separatorPos).toLowerCase(),
|
|
280
|
+
fullName.substring(separatorPos + 1),
|
|
284
281
|
];
|
|
285
282
|
};
|
|
286
283
|
const parseFullNames = (fullNames: string[]) => fullNames.map(parseFullName);
|
|
287
|
-
const matches = (
|
|
288
|
-
[
|
|
284
|
+
const matches = (pair: string[]) => {
|
|
285
|
+
const [automationName, featureName] = pair;
|
|
286
|
+
return (
|
|
287
|
+
[currentAutomationName, ALL_DRIVERS_MATCH].includes(automationName) && featureName === name
|
|
288
|
+
);
|
|
289
|
+
};
|
|
289
290
|
|
|
290
291
|
// if we have explicitly denied this feature, return false immediately
|
|
291
|
-
if (!
|
|
292
|
+
if (!util.isEmpty(this.denyInsecure) && parseFullNames(this.denyInsecure).some(matches)) {
|
|
292
293
|
return false;
|
|
293
294
|
}
|
|
294
295
|
|
|
295
296
|
// if we specifically have allowed the feature, return true
|
|
296
|
-
if (!
|
|
297
|
+
if (!util.isEmpty(this.allowInsecure) && parseFullNames(this.allowInsecure).some(matches)) {
|
|
297
298
|
return true;
|
|
298
299
|
}
|
|
299
300
|
|
|
@@ -332,7 +333,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
332
333
|
validStrategies = validStrategies.concat(this.webLocatorStrategies);
|
|
333
334
|
}
|
|
334
335
|
|
|
335
|
-
if (!
|
|
336
|
+
if (!validStrategies.includes(strategy)) {
|
|
336
337
|
throw new errors.InvalidSelectorError(
|
|
337
338
|
`Locator Strategy '${strategy}' is not supported for this session`,
|
|
338
339
|
);
|
|
@@ -370,17 +371,17 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
370
371
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
371
372
|
proxyRouteIsAvoided(sessionId: string, method: HTTPMethod, url: string, body?: any): boolean {
|
|
372
373
|
for (const avoidSchema of this.getProxyAvoidList(sessionId)) {
|
|
373
|
-
if (!
|
|
374
|
+
if (!Array.isArray(avoidSchema) || avoidSchema.length !== 2) {
|
|
374
375
|
throw new Error('Proxy avoidance must be a list of pairs');
|
|
375
376
|
}
|
|
376
377
|
const [avoidMethod, avoidPathRegex] = avoidSchema;
|
|
377
|
-
if (!
|
|
378
|
+
if (!['GET', 'POST', 'DELETE'].includes(avoidMethod)) {
|
|
378
379
|
throw new Error(`Unrecognized proxy avoidance method '${avoidMethod}'`);
|
|
379
380
|
}
|
|
380
|
-
if (!
|
|
381
|
+
if (!(avoidPathRegex instanceof RegExp)) {
|
|
381
382
|
throw new Error('Proxy avoidance path must be a regular expression');
|
|
382
383
|
}
|
|
383
|
-
const normalizedUrl = url.replace(new RegExp(`^${
|
|
384
|
+
const normalizedUrl = url.replace(new RegExp(`^${util.escapeRegExp(this.basePath)}`), '');
|
|
384
385
|
if (avoidMethod === method && avoidPathRegex.test(normalizedUrl)) {
|
|
385
386
|
return true;
|
|
386
387
|
}
|
|
@@ -406,5 +407,4 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
|
|
|
406
407
|
this.noCommandTimer = null;
|
|
407
408
|
}
|
|
408
409
|
}
|
|
409
|
-
|
|
410
410
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {util, node} from '@appium/support';
|
|
2
2
|
import {log} from './logger';
|
|
3
|
-
import {node, util} from '@appium/support';
|
|
4
3
|
import {errors} from '../protocol/errors';
|
|
5
4
|
import type {StringRecord, IDeviceSettings, SettingsUpdateListener} from '@appium/types';
|
|
6
5
|
|
|
@@ -24,7 +23,7 @@ export class DeviceSettings<T extends StringRecord = StringRecord> implements ID
|
|
|
24
23
|
*/
|
|
25
24
|
constructor(
|
|
26
25
|
defaultSettings: T = {} as T,
|
|
27
|
-
onSettingsUpdate: SettingsUpdateListener<T> = async () => {}
|
|
26
|
+
onSettingsUpdate: SettingsUpdateListener<T> = async () => {},
|
|
28
27
|
) {
|
|
29
28
|
this._settings = {...defaultSettings};
|
|
30
29
|
this._onSettingsUpdate = onSettingsUpdate;
|
|
@@ -36,32 +35,28 @@ export class DeviceSettings<T extends StringRecord = StringRecord> implements ID
|
|
|
36
35
|
* @param newSettings - New settings to merge (must be plain object; total size remains bounded).
|
|
37
36
|
*/
|
|
38
37
|
async update(newSettings: T): Promise<void> {
|
|
39
|
-
if (!
|
|
38
|
+
if (!util.isPlainObject(newSettings)) {
|
|
40
39
|
throw new errors.InvalidArgumentError(
|
|
41
40
|
`Settings update should be called with valid JSON. Got ` +
|
|
42
|
-
`${JSON.stringify(newSettings)} instead
|
|
41
|
+
`${JSON.stringify(newSettings)} instead`,
|
|
43
42
|
);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
if (node.getObjectSize({...this._settings, ...newSettings}) >= MAX_SETTINGS_SIZE) {
|
|
47
46
|
throw new errors.InvalidArgumentError(
|
|
48
47
|
`New settings cannot be applied, because the overall ` +
|
|
49
|
-
`object size exceeds the allowed limit of ${util.toReadableSizeString(MAX_SETTINGS_SIZE)}
|
|
48
|
+
`object size exceeds the allowed limit of ${util.toReadableSizeString(MAX_SETTINGS_SIZE)}`,
|
|
50
49
|
);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
for (const prop in newSettings) {
|
|
54
|
-
if (
|
|
53
|
+
if (this._settings[prop] !== undefined) {
|
|
55
54
|
if (this._settings[prop] === newSettings[prop]) {
|
|
56
55
|
log.debug(`The value of '${prop}' setting did not change. Skipping the update for it`);
|
|
57
56
|
continue;
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
|
-
await this._onSettingsUpdate(
|
|
61
|
-
prop as keyof T,
|
|
62
|
-
newSettings[prop],
|
|
63
|
-
this._settings[prop]
|
|
64
|
-
);
|
|
59
|
+
await this._onSettingsUpdate(prop as keyof T, newSettings[prop], this._settings[prop]);
|
|
65
60
|
this._settings[prop] = newSettings[prop];
|
|
66
61
|
}
|
|
67
62
|
}
|