@appium/base-driver 8.3.1 → 8.4.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/build/lib/basedriver/capabilities.d.ts +80 -0
- package/build/lib/basedriver/capabilities.d.ts.map +1 -0
- package/build/lib/basedriver/capabilities.js +11 -10
- package/build/lib/basedriver/commands/event.d.ts +9 -0
- package/build/lib/basedriver/commands/event.d.ts.map +1 -0
- package/build/lib/basedriver/commands/event.js +21 -21
- package/build/lib/basedriver/commands/find.d.ts +11 -0
- package/build/lib/basedriver/commands/find.d.ts.map +1 -0
- package/build/lib/basedriver/commands/find.js +44 -37
- package/build/lib/basedriver/commands/index.d.ts +8 -0
- package/build/lib/basedriver/commands/index.d.ts.map +1 -0
- package/build/lib/basedriver/commands/index.js +17 -14
- package/build/lib/basedriver/commands/log.d.ts +12 -0
- package/build/lib/basedriver/commands/log.d.ts.map +1 -0
- package/build/lib/basedriver/commands/log.js +24 -26
- package/build/lib/basedriver/commands/session.d.ts +11 -0
- package/build/lib/basedriver/commands/session.d.ts.map +1 -0
- package/build/lib/basedriver/commands/session.js +21 -147
- package/build/lib/basedriver/commands/settings.d.ts +10 -0
- package/build/lib/basedriver/commands/settings.d.ts.map +1 -0
- package/build/lib/basedriver/commands/settings.js +19 -17
- package/build/lib/basedriver/commands/timeout.d.ts +8 -0
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -0
- package/build/lib/basedriver/commands/timeout.js +118 -137
- package/build/lib/basedriver/core.d.ts +235 -0
- package/build/lib/basedriver/core.d.ts.map +1 -0
- package/build/lib/basedriver/core.js +283 -0
- package/build/lib/basedriver/desired-caps.d.ts +5 -0
- package/build/lib/basedriver/desired-caps.d.ts.map +1 -0
- package/build/lib/basedriver/desired-caps.js +1 -1
- package/build/lib/basedriver/device-settings.d.ts +32 -0
- package/build/lib/basedriver/device-settings.d.ts.map +1 -0
- package/build/lib/basedriver/device-settings.js +19 -11
- package/build/lib/basedriver/driver.d.ts +83 -0
- package/build/lib/basedriver/driver.d.ts.map +1 -0
- package/build/lib/basedriver/driver.js +100 -266
- package/build/lib/basedriver/helpers.d.ts +132 -0
- package/build/lib/basedriver/helpers.d.ts.map +1 -0
- package/build/lib/basedriver/helpers.js +17 -1
- package/build/lib/basedriver/logger.d.ts +3 -0
- package/build/lib/basedriver/logger.d.ts.map +1 -0
- package/build/lib/constants.d.ts +9 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/express/crash.d.ts +3 -0
- package/build/lib/express/crash.d.ts.map +1 -0
- package/build/lib/express/express-logging.d.ts +3 -0
- package/build/lib/express/express-logging.d.ts.map +1 -0
- package/build/lib/express/idempotency.d.ts +2 -0
- package/build/lib/express/idempotency.d.ts.map +1 -0
- package/build/lib/express/logger.d.ts +3 -0
- package/build/lib/express/logger.d.ts.map +1 -0
- package/build/lib/express/middleware.d.ts +9 -0
- package/build/lib/express/middleware.d.ts.map +1 -0
- package/build/lib/express/server.d.ts +10 -0
- package/build/lib/express/server.d.ts.map +1 -0
- package/build/lib/express/static.d.ts +6 -0
- package/build/lib/express/static.d.ts.map +1 -0
- package/build/lib/express/websocket.d.ts +64 -0
- package/build/lib/express/websocket.d.ts.map +1 -0
- package/build/lib/express/websocket.js +39 -38
- package/build/lib/helpers/capabilities.d.ts +13 -0
- package/build/lib/helpers/capabilities.d.ts.map +1 -0
- package/build/lib/helpers/capabilities.js +41 -1
- package/build/lib/index.d.ts +183 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +40 -20
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts +48 -0
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -0
- package/build/lib/jsonwp-proxy/proxy.d.ts +41 -0
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -0
- package/build/lib/jsonwp-proxy/proxy.js +24 -6
- package/build/lib/jsonwp-status/status.d.ts +159 -0
- package/build/lib/jsonwp-status/status.d.ts.map +1 -0
- package/build/lib/protocol/errors.d.ts +310 -0
- package/build/lib/protocol/errors.d.ts.map +1 -0
- package/build/lib/protocol/errors.js +81 -2
- package/build/lib/protocol/helpers.d.ts +22 -0
- package/build/lib/protocol/helpers.d.ts.map +1 -0
- package/build/lib/protocol/index.d.ts +16 -0
- package/build/lib/protocol/index.d.ts.map +1 -0
- package/build/lib/protocol/index.js +7 -7
- package/build/lib/protocol/protocol.d.ts +11 -0
- package/build/lib/protocol/protocol.d.ts.map +1 -0
- package/build/lib/protocol/protocol.js +2 -6
- package/build/lib/protocol/routes.d.ts +6 -0
- package/build/lib/protocol/routes.d.ts.map +1 -0
- package/build/lib/protocol/routes.js +17 -1
- package/build/lib/protocol/validators.d.ts +8 -0
- package/build/lib/protocol/validators.d.ts.map +1 -0
- package/build/test/basedriver/driver-tests.js +30 -3
- package/build/test/e2e/basedriver/websockets.e2e.spec.js +12 -7
- package/build/test/unit/basedriver/commands/event.spec.js +7 -7
- package/build/test/unit/basedriver/commands/log.spec.js +31 -24
- package/build/test/unit/basedriver/timeout.spec.js +1 -1
- package/build/test/unit/protocol/routes.spec.js +2 -2
- package/build/tsconfig.tsbuildinfo +1 -0
- package/lib/basedriver/capabilities.js +49 -10
- package/lib/basedriver/commands/event.js +49 -31
- package/lib/basedriver/commands/find.js +108 -43
- package/lib/basedriver/commands/index.js +25 -19
- package/lib/basedriver/commands/log.js +60 -33
- package/lib/basedriver/commands/session.js +39 -141
- package/lib/basedriver/commands/settings.js +33 -13
- package/lib/basedriver/commands/timeout.js +153 -153
- package/lib/basedriver/core.js +497 -0
- package/lib/basedriver/desired-caps.js +1 -1
- package/lib/basedriver/device-settings.js +47 -12
- package/lib/basedriver/driver.js +273 -395
- package/lib/basedriver/helpers.js +18 -2
- package/lib/express/websocket.js +35 -32
- package/lib/helpers/capabilities.js +60 -1
- package/lib/index.js +16 -12
- package/lib/jsonwp-proxy/proxy.js +26 -6
- package/lib/protocol/errors.js +42 -42
- package/lib/protocol/index.js +4 -4
- package/lib/protocol/protocol.js +1 -3
- package/lib/protocol/routes.js +9 -0
- package/package.json +14 -11
- package/test/basedriver/driver-tests.js +31 -2
- package/index.d.ts +0 -386
|
@@ -1,40 +1,58 @@
|
|
|
1
|
+
/* eslint-disable require-await */
|
|
2
|
+
// @ts-check
|
|
1
3
|
import _ from 'lodash';
|
|
2
4
|
|
|
3
|
-
const commands = {};
|
|
4
|
-
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param {string} vendor - a vendor prefix for the user, to ensure namespace
|
|
9
|
-
* separation
|
|
10
|
-
* @param {string} event - the event name
|
|
6
|
+
* @param {TimeoutBase} Base
|
|
7
|
+
* @returns {EventBase}
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
9
|
+
export function EventMixin (Base) {
|
|
10
|
+
/**
|
|
11
|
+
* @implements {IEventCommands}
|
|
12
|
+
*/
|
|
13
|
+
class EventCommands extends Base {
|
|
14
|
+
/**
|
|
15
|
+
* Log a user-defined event in the event log.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} vendor - a vendor prefix for the user, to ensure namespace
|
|
18
|
+
* separation
|
|
19
|
+
* @param {string} event - the event name
|
|
20
|
+
*/
|
|
21
|
+
async logCustomEvent (vendor, event) {
|
|
22
|
+
this.logEvent(`${vendor}:${event}`);
|
|
23
|
+
}
|
|
15
24
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the event log
|
|
27
|
+
* @param {string|string[]} [type] - the event type to filter with.
|
|
28
|
+
* It returns all events if the type is not provided or empty string/array.
|
|
29
|
+
* @returns {Promise<import('@appium/types').EventHistory|Record<string,number>>} - the event history log object
|
|
30
|
+
*/
|
|
31
|
+
async getLogEvents (type) {
|
|
32
|
+
if (_.isEmpty(type)) {
|
|
33
|
+
return this.eventHistory;
|
|
34
|
+
}
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
type = [type];
|
|
30
|
-
}
|
|
36
|
+
const typeList = _.castArray(type);
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
return _.reduce(
|
|
39
|
+
this.eventHistory,
|
|
40
|
+
(acc, eventTimes, eventType) => {
|
|
41
|
+
if (typeList.includes(eventType)) {
|
|
42
|
+
acc[eventType] = eventTimes;
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
},
|
|
46
|
+
{},
|
|
47
|
+
);
|
|
35
48
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return EventCommands;
|
|
52
|
+
}
|
|
39
53
|
|
|
40
|
-
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {import('@appium/types').EventCommands} IEventCommands
|
|
56
|
+
* @typedef {import('./timeout').TimeoutBase} TimeoutBase
|
|
57
|
+
* @typedef {import('../driver').BaseDriverBase<import('@appium/types').TimeoutCommands & IEventCommands>} EventBase
|
|
58
|
+
*/
|
|
@@ -1,51 +1,116 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
/* eslint-disable require-await */
|
|
3
|
+
// @ts-check
|
|
4
|
+
import {errors} from '../../protocol';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return await this.findElOrEls(strategy, selector, mult, context);
|
|
20
|
-
} catch (err) {
|
|
21
|
-
if (this.opts.printPageSourceOnFindFailure) {
|
|
22
|
-
const src = await this.getPageSource();
|
|
23
|
-
this.log.debug(`Error finding element${mult ? 's' : ''}: ${err.message}`);
|
|
24
|
-
this.log.debug(`Page source requested through 'printPageSourceOnFindFailure':`);
|
|
25
|
-
this.log.debug(src);
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {EventBase} Base
|
|
9
|
+
* @returns {FindBase}
|
|
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);
|
|
26
22
|
}
|
|
27
|
-
// still want the error to occur
|
|
28
|
-
throw err;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @returns {Promise<Element[]>}
|
|
27
|
+
*/
|
|
28
|
+
async findElements (strategy, selector) {
|
|
29
|
+
return await this.findElOrElsWithProcessing(strategy, selector, true);
|
|
30
|
+
}
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<Element>}
|
|
35
|
+
*/
|
|
36
|
+
async findElementFromElement (strategy, selector, elementId) {
|
|
37
|
+
return await this.findElOrElsWithProcessing(
|
|
38
|
+
strategy,
|
|
39
|
+
selector,
|
|
40
|
+
false,
|
|
41
|
+
elementId,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @returns {Promise<Element[]>}
|
|
48
|
+
*/
|
|
49
|
+
async findElementsFromElement (strategy, selector, elementId) {
|
|
50
|
+
return await this.findElOrElsWithProcessing(
|
|
51
|
+
strategy,
|
|
52
|
+
selector,
|
|
53
|
+
true,
|
|
54
|
+
elementId,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
// Override the following function for your own driver, and the rest is taken
|
|
58
|
+
// care of!
|
|
59
|
+
// Returns an object which adheres to the way the JSON Wire Protocol represents elements:
|
|
60
|
+
// { ELEMENT: # } eg: { ELEMENT: 3 } or { ELEMENT: 1.023 }
|
|
61
|
+
/**
|
|
62
|
+
* @template {boolean} Mult
|
|
63
|
+
* @param {string} strategy
|
|
64
|
+
* @param {string} selector
|
|
65
|
+
* @param {Mult} mult
|
|
66
|
+
* @param {string} [context]
|
|
67
|
+
* @returns {Promise<Mult extends true ? Element[] : Element>}
|
|
68
|
+
*/
|
|
69
|
+
async findElOrEls (strategy, selector, mult, context) {
|
|
70
|
+
throw new errors.NotImplementedError('Not implemented yet for find.');
|
|
71
|
+
}
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @returns {Promise<string>}
|
|
75
|
+
*/
|
|
76
|
+
async getPageSource () {
|
|
77
|
+
throw new errors.NotImplementedError('Not implemented yet for find.');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @template {boolean} Mult
|
|
81
|
+
* @param {string} strategy
|
|
82
|
+
* @param {string} selector
|
|
83
|
+
* @param {Mult} mult
|
|
84
|
+
* @param {string} [context]
|
|
85
|
+
* @returns {Promise<Mult extends true ? Element[] : Element>}
|
|
86
|
+
*/
|
|
87
|
+
async findElOrElsWithProcessing (strategy, selector, mult, context) {
|
|
88
|
+
this.validateLocatorStrategy(strategy);
|
|
89
|
+
try {
|
|
90
|
+
return await this.findElOrEls(strategy, selector, mult, context);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (this.opts.printPageSourceOnFindFailure) {
|
|
93
|
+
const src = await this.getPageSource();
|
|
94
|
+
this.log.debug(
|
|
95
|
+
`Error finding element${mult ? 's' : ''}: ${err.message}`,
|
|
96
|
+
);
|
|
97
|
+
this.log.debug(
|
|
98
|
+
`Page source requested through 'printPageSourceOnFindFailure':`,
|
|
99
|
+
);
|
|
100
|
+
this.log.debug(src);
|
|
101
|
+
}
|
|
102
|
+
// still want the error to occur
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
47
107
|
|
|
108
|
+
return FindCommands;
|
|
109
|
+
}
|
|
48
110
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @typedef {import('@appium/types').Element} Element
|
|
113
|
+
* @typedef {import('@appium/types').FindCommands} IFindCommands
|
|
114
|
+
* @typedef {import('./event').EventBase} EventBase
|
|
115
|
+
* @typedef {import('../driver').BaseDriverBase<import('@appium/types').TimeoutCommands & import('@appium/types').EventCommands & IFindCommands>} FindBase
|
|
116
|
+
*/
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import settingsCmds from './settings';
|
|
3
|
-
import timeoutCmds from './timeout';
|
|
4
|
-
import findCmds from './find';
|
|
5
|
-
import logCmds from './log';
|
|
6
|
-
import eventCmds from './event';
|
|
1
|
+
// @ts-check
|
|
7
2
|
|
|
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';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Applies all the mixins to the `BaseDriverBase` class.
|
|
12
|
+
* Returns a `BaseDriver` class.
|
|
13
|
+
* @param {BaseDriverBase} Base
|
|
14
|
+
*/
|
|
15
|
+
export function createBaseDriverClass (Base) {
|
|
16
|
+
const WithTimeoutCommands = TimeoutMixin(Base);
|
|
17
|
+
const WithEventCommands = EventMixin(WithTimeoutCommands);
|
|
18
|
+
const WithFindCommands = FindMixin(WithEventCommands);
|
|
19
|
+
const WithLogCommands = LogMixin(WithFindCommands);
|
|
20
|
+
const WithSettingsCommands = SettingsMixin(WithLogCommands);
|
|
21
|
+
const WithSessionCommands = SessionMixin(WithSettingsCommands);
|
|
22
|
+
return WithSessionCommands;
|
|
23
|
+
}
|
|
10
24
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
timeoutCmds,
|
|
16
|
-
findCmds,
|
|
17
|
-
logCmds,
|
|
18
|
-
eventCmds,
|
|
19
|
-
// add other command types here
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export default commands;
|
|
25
|
+
/**
|
|
26
|
+
* @template [T={}]
|
|
27
|
+
* @typedef {import('../driver').BaseDriverBase<T>} BaseDriverBase
|
|
28
|
+
*/
|
|
@@ -1,38 +1,65 @@
|
|
|
1
|
+
/* eslint-disable require-await */
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
1
4
|
import _ from 'lodash';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {FindBase} Base
|
|
9
|
+
* @returns {LogBase}
|
|
10
|
+
*/
|
|
11
|
+
export function LogMixin (Base) {
|
|
12
|
+
/**
|
|
13
|
+
* @implements {ILogCommands}
|
|
14
|
+
*/
|
|
15
|
+
class LogCommands extends Base {
|
|
16
|
+
/**
|
|
17
|
+
* XXX: dubious
|
|
18
|
+
* @type {Record<string,LogType<Driver>>}
|
|
19
|
+
*/
|
|
20
|
+
supportedLogTypes;
|
|
21
|
+
|
|
22
|
+
async getLogTypes () {
|
|
23
|
+
this.log.debug('Retrieving supported log types');
|
|
24
|
+
return _.keys(this.supportedLogTypes);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @this {Driver}
|
|
29
|
+
*/
|
|
30
|
+
async getLog (logType) {
|
|
31
|
+
this.log.debug(`Retrieving '${logType}' logs`);
|
|
32
|
+
|
|
33
|
+
if (!(await this.getLogTypes()).includes(logType)) {
|
|
34
|
+
const logsTypesWithDescriptions = _.reduce(
|
|
35
|
+
this.supportedLogTypes,
|
|
36
|
+
(acc, value, key) => {
|
|
37
|
+
acc[key] = value.description;
|
|
38
|
+
return acc;
|
|
39
|
+
},
|
|
40
|
+
{},
|
|
41
|
+
);
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Unsupported log type '${logType}'. ` +
|
|
44
|
+
`Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return await this.supportedLogTypes[logType].getter(this);
|
|
49
|
+
}
|
|
31
50
|
}
|
|
51
|
+
return LogCommands;
|
|
52
|
+
}
|
|
53
|
+
|
|
32
54
|
|
|
33
|
-
|
|
34
|
-
}
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {import('@appium/types').LogCommands} ILogCommands
|
|
57
|
+
* @typedef {import('@appium/types').Driver} Driver
|
|
58
|
+
* @typedef {import('./find').FindBase} FindBase
|
|
59
|
+
* @typedef {import('../driver').BaseDriverBase<import('@appium/types').TimeoutCommands & import('@appium/types').EventCommands & import('@appium/types').FindCommands & ILogCommands>} LogBase
|
|
60
|
+
*/
|
|
35
61
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
62
|
+
/**
|
|
63
|
+
* @template T
|
|
64
|
+
* @typedef {import('@appium/types').LogType<T>} LogType
|
|
65
|
+
*/
|
|
@@ -1,153 +1,51 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
1
2
|
/* eslint-disable require-await */
|
|
3
|
+
// @ts-check
|
|
2
4
|
import _ from 'lodash';
|
|
3
|
-
import { errors } from '../../protocol';
|
|
4
|
-
import { util } from '@appium/support';
|
|
5
|
-
import {
|
|
6
|
-
processCapabilities, promoteAppiumOptions, APPIUM_OPTS_CAP, PREFIXED_APPIUM_OPTS_CAP,
|
|
7
|
-
} from '../capabilities';
|
|
8
|
-
import { isW3cCaps } from '../../helpers/capabilities';
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.originalCaps = _.cloneDeep(originalCaps);
|
|
32
|
-
this.log.debug(`Creating session with W3C capabilities: ${JSON.stringify(originalCaps, null, 2)}`);
|
|
33
|
-
|
|
34
|
-
let caps;
|
|
35
|
-
try {
|
|
36
|
-
caps = processCapabilities(originalCaps, this.desiredCapConstraints, this.shouldValidateCaps);
|
|
37
|
-
if (caps[APPIUM_OPTS_CAP]) {
|
|
38
|
-
this.log.debug(`Found ${PREFIXED_APPIUM_OPTS_CAP} capability present; will promote items inside to caps`);
|
|
39
|
-
caps = promoteAppiumOptions(caps);
|
|
40
|
-
}
|
|
41
|
-
caps = fixCaps(caps, this.desiredCapConstraints, this.log);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
throw new errors.SessionNotCreatedError(e.message);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.validateDesiredCaps(caps);
|
|
47
|
-
|
|
48
|
-
this.sessionId = util.uuidV4();
|
|
49
|
-
this.caps = caps;
|
|
50
|
-
this.opts = _.cloneDeep(this.initialOpts);
|
|
51
|
-
|
|
52
|
-
// merge caps onto opts so we don't need to worry about what's where
|
|
53
|
-
Object.assign(this.opts, this.caps);
|
|
54
|
-
|
|
55
|
-
// deal with resets
|
|
56
|
-
// some people like to do weird things by setting noReset and fullReset
|
|
57
|
-
// both to true, but this is misguided and strange, so error here instead
|
|
58
|
-
if (this.opts.noReset && this.opts.fullReset) {
|
|
59
|
-
throw new Error("The 'noReset' and 'fullReset' capabilities are mutually " +
|
|
60
|
-
'exclusive and should not both be set to true. You ' +
|
|
61
|
-
"probably meant to just use 'fullReset' on its own");
|
|
62
|
-
}
|
|
63
|
-
if (this.opts.noReset === true) {
|
|
64
|
-
this.opts.fullReset = false;
|
|
65
|
-
}
|
|
66
|
-
if (this.opts.fullReset === true) {
|
|
67
|
-
this.opts.noReset = false;
|
|
68
|
-
}
|
|
69
|
-
this.opts.fastReset = !this.opts.fullReset && !this.opts.noReset;
|
|
70
|
-
this.opts.skipUninstall = this.opts.fastReset || this.opts.noReset;
|
|
71
|
-
|
|
72
|
-
// Prevents empty string caps so we don't need to test it everywhere
|
|
73
|
-
if (typeof this.opts.app === 'string' && this.opts.app.trim() === '') {
|
|
74
|
-
this.opts.app = null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!_.isUndefined(this.caps.newCommandTimeout)) {
|
|
78
|
-
this.newCommandTimeoutMs = (this.caps.newCommandTimeout * 1000);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.log.info(`Session created with session id: ${this.sessionId}`);
|
|
82
|
-
|
|
83
|
-
return [this.sessionId, caps];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
commands.getSessions = async function getSessions () {
|
|
87
|
-
let ret = [];
|
|
88
|
-
|
|
89
|
-
if (this.sessionId) {
|
|
90
|
-
ret.push({
|
|
91
|
-
id: this.sessionId,
|
|
92
|
-
capabilities: this.caps
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return ret;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
commands.getSession = async function getSession () {
|
|
100
|
-
if (this.caps.eventTimings) {
|
|
101
|
-
return Object.assign({}, this.caps, {events: this.eventHistory});
|
|
102
|
-
}
|
|
103
|
-
return this.caps;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
commands.deleteSession = async function deleteSession (/* sessionId */) {
|
|
107
|
-
this.clearNewCommandTimeout();
|
|
108
|
-
if (this.isCommandsQueueEnabled && this.commandsQueueGuard.isBusy()) {
|
|
109
|
-
// simple hack to release pending commands if they exist
|
|
110
|
-
for (const key of _.keys(this.commandsQueueGuard.queues)) {
|
|
111
|
-
this.commandsQueueGuard.queues[key] = [];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
this.sessionId = null;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
function fixCaps (originalCaps, desiredCapConstraints = {}, log) {
|
|
118
|
-
let caps = _.clone(originalCaps);
|
|
119
|
-
|
|
120
|
-
// boolean capabilities can be passed in as strings 'false' and 'true'
|
|
121
|
-
// which we want to translate into boolean values
|
|
122
|
-
let booleanCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isBoolean === true));
|
|
123
|
-
for (let cap of booleanCaps) {
|
|
124
|
-
let value = originalCaps[cap];
|
|
125
|
-
if (_.isString(value)) {
|
|
126
|
-
value = value.toLowerCase();
|
|
127
|
-
if (value === 'true' || value === 'false') {
|
|
128
|
-
log.warn(`Capability '${cap}' changed from string to boolean. This may cause unexpected behavior`);
|
|
129
|
-
caps[cap] = (value === 'true');
|
|
6
|
+
/**
|
|
7
|
+
* @param {SettingsBase} Base
|
|
8
|
+
* @returns {SessionBase}
|
|
9
|
+
*/
|
|
10
|
+
export function SessionMixin (Base) {
|
|
11
|
+
/**
|
|
12
|
+
* @implements {ISessionCommands}
|
|
13
|
+
*/
|
|
14
|
+
class SessionCommands extends Base {
|
|
15
|
+
/**
|
|
16
|
+
* @returns {Promise<MultiSessionData[]>}
|
|
17
|
+
*/
|
|
18
|
+
async getSessions () {
|
|
19
|
+
let ret = [];
|
|
20
|
+
|
|
21
|
+
if (this.sessionId) {
|
|
22
|
+
ret.push({
|
|
23
|
+
id: this.sessionId,
|
|
24
|
+
capabilities: this.caps,
|
|
25
|
+
});
|
|
130
26
|
}
|
|
27
|
+
|
|
28
|
+
return ret;
|
|
131
29
|
}
|
|
132
|
-
}
|
|
133
30
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
let newValue = parseInt(value, 10);
|
|
141
|
-
if (value !== `${newValue}`) {
|
|
142
|
-
newValue = parseFloat(value);
|
|
31
|
+
/**
|
|
32
|
+
* @returns {Promise<SingularSessionData>}
|
|
33
|
+
*/
|
|
34
|
+
async getSession () {
|
|
35
|
+
if (this.caps.eventTimings) {
|
|
36
|
+
return {...this.caps, events: this.eventHistory};
|
|
143
37
|
}
|
|
144
|
-
|
|
145
|
-
caps[cap] = newValue;
|
|
38
|
+
return this.caps;
|
|
146
39
|
}
|
|
147
40
|
}
|
|
148
41
|
|
|
149
|
-
return
|
|
42
|
+
return SessionCommands;
|
|
150
43
|
}
|
|
151
44
|
|
|
152
|
-
|
|
153
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {import('@appium/types').SessionCommands} ISessionCommands
|
|
47
|
+
* @typedef {import('@appium/types').SingularSessionData} SingularSessionData
|
|
48
|
+
* @typedef {import('@appium/types').MultiSessionData} MultiSessionData
|
|
49
|
+
* @typedef {import('./settings').SettingsBase} SettingsBase
|
|
50
|
+
* @typedef {import('../driver').BaseDriverBase<import('@appium/types').TimeoutCommands & import('@appium/types').EventCommands & import('@appium/types').FindCommands & import('@appium/types').LogCommands & import('@appium/types').SettingsCommands & ISessionCommands>} SessionBase
|
|
51
|
+
*/
|
|
@@ -1,17 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {ReturnType<import('./log').LogMixin>} Base
|
|
6
|
+
* @returns {SettingsBase}
|
|
7
|
+
*/
|
|
8
|
+
export function SettingsMixin (Base) {
|
|
9
|
+
/**
|
|
10
|
+
* @implements {ISettingsCommands}
|
|
11
|
+
*/
|
|
12
|
+
class SettingsCommands extends Base {
|
|
13
|
+
|
|
14
|
+
async updateSettings (newSettings) {
|
|
15
|
+
if (!this.settings) {
|
|
16
|
+
this.log.errorAndThrow('Cannot update settings; settings object not found');
|
|
17
|
+
}
|
|
18
|
+
return await this.settings.update(newSettings);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getSettings () {
|
|
22
|
+
if (!this.settings) {
|
|
23
|
+
this.log.errorAndThrow('Cannot get settings; settings object not found');
|
|
24
|
+
}
|
|
25
|
+
return await this.settings.getSettings();
|
|
26
|
+
}
|
|
9
27
|
|
|
10
|
-
commands.getSettings = async function getSettings () {
|
|
11
|
-
if (!this.settings) {
|
|
12
|
-
this.log.errorAndThrow('Cannot get settings; settings object not found');
|
|
13
28
|
}
|
|
14
|
-
return await this.settings.getSettings();
|
|
15
|
-
};
|
|
16
29
|
|
|
17
|
-
|
|
30
|
+
return SettingsCommands;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {import('@appium/types').SettingsCommands} ISettingsCommands
|
|
35
|
+
* @typedef {import('./log').LogBase} LogBase
|
|
36
|
+
* @typedef {import('../driver').BaseDriverBase<import('@appium/types').TimeoutCommands & import('@appium/types').EventCommands & import('@appium/types').FindCommands & import('@appium/types').LogCommands & ISettingsCommands>} SettingsBase
|
|
37
|
+
*/
|