@appium/base-driver 8.2.4 → 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 (206) 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 +12 -13
  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 -23
  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 +41 -43
  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 -16
  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 +23 -30
  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 -158
  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 +18 -22
  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 -144
  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 +2 -4
  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 +33 -15
  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 +104 -257
  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 +24 -10
  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/basedriver/logger.js +2 -4
  43. package/build/lib/constants.d.ts +9 -0
  44. package/build/lib/constants.d.ts.map +1 -0
  45. package/build/lib/constants.js +2 -4
  46. package/build/lib/express/crash.d.ts +3 -0
  47. package/build/lib/express/crash.d.ts.map +1 -0
  48. package/build/lib/express/crash.js +2 -4
  49. package/build/lib/express/express-logging.d.ts +3 -0
  50. package/build/lib/express/express-logging.d.ts.map +1 -0
  51. package/build/lib/express/express-logging.js +3 -5
  52. package/build/lib/express/idempotency.d.ts +2 -0
  53. package/build/lib/express/idempotency.d.ts.map +1 -0
  54. package/build/lib/express/idempotency.js +3 -5
  55. package/build/lib/express/logger.d.ts +3 -0
  56. package/build/lib/express/logger.d.ts.map +1 -0
  57. package/build/lib/express/logger.js +2 -4
  58. package/build/lib/express/middleware.d.ts +9 -0
  59. package/build/lib/express/middleware.d.ts.map +1 -0
  60. package/build/lib/express/middleware.js +2 -4
  61. package/build/lib/express/server.d.ts +10 -0
  62. package/build/lib/express/server.d.ts.map +1 -0
  63. package/build/lib/express/server.js +2 -4
  64. package/build/lib/express/static.d.ts +6 -0
  65. package/build/lib/express/static.d.ts.map +1 -0
  66. package/build/lib/express/static.js +2 -4
  67. package/build/lib/express/websocket.d.ts +64 -0
  68. package/build/lib/express/websocket.d.ts.map +1 -0
  69. package/build/lib/express/websocket.js +2 -4
  70. package/build/lib/helpers/capabilities.d.ts +13 -0
  71. package/build/lib/helpers/capabilities.d.ts.map +1 -0
  72. package/build/lib/helpers/capabilities.js +77 -0
  73. package/build/lib/index.d.ts +183 -0
  74. package/build/lib/index.d.ts.map +1 -0
  75. package/build/lib/index.js +41 -25
  76. package/build/lib/jsonwp-proxy/protocol-converter.d.ts +48 -0
  77. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -0
  78. package/build/lib/jsonwp-proxy/protocol-converter.js +19 -15
  79. package/build/lib/jsonwp-proxy/proxy.d.ts +41 -0
  80. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -0
  81. package/build/lib/jsonwp-proxy/proxy.js +20 -15
  82. package/build/lib/jsonwp-status/status.d.ts +159 -0
  83. package/build/lib/jsonwp-status/status.d.ts.map +1 -0
  84. package/build/lib/jsonwp-status/status.js +2 -4
  85. package/build/lib/protocol/errors.d.ts +310 -0
  86. package/build/lib/protocol/errors.d.ts.map +1 -0
  87. package/build/lib/protocol/errors.js +82 -5
  88. package/build/lib/protocol/helpers.d.ts +22 -0
  89. package/build/lib/protocol/helpers.d.ts.map +1 -0
  90. package/build/lib/protocol/helpers.js +2 -4
  91. package/build/lib/protocol/index.d.ts +16 -0
  92. package/build/lib/protocol/index.d.ts.map +1 -0
  93. package/build/lib/protocol/index.js +8 -10
  94. package/build/lib/protocol/protocol.d.ts +11 -0
  95. package/build/lib/protocol/protocol.d.ts.map +1 -0
  96. package/build/lib/protocol/protocol.js +38 -35
  97. package/build/lib/protocol/routes.d.ts +6 -0
  98. package/build/lib/protocol/routes.d.ts.map +1 -0
  99. package/build/lib/protocol/routes.js +84 -4
  100. package/build/lib/protocol/validators.d.ts +8 -0
  101. package/build/lib/protocol/validators.d.ts.map +1 -0
  102. package/build/lib/protocol/validators.js +2 -4
  103. package/build/test/basedriver/README.md +5 -0
  104. package/build/test/basedriver/driver-e2e-tests.js +2 -4
  105. package/build/test/basedriver/driver-tests.js +41 -19
  106. package/build/test/basedriver/index.js +2 -4
  107. package/build/test/e2e/basedriver/driver.e2e.spec.js +15 -0
  108. package/build/test/e2e/basedriver/helpers.e2e.spec.js +192 -0
  109. package/build/test/e2e/basedriver/websockets.e2e.spec.js +82 -0
  110. package/build/test/e2e/express/server.e2e.spec.js +159 -0
  111. package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +59 -0
  112. package/build/test/e2e/protocol/fake-driver.js +163 -0
  113. package/build/test/e2e/protocol/helpers.js +25 -0
  114. package/build/test/e2e/protocol/protocol.e2e.spec.js +1186 -0
  115. package/build/test/helpers.js +2 -4
  116. package/build/test/unit/basedriver/capabilities.spec.js +672 -0
  117. package/build/test/unit/basedriver/capability.spec.js +353 -0
  118. package/build/test/unit/basedriver/commands/event.spec.js +110 -0
  119. package/build/test/unit/basedriver/commands/log.spec.js +92 -0
  120. package/build/test/unit/basedriver/driver.spec.js +15 -0
  121. package/build/test/unit/basedriver/helpers.spec.js +151 -0
  122. package/build/test/unit/basedriver/timeout.spec.js +135 -0
  123. package/build/test/unit/express/server.spec.js +155 -0
  124. package/build/test/unit/express/static.spec.js +26 -0
  125. package/build/test/unit/jsonwp-proxy/mock-request.js +91 -0
  126. package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +171 -0
  127. package/build/test/unit/jsonwp-proxy/proxy.spec.js +292 -0
  128. package/build/test/unit/jsonwp-proxy/url.spec.js +165 -0
  129. package/build/test/unit/jsonwp-status/status.spec.js +34 -0
  130. package/build/test/unit/protocol/errors.spec.js +390 -0
  131. package/build/test/unit/protocol/routes.spec.js +80 -0
  132. package/build/test/unit/protocol/validator.spec.js +149 -0
  133. package/build/tsconfig.tsbuildinfo +1 -0
  134. package/lib/basedriver/capabilities.js +49 -10
  135. package/lib/basedriver/commands/event.js +49 -31
  136. package/lib/basedriver/commands/find.js +107 -45
  137. package/lib/basedriver/commands/index.js +25 -19
  138. package/lib/basedriver/commands/log.js +59 -34
  139. package/lib/basedriver/commands/session.js +39 -142
  140. package/lib/basedriver/commands/settings.js +32 -14
  141. package/lib/basedriver/commands/timeout.js +153 -154
  142. package/lib/basedriver/core.js +497 -0
  143. package/lib/basedriver/desired-caps.js +1 -1
  144. package/lib/basedriver/device-settings.js +57 -13
  145. package/lib/basedriver/driver.js +277 -375
  146. package/lib/basedriver/helpers.js +31 -13
  147. package/lib/express/express-logging.js +1 -1
  148. package/lib/express/idempotency.js +1 -1
  149. package/lib/helpers/capabilities.js +84 -0
  150. package/lib/index.js +17 -13
  151. package/lib/jsonwp-proxy/protocol-converter.js +14 -13
  152. package/lib/jsonwp-proxy/proxy.js +16 -12
  153. package/lib/protocol/errors.js +42 -42
  154. package/lib/protocol/index.js +4 -4
  155. package/lib/protocol/protocol.js +35 -32
  156. package/lib/protocol/routes.js +69 -1
  157. package/package.json +37 -24
  158. package/test/basedriver/README.md +5 -0
  159. package/test/basedriver/driver-e2e-tests.js +1 -1
  160. package/test/basedriver/driver-tests.js +43 -9
  161. package/build/lib/protocol/sessions-cache.js +0 -88
  162. package/build/test/basedriver/capabilities-specs.js +0 -632
  163. package/build/test/basedriver/capability-specs.js +0 -396
  164. package/build/test/basedriver/commands/event-specs.js +0 -112
  165. package/build/test/basedriver/commands/log-specs.js +0 -80
  166. package/build/test/basedriver/driver-e2e-specs.js +0 -17
  167. package/build/test/basedriver/driver-specs.js +0 -17
  168. package/build/test/basedriver/helpers-e2e-specs.js +0 -194
  169. package/build/test/basedriver/helpers-specs.js +0 -153
  170. package/build/test/basedriver/timeout-specs.js +0 -139
  171. package/build/test/basedriver/websockets-e2e-specs.js +0 -84
  172. package/build/test/express/server-e2e-specs.js +0 -156
  173. package/build/test/express/server-specs.js +0 -151
  174. package/build/test/express/static-specs.js +0 -23
  175. package/build/test/jsonwp-proxy/mock-request.js +0 -93
  176. package/build/test/jsonwp-proxy/protocol-converter-specs.js +0 -173
  177. package/build/test/jsonwp-proxy/proxy-e2e-specs.js +0 -61
  178. package/build/test/jsonwp-proxy/proxy-specs.js +0 -294
  179. package/build/test/jsonwp-proxy/url-specs.js +0 -167
  180. package/build/test/jsonwp-status/status-specs.js +0 -36
  181. package/build/test/protocol/errors-specs.js +0 -388
  182. package/build/test/protocol/fake-driver.js +0 -168
  183. package/build/test/protocol/helpers.js +0 -27
  184. package/build/test/protocol/protocol-e2e-specs.js +0 -1182
  185. package/build/test/protocol/routes-specs.js +0 -82
  186. package/build/test/protocol/validator-specs.js +0 -151
  187. package/index.d.ts +0 -386
  188. package/lib/protocol/sessions-cache.js +0 -74
  189. package/test/basedriver/capabilities-specs.js +0 -505
  190. package/test/basedriver/capability-specs.js +0 -409
  191. package/test/basedriver/commands/event-specs.js +0 -74
  192. package/test/basedriver/commands/log-specs.js +0 -70
  193. package/test/basedriver/driver-e2e-specs.js +0 -8
  194. package/test/basedriver/driver-specs.js +0 -8
  195. package/test/basedriver/fixtures/BadZippedApp.zip +0 -1
  196. package/test/basedriver/fixtures/FakeAndroidApp.apk +0 -1
  197. package/test/basedriver/fixtures/FakeAndroidApp.asd +0 -0
  198. package/test/basedriver/fixtures/FakeIOSApp.app +0 -1
  199. package/test/basedriver/fixtures/FakeIOSApp.app.zip +0 -0
  200. package/test/basedriver/fixtures/FakeIOSApp.ipa +0 -0
  201. package/test/basedriver/fixtures/custom-element-finder-bad.js +0 -5
  202. package/test/basedriver/fixtures/custom-element-finder.js +0 -29
  203. package/test/basedriver/helpers-e2e-specs.js +0 -187
  204. package/test/basedriver/helpers-specs.js +0 -137
  205. package/test/basedriver/timeout-specs.js +0 -133
  206. package/test/basedriver/websockets-e2e-specs.js +0 -75
