@appium/base-driver 8.3.1 → 8.4.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.
Files changed (115) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +80 -0
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -0
  3. package/build/lib/basedriver/capabilities.js +11 -10
  4. package/build/lib/basedriver/commands/event.d.ts +9 -0
  5. package/build/lib/basedriver/commands/event.d.ts.map +1 -0
  6. package/build/lib/basedriver/commands/event.js +21 -21
  7. package/build/lib/basedriver/commands/find.d.ts +11 -0
  8. package/build/lib/basedriver/commands/find.d.ts.map +1 -0
  9. package/build/lib/basedriver/commands/find.js +44 -37
  10. package/build/lib/basedriver/commands/index.d.ts +8 -0
  11. package/build/lib/basedriver/commands/index.d.ts.map +1 -0
  12. package/build/lib/basedriver/commands/index.js +17 -14
  13. package/build/lib/basedriver/commands/log.d.ts +12 -0
  14. package/build/lib/basedriver/commands/log.d.ts.map +1 -0
  15. package/build/lib/basedriver/commands/log.js +24 -26
  16. package/build/lib/basedriver/commands/session.d.ts +11 -0
  17. package/build/lib/basedriver/commands/session.d.ts.map +1 -0
  18. package/build/lib/basedriver/commands/session.js +21 -147
  19. package/build/lib/basedriver/commands/settings.d.ts +10 -0
  20. package/build/lib/basedriver/commands/settings.d.ts.map +1 -0
  21. package/build/lib/basedriver/commands/settings.js +19 -17
  22. package/build/lib/basedriver/commands/timeout.d.ts +8 -0
  23. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -0
  24. package/build/lib/basedriver/commands/timeout.js +118 -137
  25. package/build/lib/basedriver/core.d.ts +235 -0
  26. package/build/lib/basedriver/core.d.ts.map +1 -0
  27. package/build/lib/basedriver/core.js +283 -0
  28. package/build/lib/basedriver/desired-caps.d.ts +5 -0
  29. package/build/lib/basedriver/desired-caps.d.ts.map +1 -0
  30. package/build/lib/basedriver/desired-caps.js +1 -1
  31. package/build/lib/basedriver/device-settings.d.ts +32 -0
  32. package/build/lib/basedriver/device-settings.d.ts.map +1 -0
  33. package/build/lib/basedriver/device-settings.js +19 -11
  34. package/build/lib/basedriver/driver.d.ts +83 -0
  35. package/build/lib/basedriver/driver.d.ts.map +1 -0
  36. package/build/lib/basedriver/driver.js +100 -266
  37. package/build/lib/basedriver/helpers.d.ts +132 -0
  38. package/build/lib/basedriver/helpers.d.ts.map +1 -0
  39. package/build/lib/basedriver/helpers.js +17 -1
  40. package/build/lib/basedriver/logger.d.ts +3 -0
  41. package/build/lib/basedriver/logger.d.ts.map +1 -0
  42. package/build/lib/constants.d.ts +9 -0
  43. package/build/lib/constants.d.ts.map +1 -0
  44. package/build/lib/express/crash.d.ts +3 -0
  45. package/build/lib/express/crash.d.ts.map +1 -0
  46. package/build/lib/express/express-logging.d.ts +3 -0
  47. package/build/lib/express/express-logging.d.ts.map +1 -0
  48. package/build/lib/express/idempotency.d.ts +2 -0
  49. package/build/lib/express/idempotency.d.ts.map +1 -0
  50. package/build/lib/express/logger.d.ts +3 -0
  51. package/build/lib/express/logger.d.ts.map +1 -0
  52. package/build/lib/express/middleware.d.ts +9 -0
  53. package/build/lib/express/middleware.d.ts.map +1 -0
  54. package/build/lib/express/server.d.ts +10 -0
  55. package/build/lib/express/server.d.ts.map +1 -0
  56. package/build/lib/express/static.d.ts +6 -0
  57. package/build/lib/express/static.d.ts.map +1 -0
  58. package/build/lib/express/websocket.d.ts +64 -0
  59. package/build/lib/express/websocket.d.ts.map +1 -0
  60. package/build/lib/helpers/capabilities.d.ts +13 -0
  61. package/build/lib/helpers/capabilities.d.ts.map +1 -0
  62. package/build/lib/helpers/capabilities.js +41 -1
  63. package/build/lib/index.d.ts +183 -0
  64. package/build/lib/index.d.ts.map +1 -0
  65. package/build/lib/index.js +40 -20
  66. package/build/lib/jsonwp-proxy/protocol-converter.d.ts +48 -0
  67. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -0
  68. package/build/lib/jsonwp-proxy/proxy.d.ts +41 -0
  69. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -0
  70. package/build/lib/jsonwp-status/status.d.ts +159 -0
  71. package/build/lib/jsonwp-status/status.d.ts.map +1 -0
  72. package/build/lib/protocol/errors.d.ts +310 -0
  73. package/build/lib/protocol/errors.d.ts.map +1 -0
  74. package/build/lib/protocol/errors.js +81 -2
  75. package/build/lib/protocol/helpers.d.ts +22 -0
  76. package/build/lib/protocol/helpers.d.ts.map +1 -0
  77. package/build/lib/protocol/index.d.ts +16 -0
  78. package/build/lib/protocol/index.d.ts.map +1 -0
  79. package/build/lib/protocol/index.js +7 -7
  80. package/build/lib/protocol/protocol.d.ts +11 -0
  81. package/build/lib/protocol/protocol.d.ts.map +1 -0
  82. package/build/lib/protocol/protocol.js +2 -6
  83. package/build/lib/protocol/routes.d.ts +6 -0
  84. package/build/lib/protocol/routes.d.ts.map +1 -0
  85. package/build/lib/protocol/routes.js +17 -1
  86. package/build/lib/protocol/validators.d.ts +8 -0
  87. package/build/lib/protocol/validators.d.ts.map +1 -0
  88. package/build/test/basedriver/driver-tests.js +30 -3
  89. package/build/test/unit/basedriver/commands/event.spec.js +7 -7
  90. package/build/test/unit/basedriver/commands/log.spec.js +31 -24
  91. package/build/test/unit/basedriver/timeout.spec.js +1 -1
  92. package/build/test/unit/protocol/routes.spec.js +2 -2
  93. package/build/tsconfig.tsbuildinfo +1 -0
  94. package/lib/basedriver/capabilities.js +49 -10
  95. package/lib/basedriver/commands/event.js +49 -31
  96. package/lib/basedriver/commands/find.js +108 -43
  97. package/lib/basedriver/commands/index.js +25 -19
  98. package/lib/basedriver/commands/log.js +60 -33
  99. package/lib/basedriver/commands/session.js +39 -141
  100. package/lib/basedriver/commands/settings.js +33 -13
  101. package/lib/basedriver/commands/timeout.js +153 -153
  102. package/lib/basedriver/core.js +497 -0
  103. package/lib/basedriver/desired-caps.js +1 -1
  104. package/lib/basedriver/device-settings.js +47 -12
  105. package/lib/basedriver/driver.js +273 -395
  106. package/lib/basedriver/helpers.js +18 -2
  107. package/lib/helpers/capabilities.js +60 -1
  108. package/lib/index.js +16 -12
  109. package/lib/protocol/errors.js +42 -42
  110. package/lib/protocol/index.js +4 -4
  111. package/lib/protocol/protocol.js +1 -3
  112. package/lib/protocol/routes.js +9 -0
  113. package/package.json +10 -9
  114. package/test/basedriver/driver-tests.js +31 -2
  115. package/index.d.ts +0 -386
