@appium/base-driver 9.3.2 → 9.3.3
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/LICENSE +1 -1
- package/build/lib/basedriver/commands/event.d.ts +5 -9
- package/build/lib/basedriver/commands/event.d.ts.map +1 -1
- package/build/lib/basedriver/commands/event.js +28 -49
- package/build/lib/basedriver/commands/event.js.map +1 -1
- package/build/lib/basedriver/commands/execute.d.ts +5 -11
- package/build/lib/basedriver/commands/execute.d.ts.map +1 -1
- package/build/lib/basedriver/commands/execute.js +15 -39
- package/build/lib/basedriver/commands/execute.js.map +1 -1
- package/build/lib/basedriver/commands/find.d.ts +5 -12
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.js +38 -98
- package/build/lib/basedriver/commands/find.js.map +1 -1
- package/build/lib/basedriver/commands/index.d.ts +7 -3
- package/build/lib/basedriver/commands/index.d.ts.map +1 -1
- package/build/lib/basedriver/commands/index.js +20 -27
- package/build/lib/basedriver/commands/index.js.map +1 -1
- package/build/lib/basedriver/commands/log.d.ts +5 -10
- package/build/lib/basedriver/commands/log.d.ts.map +1 -1
- package/build/lib/basedriver/commands/log.js +17 -50
- package/build/lib/basedriver/commands/log.js.map +1 -1
- package/build/lib/basedriver/commands/mixin.d.ts +12 -0
- package/build/lib/basedriver/commands/mixin.d.ts.map +1 -0
- package/build/lib/basedriver/commands/mixin.js +17 -0
- package/build/lib/basedriver/commands/mixin.js.map +1 -0
- package/build/lib/basedriver/commands/session.d.ts +5 -11
- package/build/lib/basedriver/commands/session.d.ts.map +1 -1
- package/build/lib/basedriver/commands/session.js +20 -52
- package/build/lib/basedriver/commands/session.js.map +1 -1
- package/build/lib/basedriver/commands/settings.d.ts +5 -9
- package/build/lib/basedriver/commands/settings.d.ts.map +1 -1
- package/build/lib/basedriver/commands/settings.js +14 -34
- package/build/lib/basedriver/commands/settings.js.map +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts +5 -9
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +107 -126
- package/build/lib/basedriver/commands/timeout.js.map +1 -1
- package/build/lib/basedriver/core.d.ts +2 -4
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +0 -2
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/driver.d.ts +12 -12
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +22 -14
- package/build/lib/basedriver/driver.js.map +1 -1
- package/build/lib/express/server.d.ts +3 -15
- package/build/lib/express/server.d.ts.map +1 -1
- package/lib/basedriver/commands/event.ts +48 -0
- package/lib/basedriver/commands/execute.ts +39 -0
- package/lib/basedriver/commands/find.ts +79 -0
- package/lib/basedriver/commands/index.ts +7 -0
- package/lib/basedriver/commands/log.ts +36 -0
- package/lib/basedriver/commands/mixin.ts +14 -0
- package/lib/basedriver/commands/session.ts +34 -0
- package/lib/basedriver/commands/settings.ts +25 -0
- package/lib/basedriver/commands/timeout.ts +155 -0
- package/lib/basedriver/core.js +0 -3
- package/lib/basedriver/driver.js +8 -11
- package/package.json +6 -6
- package/lib/basedriver/commands/event.js +0 -63
- package/lib/basedriver/commands/execute.js +0 -45
- package/lib/basedriver/commands/find.js +0 -108
- package/lib/basedriver/commands/index.js +0 -35
- package/lib/basedriver/commands/log.js +0 -64
- package/lib/basedriver/commands/session.js +0 -57
- package/lib/basedriver/commands/settings.js +0 -38
- package/lib/basedriver/commands/timeout.js +0 -168
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-unused-vars */
|
|
4
|
+
/* eslint-disable require-await */
|
|
5
|
+
import {waitForCondition} from 'asyncbox';
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
import {util} from '@appium/support';
|
|
8
|
+
import {errors} from '../../protocol';
|
|
9
|
+
import {BaseDriver} from '../driver';
|
|
10
|
+
import {Constraints, ITimeoutCommands} from '@appium/types';
|
|
11
|
+
import {mixin} from './mixin';
|
|
12
|
+
|
|
13
|
+
declare module '../driver' {
|
|
14
|
+
interface BaseDriver<C extends Constraints> extends ITimeoutCommands {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const MIN_TIMEOUT = 0;
|
|
18
|
+
|
|
19
|
+
const TimeoutCommands: ITimeoutCommands = {
|
|
20
|
+
async timeouts(type, ms, script, pageLoad, implicit) {
|
|
21
|
+
if (util.hasValue(type) && util.hasValue(ms)) {
|
|
22
|
+
this.log.debug(`MJSONWP timeout arguments: ${JSON.stringify({type, ms})}}`);
|
|
23
|
+
|
|
24
|
+
switch (type) {
|
|
25
|
+
case 'command':
|
|
26
|
+
await this.newCommandTimeout(ms);
|
|
27
|
+
return;
|
|
28
|
+
case 'implicit':
|
|
29
|
+
await this.implicitWaitMJSONWP(ms);
|
|
30
|
+
return;
|
|
31
|
+
case 'page load':
|
|
32
|
+
await this.pageLoadTimeoutMJSONWP(ms);
|
|
33
|
+
return;
|
|
34
|
+
case 'script':
|
|
35
|
+
await this.scriptTimeoutMJSONWP(ms);
|
|
36
|
+
return;
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`'${type}' type is not supported for MJSONWP timeout`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Otherwise assume it is W3C protocol
|
|
43
|
+
this.log.debug(
|
|
44
|
+
`W3C timeout argument: ${JSON.stringify({
|
|
45
|
+
script,
|
|
46
|
+
pageLoad,
|
|
47
|
+
implicit,
|
|
48
|
+
})}}`
|
|
49
|
+
);
|
|
50
|
+
if (util.hasValue(script)) {
|
|
51
|
+
await this.scriptTimeoutW3C(script);
|
|
52
|
+
}
|
|
53
|
+
if (util.hasValue(pageLoad)) {
|
|
54
|
+
await this.pageLoadTimeoutW3C(pageLoad);
|
|
55
|
+
}
|
|
56
|
+
if (util.hasValue(implicit)) {
|
|
57
|
+
await this.implicitWaitW3C(implicit);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
async getTimeouts() {
|
|
62
|
+
return {
|
|
63
|
+
command: this.newCommandTimeoutMs,
|
|
64
|
+
implicit: this.implicitWaitMs,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// implicit
|
|
69
|
+
async implicitWaitW3C(ms) {
|
|
70
|
+
await this.implicitWait(ms);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
async implicitWaitMJSONWP(ms) {
|
|
74
|
+
await this.implicitWait(ms);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
async implicitWait(ms) {
|
|
78
|
+
await this.setImplicitWait(this.parseTimeoutArgument(ms));
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
// pageLoad
|
|
82
|
+
async pageLoadTimeoutW3C(ms) {
|
|
83
|
+
throw new errors.NotImplementedError('Not implemented yet for pageLoad.');
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async pageLoadTimeoutMJSONWP(ms) {
|
|
87
|
+
throw new errors.NotImplementedError('Not implemented yet for pageLoad.');
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// script
|
|
91
|
+
async scriptTimeoutW3C(ms) {
|
|
92
|
+
throw new errors.NotImplementedError('Not implemented yet for script.');
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
async scriptTimeoutMJSONWP(ms) {
|
|
96
|
+
throw new errors.NotImplementedError('Not implemented yet for script.');
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// command
|
|
100
|
+
async newCommandTimeout(ms) {
|
|
101
|
+
this.setNewCommandTimeout(this.parseTimeoutArgument(ms));
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
setImplicitWait(ms) {
|
|
105
|
+
// eslint-disable-line require-await
|
|
106
|
+
this.implicitWaitMs = ms;
|
|
107
|
+
this.log.debug(`Set implicit wait to ${ms}ms`);
|
|
108
|
+
if (this.managedDrivers && this.managedDrivers.length) {
|
|
109
|
+
this.log.debug('Setting implicit wait on managed drivers');
|
|
110
|
+
for (const driver of this.managedDrivers) {
|
|
111
|
+
if (_.isFunction(driver.setImplicitWait)) {
|
|
112
|
+
driver.setImplicitWait(ms);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
setNewCommandTimeout(ms) {
|
|
119
|
+
this.newCommandTimeoutMs = ms;
|
|
120
|
+
this.log.debug(`Set new command timeout to ${ms}ms`);
|
|
121
|
+
if (this.managedDrivers && this.managedDrivers.length) {
|
|
122
|
+
this.log.debug('Setting new command timeout on managed drivers');
|
|
123
|
+
for (const driver of this.managedDrivers) {
|
|
124
|
+
if (_.isFunction(driver.setNewCommandTimeout)) {
|
|
125
|
+
driver.setNewCommandTimeout(ms);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
async implicitWaitForCondition(condFn) {
|
|
132
|
+
this.log.debug(`Waiting up to ${this.implicitWaitMs} ms for condition`);
|
|
133
|
+
const wrappedCondFn = async (...args: any[]) => {
|
|
134
|
+
// reset command timeout
|
|
135
|
+
await this.clearNewCommandTimeout();
|
|
136
|
+
|
|
137
|
+
return await condFn(...args);
|
|
138
|
+
};
|
|
139
|
+
return await waitForCondition(wrappedCondFn, {
|
|
140
|
+
waitMs: this.implicitWaitMs,
|
|
141
|
+
intervalMs: 500,
|
|
142
|
+
logger: this.log,
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
parseTimeoutArgument<C extends Constraints>(this: BaseDriver<C>, ms: number | string) {
|
|
147
|
+
const duration = parseInt(String(ms), 10);
|
|
148
|
+
if (_.isNaN(duration) || duration < MIN_TIMEOUT) {
|
|
149
|
+
throw new errors.UnknownError(`Invalid timeout value '${ms}'`);
|
|
150
|
+
}
|
|
151
|
+
return duration;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
mixin(TimeoutCommands);
|
package/lib/basedriver/core.js
CHANGED
package/lib/basedriver/driver.js
CHANGED
|
@@ -8,7 +8,6 @@ import B from 'bluebird';
|
|
|
8
8
|
import _ from 'lodash';
|
|
9
9
|
import {fixCaps, isW3cCaps} from '../helpers/capabilities';
|
|
10
10
|
import {DELETE_SESSION_COMMAND, determineProtocol, errors} from '../protocol';
|
|
11
|
-
import {createBaseDriverClass} from './commands';
|
|
12
11
|
import helpers from './helpers';
|
|
13
12
|
import {BASE_DESIRED_CAP_CONSTRAINTS} from '@appium/types';
|
|
14
13
|
|
|
@@ -22,9 +21,10 @@ const ON_UNEXPECTED_SHUTDOWN_EVENT = 'onUnexpectedShutdown';
|
|
|
22
21
|
* @implements {SessionHandler<C>}
|
|
23
22
|
* @template {Constraints} C
|
|
24
23
|
* @template {StringRecord} [CArgs=StringRecord]
|
|
24
|
+
* @implements {Driver<C, CArgs>}
|
|
25
25
|
* @extends {DriverCore<C>}
|
|
26
26
|
*/
|
|
27
|
-
export class
|
|
27
|
+
export class BaseDriver extends DriverCore {
|
|
28
28
|
/**
|
|
29
29
|
* @type {CArgs & ServerArgs}
|
|
30
30
|
*/
|
|
@@ -59,7 +59,7 @@ export class BaseDriverCore extends DriverCore {
|
|
|
59
59
|
super(opts, shouldValidateCaps);
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* This must be assigned here because the declaration of {@linkcode
|
|
62
|
+
* This must be assigned here because the declaration of {@linkcode BaseDriver.opts} above
|
|
63
63
|
* blows away {@linkcode DriverCore.opts}.
|
|
64
64
|
*/
|
|
65
65
|
this.opts = opts;
|
|
@@ -407,12 +407,9 @@ export class BaseDriverCore extends DriverCore {
|
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
|
|
411
|
-
*
|
|
412
|
-
|
|
413
|
-
* @implements {Driver<C>}
|
|
414
|
-
*/
|
|
415
|
-
export class BaseDriver extends createBaseDriverClass(BaseDriverCore) {}
|
|
410
|
+
// eslint-disable-next-line import/no-unresolved
|
|
411
|
+
export * from './commands';
|
|
412
|
+
|
|
416
413
|
export default BaseDriver;
|
|
417
414
|
|
|
418
415
|
/**
|
|
@@ -433,11 +430,11 @@ export default BaseDriver;
|
|
|
433
430
|
*/
|
|
434
431
|
|
|
435
432
|
/**
|
|
436
|
-
* This is used to extend {@linkcode
|
|
433
|
+
* This is used to extend {@linkcode BaseDriver} by the mixins and also external drivers.
|
|
437
434
|
* @template {Constraints} C
|
|
438
435
|
* @template [Proto={}]
|
|
439
436
|
* @template [Static={}]
|
|
440
|
-
* @typedef {import('@appium/types').Class<
|
|
437
|
+
* @typedef {import('@appium/types').Class<BaseDriver<C> & Proto,import('@appium/types').DriverStatic & Static>} BaseDriverBase
|
|
441
438
|
*/
|
|
442
439
|
|
|
443
440
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/base-driver",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.3",
|
|
4
4
|
"description": "Base driver class for Appium drivers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"test:unit": "mocha \"./test/unit/**/*.spec.js\""
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@appium/support": "^3.1.
|
|
47
|
-
"@appium/types": "^0.10.
|
|
46
|
+
"@appium/support": "^3.1.7",
|
|
47
|
+
"@appium/types": "^0.10.1",
|
|
48
48
|
"@colors/colors": "1.5.0",
|
|
49
49
|
"@types/async-lock": "1.4.0",
|
|
50
50
|
"@types/bluebird": "3.5.38",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"express": "4.18.2",
|
|
61
61
|
"http-status-codes": "2.2.0",
|
|
62
62
|
"lodash": "4.17.21",
|
|
63
|
-
"lru-cache": "7.
|
|
63
|
+
"lru-cache": "7.18.3",
|
|
64
64
|
"method-override": "3.0.0",
|
|
65
65
|
"morgan": "1.10.0",
|
|
66
66
|
"serve-favicon": "2.5.0",
|
|
67
67
|
"source-map-support": "0.5.21",
|
|
68
|
-
"type-fest": "3.6.
|
|
68
|
+
"type-fest": "3.6.1",
|
|
69
69
|
"validate.js": "0.13.1"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "872b924a97c13142bdb8bf4218a4db324f309ce4",
|
|
79
79
|
"typedoc": {
|
|
80
80
|
"entryPoint": "./lib/index.js"
|
|
81
81
|
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/* eslint-disable require-await */
|
|
2
|
-
// @ts-check
|
|
3
|
-
import _ from 'lodash';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @template {Constraints} C
|
|
7
|
-
* @param {import('./timeout').TimeoutBase<C>} Base
|
|
8
|
-
* @returns {EventBase<C>}
|
|
9
|
-
*/
|
|
10
|
-
export function EventMixin(Base) {
|
|
11
|
-
/**
|
|
12
|
-
* @implements {IEventCommands}
|
|
13
|
-
*/
|
|
14
|
-
class EventCommands extends Base {
|
|
15
|
-
/**
|
|
16
|
-
* Log a user-defined event in the event log.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} vendor - a vendor prefix for the user, to ensure namespace
|
|
19
|
-
* separation
|
|
20
|
-
* @param {string} event - the event name
|
|
21
|
-
*/
|
|
22
|
-
async logCustomEvent(vendor, event) {
|
|
23
|
-
this.logEvent(`${vendor}:${event}`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Get the event log
|
|
28
|
-
* @param {string|string[]} [type] - the event type to filter with.
|
|
29
|
-
* It returns all events if the type is not provided or empty string/array.
|
|
30
|
-
* @returns {Promise<import('@appium/types').EventHistory|Record<string,number>>} - the event history log object
|
|
31
|
-
*/
|
|
32
|
-
async getLogEvents(type) {
|
|
33
|
-
if (_.isEmpty(type)) {
|
|
34
|
-
return this.eventHistory;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const typeList = _.castArray(type);
|
|
38
|
-
|
|
39
|
-
return _.reduce(
|
|
40
|
-
this.eventHistory,
|
|
41
|
-
(acc, eventTimes, eventType) => {
|
|
42
|
-
if (typeList.includes(eventType)) {
|
|
43
|
-
acc[eventType] = eventTimes;
|
|
44
|
-
}
|
|
45
|
-
return acc;
|
|
46
|
-
},
|
|
47
|
-
{}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return EventCommands;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
57
|
-
* @typedef {import('@appium/types').IEventCommands} IEventCommands
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @template {Constraints} C
|
|
62
|
-
* @typedef {import('../driver').BaseDriverBase<C, import('@appium/types').ITimeoutCommands & IEventCommands>} EventBase
|
|
63
|
-
*/
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import {errors, validateExecuteMethodParams} from '../../protocol';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @template {Constraints} C
|
|
6
|
-
* @param {import('./session').SessionBase<C>} Base
|
|
7
|
-
* @returns {ExecuteBase<C>}
|
|
8
|
-
*/
|
|
9
|
-
export function ExecuteMixin(Base) {
|
|
10
|
-
/**
|
|
11
|
-
* @implements {IExecuteCommands}
|
|
12
|
-
*/
|
|
13
|
-
class ExecuteCommands extends Base {
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} script
|
|
16
|
-
* @param {[Record<string, any>]|[]} protoArgs
|
|
17
|
-
*/
|
|
18
|
-
async executeMethod(script, protoArgs) {
|
|
19
|
-
const Driver = /** @type {DriverClass} */ (this.constructor);
|
|
20
|
-
const commandMetadata = {...Driver.executeMethodMap?.[script]};
|
|
21
|
-
if (!commandMetadata.command) {
|
|
22
|
-
const availableScripts = _.keys(Driver.executeMethodMap);
|
|
23
|
-
throw new errors.UnsupportedOperationError(
|
|
24
|
-
`Unsupported execute method '${script}'. Available methods ` +
|
|
25
|
-
`are: ${availableScripts.join(', ')}`
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
const args = validateExecuteMethodParams(protoArgs, commandMetadata.params);
|
|
29
|
-
return await this[commandMetadata.command](...args);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return ExecuteCommands;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {import('@appium/types').IExecuteCommands} IExecuteCommands
|
|
37
|
-
* @typedef {import('@appium/types').Driver} Driver
|
|
38
|
-
* @typedef {import('@appium/types').DriverClass} DriverClass
|
|
39
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @template {Constraints} C
|
|
44
|
-
* @typedef {import('../driver').BaseDriverBase<C, import('@appium/types').ITimeoutCommands & import('@appium/types').IEventCommands & import('@appium/types').IFindCommands & import('@appium/types').ILogCommands<C> & import('@appium/types').ISettingsCommands & import('@appium/types').ISessionCommands & IExecuteCommands>} ExecuteBase
|
|
45
|
-
*/
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/* eslint-disable require-await */
|
|
3
|
-
// @ts-check
|
|
4
|
-
import {errors} from '../../protocol';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @template {Constraints} C
|
|
8
|
-
* @param {import('./event').EventBase<C>} Base
|
|
9
|
-
* @returns {FindBase<C>}
|
|
10
|
-
*/
|
|
11
|
-
export function FindMixin(Base) {
|
|
12
|
-
/**
|
|
13
|
-
* @implements {IFindCommands}
|
|
14
|
-
*/
|
|
15
|
-
class FindCommands extends Base {
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @returns {Promise<Element>}
|
|
19
|
-
*/
|
|
20
|
-
async findElement(strategy, selector) {
|
|
21
|
-
return await this.findElOrElsWithProcessing(strategy, selector, false);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @returns {Promise<Element[]>}
|
|
27
|
-
*/
|
|
28
|
-
async findElements(strategy, selector) {
|
|
29
|
-
return await this.findElOrElsWithProcessing(strategy, selector, true);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @returns {Promise<Element>}
|
|
35
|
-
*/
|
|
36
|
-
async findElementFromElement(strategy, selector, elementId) {
|
|
37
|
-
return await this.findElOrElsWithProcessing(strategy, selector, false, elementId);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @returns {Promise<Element[]>}
|
|
43
|
-
*/
|
|
44
|
-
async findElementsFromElement(strategy, selector, elementId) {
|
|
45
|
-
return await this.findElOrElsWithProcessing(strategy, selector, true, elementId);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Returns an object which adheres to the way the JSON Wire Protocol represents elements:
|
|
49
|
-
*
|
|
50
|
-
* Override this for your own driver!
|
|
51
|
-
* @template {boolean} Mult
|
|
52
|
-
* @template [Ctx=any]
|
|
53
|
-
* @param {string} strategy
|
|
54
|
-
* @param {string} selector
|
|
55
|
-
* @param {Mult} mult
|
|
56
|
-
* @param {Ctx} [context]
|
|
57
|
-
* @returns {Promise<Mult extends true ? Element[] : Element>}
|
|
58
|
-
*/
|
|
59
|
-
async findElOrEls(strategy, selector, mult, context) {
|
|
60
|
-
throw new errors.NotImplementedError('Not implemented yet for find.');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @returns {Promise<string>}
|
|
65
|
-
*/
|
|
66
|
-
async getPageSource() {
|
|
67
|
-
throw new errors.NotImplementedError('Not implemented yet for find.');
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @template {boolean} Mult
|
|
71
|
-
* @template [Ctx=any]
|
|
72
|
-
* @param {string} strategy
|
|
73
|
-
* @param {string} selector
|
|
74
|
-
* @param {Mult} mult
|
|
75
|
-
* @param {Ctx} [context]
|
|
76
|
-
* @returns {Promise<Mult extends true ? Element[] : Element>}
|
|
77
|
-
*/
|
|
78
|
-
async findElOrElsWithProcessing(strategy, selector, mult, context) {
|
|
79
|
-
this.validateLocatorStrategy(strategy);
|
|
80
|
-
try {
|
|
81
|
-
return await this.findElOrEls(strategy, selector, mult, context);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
if (this.opts.printPageSourceOnFindFailure) {
|
|
84
|
-
const src = await this.getPageSource();
|
|
85
|
-
this.log.debug(`Error finding element${mult ? 's' : ''}: ${err.message}`);
|
|
86
|
-
this.log.debug(`Page source requested through 'printPageSourceOnFindFailure':`);
|
|
87
|
-
this.log.debug(src);
|
|
88
|
-
}
|
|
89
|
-
// still want the error to occur
|
|
90
|
-
throw err;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return FindCommands;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @typedef {import('@appium/types').Element} Element
|
|
100
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
101
|
-
* @typedef {import('@appium/types').IFindCommands} IFindCommands
|
|
102
|
-
* @typedef {import('@appium/types').ITimeoutCommands} ITimeoutCommands
|
|
103
|
-
* @typedef {import('@appium/types').IEventCommands} IEventCommands
|
|
104
|
-
*/
|
|
105
|
-
/**
|
|
106
|
-
* @template {Constraints} C
|
|
107
|
-
* @typedef {import('../driver').BaseDriverBase<C, ITimeoutCommands & IEventCommands & IFindCommands>} FindBase
|
|
108
|
-
*/
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import {EventMixin} from './event';
|
|
4
|
-
import {FindMixin} from './find';
|
|
5
|
-
import {LogMixin} from './log';
|
|
6
|
-
import {SessionMixin} from './session';
|
|
7
|
-
import {SettingsMixin} from './settings';
|
|
8
|
-
import {TimeoutMixin} from './timeout';
|
|
9
|
-
import {ExecuteMixin} from './execute';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Applies all the mixins to the `BaseDriverBase` class; returns a `BaseDriver` class definition.
|
|
13
|
-
* Each mixin is applied in the order it is listed here, and each type is a union with the previous.
|
|
14
|
-
*
|
|
15
|
-
* @template {Constraints} C
|
|
16
|
-
* @param {BaseDriverBase<C>} Base
|
|
17
|
-
*/
|
|
18
|
-
export const createBaseDriverClass = _.flow(
|
|
19
|
-
TimeoutMixin,
|
|
20
|
-
EventMixin,
|
|
21
|
-
FindMixin,
|
|
22
|
-
LogMixin,
|
|
23
|
-
SettingsMixin,
|
|
24
|
-
SessionMixin,
|
|
25
|
-
ExecuteMixin
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @template {Constraints} C
|
|
30
|
-
* @typedef {import('../driver').BaseDriverBase<C>} BaseDriverBase
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
35
|
-
*/
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/* eslint-disable require-await */
|
|
2
|
-
// @ts-check
|
|
3
|
-
|
|
4
|
-
import _ from 'lodash';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @template {Constraints} C
|
|
8
|
-
* @param {import('./find').FindBase<C>} Base
|
|
9
|
-
* @returns {LogBase<C>}
|
|
10
|
-
*/
|
|
11
|
-
export function LogMixin(Base) {
|
|
12
|
-
/**
|
|
13
|
-
* @implements {ILogCommands<C>}
|
|
14
|
-
*/
|
|
15
|
-
class LogCommands extends Base {
|
|
16
|
-
/** @type {Readonly<import('@appium/types').LogDefRecord<C>>} */
|
|
17
|
-
supportedLogTypes;
|
|
18
|
-
|
|
19
|
-
constructor(...args) {
|
|
20
|
-
super(...args);
|
|
21
|
-
this.supportedLogTypes ??= {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getLogTypes() {
|
|
25
|
-
this.log.debug('Retrieving supported log types');
|
|
26
|
-
return Object.keys(this.supportedLogTypes);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @this {import('@appium/types').Driver<C>}
|
|
31
|
-
* @param {keyof typeof this.supportedLogTypes} logType
|
|
32
|
-
* @returns {Promise<import('type-fest').AsyncReturnType<typeof this.supportedLogTypes[keyof typeof this.supportedLogTypes]['getter']>>}
|
|
33
|
-
*/
|
|
34
|
-
async getLog(logType) {
|
|
35
|
-
this.log.debug(`Retrieving '${String(logType)}' logs`);
|
|
36
|
-
|
|
37
|
-
if (!(logType in this.supportedLogTypes)) {
|
|
38
|
-
const logsTypesWithDescriptions = _.mapValues(this.supportedLogTypes, 'description');
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Unsupported log type '${String(logType)}'. ` +
|
|
41
|
-
`Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return await this.supportedLogTypes[logType].getter(this);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return LogCommands;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
53
|
-
* @typedef {import('@appium/types').StringRecord} StringRecord
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @template {Constraints} C
|
|
58
|
-
* @typedef {import('@appium/types').ILogCommands<C>} ILogCommands
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @template {Constraints} C
|
|
63
|
-
* @typedef {import('../driver').BaseDriverBase<C, import('@appium/types').ITimeoutCommands & import('@appium/types').IEventCommands & import('@appium/types').IFindCommands & ILogCommands<C>>} LogBase
|
|
64
|
-
*/
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/* eslint-disable require-await */
|
|
3
|
-
// @ts-check
|
|
4
|
-
import _ from 'lodash';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @template {Constraints} C
|
|
8
|
-
* @param {import('./settings').SettingsBase<C>} Base
|
|
9
|
-
* @returns {SessionBase<C>}
|
|
10
|
-
*/
|
|
11
|
-
export function SessionMixin(Base) {
|
|
12
|
-
/**
|
|
13
|
-
* @implements {ISessionCommands}
|
|
14
|
-
*/
|
|
15
|
-
class SessionCommands extends Base {
|
|
16
|
-
/**
|
|
17
|
-
* @returns {Promise<MultiSessionData[]>}
|
|
18
|
-
*/
|
|
19
|
-
async getSessions() {
|
|
20
|
-
let ret = [];
|
|
21
|
-
|
|
22
|
-
if (this.sessionId) {
|
|
23
|
-
ret.push({
|
|
24
|
-
id: this.sessionId,
|
|
25
|
-
capabilities: this.caps,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return ret;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns capabilities for the session and event history (if applicable)
|
|
34
|
-
* @returns {Promise<SingularSessionData>}
|
|
35
|
-
*/
|
|
36
|
-
async getSession() {
|
|
37
|
-
if (this.caps.eventTimings) {
|
|
38
|
-
return {...this.caps, events: this.eventHistory};
|
|
39
|
-
}
|
|
40
|
-
return this.caps;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return SessionCommands;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @typedef {import('@appium/types').ISessionCommands} ISessionCommands
|
|
49
|
-
* @typedef {import('@appium/types').SingularSessionData} SingularSessionData
|
|
50
|
-
* @typedef {import('@appium/types').MultiSessionData} MultiSessionData
|
|
51
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @template {Constraints} C
|
|
56
|
-
* @typedef {import('../driver').BaseDriverBase<C, import('@appium/types').ITimeoutCommands & import('@appium/types').IEventCommands & import('@appium/types').IFindCommands & import('@appium/types').ILogCommands<C> & import('@appium/types').ISettingsCommands & ISessionCommands>} SessionBase
|
|
57
|
-
*/
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @template {Constraints} C
|
|
5
|
-
* @param {import('./log').LogBase<C>} Base
|
|
6
|
-
* @returns {SettingsBase<C>}
|
|
7
|
-
*/
|
|
8
|
-
export function SettingsMixin(Base) {
|
|
9
|
-
/**
|
|
10
|
-
* @implements {ISettingsCommands}
|
|
11
|
-
*/
|
|
12
|
-
class SettingsCommands extends Base {
|
|
13
|
-
async updateSettings(newSettings) {
|
|
14
|
-
if (!this.settings) {
|
|
15
|
-
this.log.errorAndThrow('Cannot update settings; settings object not found');
|
|
16
|
-
}
|
|
17
|
-
return await this.settings.update(newSettings);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async getSettings() {
|
|
21
|
-
if (!this.settings) {
|
|
22
|
-
this.log.errorAndThrow('Cannot get settings; settings object not found');
|
|
23
|
-
}
|
|
24
|
-
return await this.settings.getSettings();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return SettingsCommands;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @typedef {import('@appium/types').Constraints} Constraints
|
|
33
|
-
* @typedef {import('@appium/types').ISettingsCommands} ISettingsCommands
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @template {Constraints} C
|
|
37
|
-
* @typedef {import('../driver').BaseDriverBase<C, import('@appium/types').ITimeoutCommands & import('@appium/types').IEventCommands & import('@appium/types').IFindCommands & import('@appium/types').ILogCommands<C> & ISettingsCommands>} SettingsBase
|
|
38
|
-
*/
|