@@ -1,54 +1,116 @@
1
- import log from '../logger';
1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable require-await */
3
+ // @ts-check
4
+ import {errors} from '../../protocol';
2
5
 
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);
22
+ }
3
23
 
4
- const commands = {}, helpers = {}, extensions = {};
5
-
24
+ /**
25
+ *
26
+ * @returns {Promise<Element[]>}
27
+ */
28
+ async findElements (strategy, selector) {
29
+ return await this.findElOrElsWithProcessing(strategy, selector, true);
30
+ }
6
31
 
7
- // Override the following function for your own driver, and the rest is taken
8
- // care of!
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
+ }
9
44
 
10
- // helpers.findElOrEls = async function (strategy, selector, mult, context) {}
11
- // strategy: locator strategy
12
- // selector: the actual selector for finding an element
13
- // mult: multiple elements or just one?
14
- // context: finding an element from the root context? or starting from another element
15
- //
16
- // Returns an object which adheres to the way the JSON Wire Protocol represents elements:
17
- // { ELEMENT: # } eg: { ELEMENT: 3 } or { ELEMENT: 1.023 }
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
+ }
18
72
 
19
- helpers.findElOrElsWithProcessing = async function findElOrElsWithProcessing (strategy, selector, mult, context) {
20
- this.validateLocatorStrategy(strategy);
21
- try {
22
- return await this.findElOrEls(strategy, selector, mult, context);
23
- } catch (err) {
24
- if (this.opts.printPageSourceOnFindFailure) {
25
- const src = await this.getPageSource();
26
- log.debug(`Error finding element${mult ? 's' : ''}: ${err.message}`);
27
- log.debug(`Page source requested through 'printPageSourceOnFindFailure':`);
28
- log.debug(src);
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
+ }
29
105
  }
30
- // still want the error to occur
31
- throw err;
32
106
  }