@@ -1,51 +1,116 @@
1
- const commands = {}, helpers = {}, extensions = {};
1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable require-await */
3
+ // @ts-check
4
+ import {errors} from '../../protocol';
2
5
 
3
-
4
- // Override the following function for your own driver, and the rest is taken
5
- // care of!
6
-
7
- // helpers.findElOrEls = async function (strategy, selector, mult, context) {}
8
- // strategy: locator strategy
9
- // selector: the actual selector for finding an element
10
- // mult: multiple elements or just one?
11
- // context: finding an element from the root context? or starting from another element
12
- //
13
- // Returns an object which adheres to the way the JSON Wire Protocol represents elements:
14
- // { ELEMENT: # } eg: { ELEMENT: 3 } or { ELEMENT: 1.023 }
15
-
16
- helpers.findElOrElsWithProcessing = async function findElOrElsWithProcessing (strategy, selector, mult, context) {
17
- this.validateLocatorStrategy(strategy);
18
- try {
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
- commands.findElement = async function findElement (strategy, selector) {
33
- return await this.findElOrElsWithProcessing(strategy, selector, false);
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
- commands.findElements = async function findElements (strategy, selector) {
37
- return await this.findElOrElsWithProcessing(strategy, selector, true);
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
- commands.findElementFromElement = async function findElementFromElement (strategy, selector, elementId) {
41
- return await this.findElOrElsWithProcessing(strategy, selector, false, elementId);
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
- commands.findElementsFromElement = async function findElementsFromElement (strategy, selector, elementId) {
45
- return await this.findElOrElsWithProcessing(strategy, selector, true, elementId);
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
- Object.assign(extensions, commands, helpers);
50
- export { commands, helpers };
51
- export default extensions;
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
- import sessionCmds from './session';
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
- let commands = {};
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
- Object.assign(
12
- commands,
13
- sessionCmds,
14
- settingsCmds,
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
- const commands = {}, helpers = {}, extensions = {};
4
-
5
- // override in sub-classes, with appropriate logs
6
- // in the form of
7
- // {
8
- // type: {
9
- // description: 'some useful text',
10
- // getter: () => {}, // some function that will be called to get the logs
11
- // }
12
- // }
13
- extensions.supportedLogTypes = {};
14
-
15
- // eslint-disable-next-line require-await
16
- commands.getLogTypes = async function getLogTypes () {
17
- this.log.debug('Retrieving supported log types');
18
- return _.keys(this.supportedLogTypes);
19
- };
20
-
21
- commands.getLog = async function getLog (logType) {
22
- this.log.debug(`Retrieving '${logType}' logs`);
23
-
24
- if (!(await this.getLogTypes()).includes(logType)) {
25
- const logsTypesWithDescriptions = _.reduce(this.supportedLogTypes, (acc, value, key) => {
26
- acc[key] = value.description;
27
- return acc;
28
- }, {});
29
- throw new Error(`Unsupported log type '${logType}'. ` +
30
- `Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`);
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
- return await this.supportedLogTypes[logType].getter(this);
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
- Object.assign(extensions, commands, helpers);
37
- export { commands, helpers};
38
- export default extensions;
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
- const commands = {};
11
-
12
- commands.createSession = async function createSession (w3cCapabilities1, w3cCapabilities2, w3cCapabilities) {
13
- if (this.sessionId !== null) {
14
- throw new errors.SessionNotCreatedError('Cannot create a new session while one is in progress');
15
- }
16
-
17
- this.log.debug();
18
-
19
- // Historically the first two arguments were reserved for JSONWP capabilities.
20
- // Appium 2 has dropped the support of these, so now we only accept capability
21
- // objects in W3C format and thus allow any of the three arguments to represent
22
- // the latter.
23
- const originalCaps = [w3cCapabilities, w3cCapabilities1, w3cCapabilities2].find(isW3cCaps);
24
- if (!originalCaps) {
25
- throw new errors.SessionNotCreatedError('Appium only supports W3C-style capability objects. ' +
26
- 'Your client is sending an older capabilities format. Please update your client library.');
27
- }
28
-
29
- this.setProtocolW3C();
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
- // int capabilities are often sent in as strings by frameworks
135
- let intCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isNumber === true));
136
- for (let cap of intCaps) {
137
- let value = originalCaps[cap];
138
- if (_.isString(value) && !isNaN(value)) {
139
- value = value.trim();
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
- log.warn(`Capability '${cap}' changed from string ('${value}') to integer (${newValue}). This may cause unexpected behavior`);
145
- caps[cap] = newValue;
38
+ return this.caps;
146
39
  }
147
40
  }
148
41
 
149
- return caps;
42
+ return SessionCommands;
150
43
  }
151
44
 
152
- export default commands;
153
- export { promoteAppiumOptions };
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
- const commands = {};
1
+ // @ts-check
2
2
 
3
- commands.updateSettings = async function updateSettings (newSettings) {
4
- if (!this.settings) {
5
- this.log.errorAndThrow('Cannot update settings; settings object not found');
6
- }
7
- return await this.settings.update(newSettings);
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
- export default commands;
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
+ */