33
- };
34
-
35
- commands.findElement = async function findElement (strategy, selector) {
36
- return await this.findElOrElsWithProcessing(strategy, selector, false);
37
- };
38
-
39
- commands.findElements = async function findElements (strategy, selector) {
40
- return await this.findElOrElsWithProcessing(strategy, selector, true);
41
- };
42
-
43
- commands.findElementFromElement = async function findElementFromElement (strategy, selector, elementId) {
44
- return await this.findElOrElsWithProcessing(strategy, selector, false, elementId);
45
- };
46
-
47
- commands.findElementsFromElement = async function findElementsFromElement (strategy, selector, elementId) {
48
- return await this.findElOrElsWithProcessing(strategy, selector, true, elementId);
49
- };
50
107
 
108
+ return FindCommands;
109
+ }
51
110
 
52
- Object.assign(extensions, commands, helpers);
53
- export { commands, helpers };
54
- 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,40 +1,65 @@
1
- import log from '../logger';
1
+ /* eslint-disable require-await */
2
+ // @ts-check
3
+
2
4
  import _ from 'lodash';
3
5
 
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`);
4
32
 
5
- const commands = {}, helpers = {}, extensions = {};
6
-
7
- // override in sub-classes, with appropriate logs
8
- // in the form of
9
- // {
10
- // type: {
11
- // description: 'some useful text',
12
- // getter: () => {}, // some function that will be called to get the logs
13
- // }
14
- // }
15
- extensions.supportedLogTypes = {};
16
-
17
- // eslint-disable-next-line require-await
18
- commands.getLogTypes = async function getLogTypes () {
19
- log.debug('Retrieving supported log types');
20
- return _.keys(this.supportedLogTypes);
21
- };
22
-
23
- commands.getLog = async function getLog (logType) {
24
- log.debug(`Retrieving '${logType}' logs`);
25
-
26
- if (!(await this.getLogTypes()).includes(logType)) {
27
- const logsTypesWithDescriptions = _.reduce(this.supportedLogTypes, (acc, value, key) => {
28
- acc[key] = value.description;
29
- return acc;
30
- }, {});
31
- throw new Error(`Unsupported log type '${logType}'. ` +
32
- `Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`);
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
+ }
33
50
  }
51
+ return LogCommands;
52
+ }
53
+
34
54
 
35
- return await this.supportedLogTypes[logType].getter(this);
36
- };
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
+ */
37
61
 
38
- Object.assign(extensions, commands, helpers);
39
- export { commands, helpers};
40
- export default extensions;
62
+ /**
63
+ * @template T
64
+ * @typedef {import('@appium/types').LogType<T>} LogType
65
+ */
@@ -1,154 +1,51 @@
1
+ /* eslint-disable no-unused-vars */
1
2
  /* eslint-disable require-await */
3
+ // @ts-check
2
4
  import _ from 'lodash';
3
- import log from '../logger';
4
- import { errors } from '../../protocol';
5
- import { util } from '@appium/support';
6
- import { processCapabilities, promoteAppiumOptions, APPIUM_OPTS_CAP, PREFIXED_APPIUM_OPTS_CAP } from '../capabilities';
7
5
 
8
- let commands = {};
9
-
10
- // TODO: Remove jsonwpDesiredCapabilities and jsonwpRequiredCaps completely
11
- // since Appium 2.0 no longer supports them.
12
- commands.createSession = async function createSession (jsonwpDesiredCapabilities, jsonwpRequiredCaps, w3cCapabilities) {
13
- if (this.sessionId !== null) {
14
- throw new errors.SessionNotCreatedError('Cannot create a new session ' +
15
- 'while one is in progress');
16
- }
17
-
18
- log.debug();
19
-
20
- if (!w3cCapabilities) {
21
- throw new errors.SessionNotCreatedError('Appium only supports W3C-style capability objects. ' +
22
- 'Your client is sending an older capabilities format. Please update your client library.');
23
- }
24
-
25
- if (jsonwpDesiredCapabilities) {
26
- log.warn('Appium received (M)JSONWP desired capabilities in alongside the W3C capabilities; they will be ignored');
27
- }
28
-
29
- this.setProtocolW3C();
30
-
31
- this.originalCaps = _.cloneDeep(w3cCapabilities);
32
- log.debug(`Creating session with W3C capabilities: ${JSON.stringify(w3cCapabilities, null, 2)}`);
33
-
34
-
35
- let caps;
36
- try {
37
- caps = processCapabilities(w3cCapabilities, this.desiredCapConstraints, this.shouldValidateCaps);
38
- if (caps[APPIUM_OPTS_CAP]) {
39
- log.debug(`Found ${PREFIXED_APPIUM_OPTS_CAP} capability present; will promote items inside to caps`);
40
- caps = promoteAppiumOptions(caps);
41
- }
42
- caps = fixCaps(caps, this.desiredCapConstraints);
43
- } catch (e) {
44
- throw new errors.SessionNotCreatedError(e.message);
45
- }
46
-
47
- this.validateDesiredCaps(caps);
48
-
49
- this.sessionId = util.uuidV4();
50
- this.caps = caps;
51
- this.opts = _.cloneDeep(this.initialOpts);
52
-
53
- // merge caps onto opts so we don't need to worry about what's where
54
- Object.assign(this.opts, this.caps);
55
-
56
- // deal with resets
57
- // some people like to do weird things by setting noReset and fullReset
58
- // both to true, but this is misguided and strange, so error here instead
59
- if (this.opts.noReset && this.opts.fullReset) {
60
- throw new Error("The 'noReset' and 'fullReset' capabilities are mutually " +
61
- 'exclusive and should not both be set to true. You ' +
62
- "probably meant to just use 'fullReset' on its own");
63
- }
64
- if (this.opts.noReset === true) {
65
- this.opts.fullReset = false;
66
- }
67
- if (this.opts.fullReset === true) {
68
- this.opts.noReset = false;
69
- }
70
- this.opts.fastReset = !this.opts.fullReset && !this.opts.noReset;
71
- this.opts.skipUninstall = this.opts.fastReset || this.opts.noReset;
72
-
73
- // Prevents empty string caps so we don't need to test it everywhere
74
- if (typeof this.opts.app === 'string' && this.opts.app.trim() === '') {
75
- this.opts.app = null;
76
- }
77
-
78
- if (!_.isUndefined(this.caps.newCommandTimeout)) {
79
- this.newCommandTimeoutMs = (this.caps.newCommandTimeout * 1000);
80
- }
81
-
82
- log.info(`Session created with session id: ${this.sessionId}`);
83
-
84
- return [this.sessionId, caps];
85
- };
86
-
87
- commands.getSessions = async function getSessions () {
88
- let ret = [];
89
-
90
- if (this.sessionId) {
91
- ret.push({
92
- id: this.sessionId,
93
- capabilities: this.caps
94
- });
95
- }
96
-
97
- return ret;
98
- };
99
-
100
- commands.getSession = async function getSession () {
101
- if (this.caps.eventTimings) {
102
- return Object.assign({}, this.caps, {events: this.eventHistory});
103
- }
104
- return this.caps;
105
- };
106
-
107
- commands.deleteSession = async function deleteSession (/* sessionId */) {
108
- this.clearNewCommandTimeout();
109
- if (this.isCommandsQueueEnabled && this.commandsQueueGuard.isBusy()) {
110
- // simple hack to release pending commands if they exist
111
- for (const key of _.keys(this.commandsQueueGuard.queues)) {
112
- this.commandsQueueGuard.queues[key] = [];
113
- }
114
- }
115
- this.sessionId = null;
116
- };
117
-
118
- function fixCaps (originalCaps, desiredCapConstraints = {}) {
119
- let caps = _.clone(originalCaps);
120
-
121
- // boolean capabilities can be passed in as strings 'false' and 'true'
122
- // which we want to translate into boolean values
123
- let booleanCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isBoolean === true));
124
- for (let cap of booleanCaps) {
125
- let value = originalCaps[cap];
126
- if (_.isString(value)) {
127
- value = value.toLowerCase();
128
- if (value === 'true' || value === 'false') {
129
- log.warn(`Capability '${cap}' changed from string to boolean. This may cause unexpected behavior`);
130
- 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
+ });
131
26
  }
27
+
28
+ return ret;
132
29
  }
133
- }
134
30
 
135
- // int capabilities are often sent in as strings by frameworks
136
- let intCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isNumber === true));
137
- for (let cap of intCaps) {
138
- let value = originalCaps[cap];
139
- if (_.isString(value) && !isNaN(value)) {
140
- value = value.trim();
141
- let newValue = parseInt(value, 10);
142
- if (value !== `${newValue}`) {
143
- newValue = parseFloat(value);
31
+ /**
32
+ * @returns {Promise<SingularSessionData>}
33
+ */
34
+ async getSession () {
35
+ if (this.caps.eventTimings) {
36
+ return {...this.caps, events: this.eventHistory};
144
37
  }
145
- log.warn(`Capability '${cap}' changed from string ('${value}') to integer (${newValue}). This may cause unexpected behavior`);
146
- caps[cap] = newValue;
38
+ return this.caps;
147
39
  }
148
40
  }
149
41
 
150
- return caps;
42
+ return SessionCommands;
151
43
  }
152
44
 
153
- export default commands;
154
- 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,19 +1,37 @@
1
- import log from '../logger';
1
+ // @ts-check
2
2
 
3
- let commands = {};
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 {
4
13
 
5
- commands.updateSettings = async function updateSettings (newSettings) {
6
- if (!this.settings) {
7
- log.errorAndThrow('Cannot update settings; settings object not found');
8
- }
9
- return await this.settings.update(newSettings);
10
- };
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
+ }
11
27
 
12
- commands.getSettings = async function getSettings () {
13
- if (!this.settings) {
14
- log.errorAndThrow('Cannot get settings; settings object not found');
15
28
  }
16
- return await this.settings.getSettings();
17
- };
18
29
 
19
- 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
+ */