appium-android-driver 5.14.7 → 6.0.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 (192) hide show
  1. package/build/index.d.ts +282 -0
  2. package/build/index.d.ts.map +1 -0
  3. package/build/index.js.map +1 -0
  4. package/build/lib/commands/actions.d.ts +6 -224
  5. package/build/lib/commands/actions.d.ts.map +1 -1
  6. package/build/lib/commands/actions.js +306 -405
  7. package/build/lib/commands/actions.js.map +1 -1
  8. package/build/lib/commands/alert.d.ts +7 -9
  9. package/build/lib/commands/alert.d.ts.map +1 -1
  10. package/build/lib/commands/alert.js +24 -18
  11. package/build/lib/commands/alert.js.map +1 -1
  12. package/build/lib/commands/app-management.d.ts +7 -313
  13. package/build/lib/commands/app-management.d.ts.map +1 -1
  14. package/build/lib/commands/app-management.js +135 -293
  15. package/build/lib/commands/app-management.js.map +1 -1
  16. package/build/lib/commands/context.d.ts +8 -92
  17. package/build/lib/commands/context.d.ts.map +1 -1
  18. package/build/lib/commands/context.js +381 -439
  19. package/build/lib/commands/context.js.map +1 -1
  20. package/build/lib/commands/element.d.ts +8 -35
  21. package/build/lib/commands/element.d.ts.map +1 -1
  22. package/build/lib/commands/element.js +153 -136
  23. package/build/lib/commands/element.js.map +1 -1
  24. package/build/lib/commands/emu-console.d.ts +6 -48
  25. package/build/lib/commands/emu-console.d.ts.map +1 -1
  26. package/build/lib/commands/emu-console.js +19 -34
  27. package/build/lib/commands/emu-console.js.map +1 -1
  28. package/build/lib/commands/execute.d.ts +6 -5
  29. package/build/lib/commands/execute.d.ts.map +1 -1
  30. package/build/lib/commands/execute.js +77 -66
  31. package/build/lib/commands/execute.js.map +1 -1
  32. package/build/lib/commands/file-actions.d.ts +7 -128
  33. package/build/lib/commands/file-actions.d.ts.map +1 -1
  34. package/build/lib/commands/file-actions.js +183 -219
  35. package/build/lib/commands/file-actions.js.map +1 -1
  36. package/build/lib/commands/find.d.ts +8 -12
  37. package/build/lib/commands/find.d.ts.map +1 -1
  38. package/build/lib/commands/find.js +19 -23
  39. package/build/lib/commands/find.js.map +1 -1
  40. package/build/lib/commands/general.d.ts +9 -132
  41. package/build/lib/commands/general.d.ts.map +1 -1
  42. package/build/lib/commands/general.js +281 -312
  43. package/build/lib/commands/general.js.map +1 -1
  44. package/build/lib/commands/ime.d.ts +7 -10
  45. package/build/lib/commands/ime.d.ts.map +1 -1
  46. package/build/lib/commands/ime.js +47 -35
  47. package/build/lib/commands/ime.js.map +1 -1
  48. package/build/lib/commands/index.d.ts +27 -2
  49. package/build/lib/commands/index.d.ts.map +1 -1
  50. package/build/lib/commands/index.js +41 -19
  51. package/build/lib/commands/index.js.map +1 -1
  52. package/build/lib/commands/intent.d.ts +7 -417
  53. package/build/lib/commands/intent.d.ts.map +1 -1
  54. package/build/lib/commands/intent.js +104 -216
  55. package/build/lib/commands/intent.js.map +1 -1
  56. package/build/lib/commands/keyboard.d.ts +6 -5
  57. package/build/lib/commands/keyboard.d.ts.map +1 -1
  58. package/build/lib/commands/keyboard.js +16 -8
  59. package/build/lib/commands/keyboard.js.map +1 -1
  60. package/build/lib/commands/log.d.ts +7 -44
  61. package/build/lib/commands/log.d.ts.map +1 -1
  62. package/build/lib/commands/log.js +146 -108
  63. package/build/lib/commands/log.js.map +1 -1
  64. package/build/lib/commands/media-projection.d.ts +7 -143
  65. package/build/lib/commands/media-projection.d.ts.map +1 -1
  66. package/build/lib/commands/media-projection.js +113 -140
  67. package/build/lib/commands/media-projection.js.map +1 -1
  68. package/build/lib/commands/mixins.d.ts +740 -0
  69. package/build/lib/commands/mixins.d.ts.map +1 -0
  70. package/build/lib/commands/mixins.js +19 -0
  71. package/build/lib/commands/mixins.js.map +1 -0
  72. package/build/lib/commands/network.d.ts +7 -138
  73. package/build/lib/commands/network.d.ts.map +1 -1
  74. package/build/lib/commands/network.js +212 -254
  75. package/build/lib/commands/network.js.map +1 -1
  76. package/build/lib/commands/performance.d.ts +24 -70
  77. package/build/lib/commands/performance.d.ts.map +1 -1
  78. package/build/lib/commands/performance.js +144 -100
  79. package/build/lib/commands/performance.js.map +1 -1
  80. package/build/lib/commands/permissions.d.ts +8 -92
  81. package/build/lib/commands/permissions.d.ts.map +1 -1
  82. package/build/lib/commands/permissions.js +75 -87
  83. package/build/lib/commands/permissions.js.map +1 -1
  84. package/build/lib/commands/recordscreen.d.ts +7 -193
  85. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  86. package/build/lib/commands/recordscreen.js +151 -182
  87. package/build/lib/commands/recordscreen.js.map +1 -1
  88. package/build/lib/commands/shell.d.ts +7 -7
  89. package/build/lib/commands/shell.d.ts.map +1 -1
  90. package/build/lib/commands/shell.js +40 -33
  91. package/build/lib/commands/shell.js.map +1 -1
  92. package/build/lib/commands/streamscreen.d.ts +9 -103
  93. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  94. package/build/lib/commands/streamscreen.js +261 -218
  95. package/build/lib/commands/streamscreen.js.map +1 -1
  96. package/build/lib/commands/system-bars.d.ts +22 -90
  97. package/build/lib/commands/system-bars.d.ts.map +1 -1
  98. package/build/lib/commands/system-bars.js +76 -74
  99. package/build/lib/commands/system-bars.js.map +1 -1
  100. package/build/lib/commands/touch.d.ts +10 -29
  101. package/build/lib/commands/touch.d.ts.map +1 -1
  102. package/build/lib/commands/touch.js +301 -285
  103. package/build/lib/commands/touch.js.map +1 -1
  104. package/build/lib/commands/types.d.ts +978 -0
  105. package/build/lib/commands/types.d.ts.map +1 -0
  106. package/build/lib/commands/types.js +3 -0
  107. package/build/lib/commands/types.js.map +1 -0
  108. package/build/lib/constraints.d.ts +291 -0
  109. package/build/lib/constraints.d.ts.map +1 -0
  110. package/build/lib/constraints.js +300 -0
  111. package/build/lib/constraints.js.map +1 -0
  112. package/build/lib/driver.d.ts +68 -37
  113. package/build/lib/driver.d.ts.map +1 -1
  114. package/build/lib/driver.js +123 -80
  115. package/build/lib/driver.js.map +1 -1
  116. package/build/lib/helpers/android.d.ts +164 -0
  117. package/build/lib/helpers/android.d.ts.map +1 -0
  118. package/build/lib/helpers/android.js +819 -0
  119. package/build/lib/helpers/android.js.map +1 -0
  120. package/build/lib/helpers/index.d.ts +7 -0
  121. package/build/lib/helpers/index.d.ts.map +1 -0
  122. package/build/lib/helpers/index.js +29 -0
  123. package/build/lib/helpers/index.js.map +1 -0
  124. package/build/lib/helpers/types.d.ts +121 -0
  125. package/build/lib/helpers/types.d.ts.map +1 -0
  126. package/build/lib/helpers/types.js +3 -0
  127. package/build/lib/helpers/types.js.map +1 -0
  128. package/build/lib/helpers/unlock.d.ts +32 -0
  129. package/build/lib/helpers/unlock.d.ts.map +1 -0
  130. package/build/lib/helpers/unlock.js +273 -0
  131. package/build/lib/helpers/unlock.js.map +1 -0
  132. package/build/lib/helpers/webview.d.ts +74 -0
  133. package/build/lib/helpers/webview.d.ts.map +1 -0
  134. package/build/lib/helpers/webview.js +421 -0
  135. package/build/lib/helpers/webview.js.map +1 -0
  136. package/build/lib/index.d.ts +9 -0
  137. package/build/lib/index.d.ts.map +1 -0
  138. package/build/lib/index.js +37 -0
  139. package/build/lib/index.js.map +1 -0
  140. package/build/lib/method-map.d.ts +0 -8
  141. package/build/lib/method-map.d.ts.map +1 -1
  142. package/build/lib/method-map.js +63 -74
  143. package/build/lib/method-map.js.map +1 -1
  144. package/build/lib/stubs.d.ts +0 -1
  145. package/build/lib/stubs.d.ts.map +1 -1
  146. package/build/lib/stubs.js +1 -0
  147. package/build/lib/stubs.js.map +1 -1
  148. package/build/lib/utils.d.ts +1 -1
  149. package/build/lib/utils.d.ts.map +1 -1
  150. package/lib/commands/actions.js +351 -464
  151. package/lib/commands/alert.js +27 -17
  152. package/lib/commands/app-management.js +156 -314
  153. package/lib/commands/context.js +457 -441
  154. package/lib/commands/element.js +201 -157
  155. package/lib/commands/emu-console.js +25 -45
  156. package/lib/commands/execute.js +106 -90
  157. package/lib/commands/file-actions.js +222 -240
  158. package/lib/commands/find.ts +103 -0
  159. package/lib/commands/general.js +327 -339
  160. package/lib/commands/ime.js +50 -34
  161. package/lib/commands/{index.js → index.ts} +20 -24
  162. package/lib/commands/intent.js +108 -249
  163. package/lib/commands/keyboard.js +20 -8
  164. package/lib/commands/log.js +172 -116
  165. package/lib/commands/media-projection.js +134 -161
  166. package/lib/commands/mixins.ts +966 -0
  167. package/lib/commands/network.js +252 -281
  168. package/lib/commands/performance.js +203 -132
  169. package/lib/commands/permissions.js +108 -109
  170. package/lib/commands/recordscreen.js +212 -209
  171. package/lib/commands/shell.js +51 -40
  172. package/lib/commands/streamscreen.js +355 -289
  173. package/lib/commands/system-bars.js +92 -83
  174. package/lib/commands/touch.js +357 -294
  175. package/lib/commands/types.ts +1097 -0
  176. package/lib/{desired-caps.js → constraints.ts} +106 -103
  177. package/lib/{driver.js → driver.ts} +278 -132
  178. package/lib/helpers/android.ts +1143 -0
  179. package/lib/helpers/index.ts +6 -0
  180. package/lib/helpers/types.ts +134 -0
  181. package/lib/helpers/unlock.ts +329 -0
  182. package/lib/helpers/webview.ts +582 -0
  183. package/lib/index.ts +18 -0
  184. package/lib/method-map.js +87 -98
  185. package/lib/stubs.ts +0 -1
  186. package/package.json +27 -20
  187. package/index.js +0 -24
  188. package/lib/android-helpers.js +0 -983
  189. package/lib/commands/coverage.js +0 -18
  190. package/lib/commands/find.js +0 -82
  191. package/lib/unlock-helpers.js +0 -278
  192. package/lib/webview-helpers.js +0 -602
@@ -1,42 +1,58 @@
1
- import { errors } from 'appium/driver';
1
+ // @ts-check
2
2
 
3
- let commands = {}, helpers = {}, extensions = {};
3
+ import {mixin} from './mixins';
4
+ import {errors} from 'appium/driver';
4
5
 
5
- commands.isIMEActivated = async function isIMEActivated () { // eslint-disable-line require-await
6
- // IME is always activated on Android devices
7
- return true;
8
- };
6
+ /**
7
+ * @type {import('./mixins').IMEMixin & ThisType<import('../driver').AndroidDriver>}
8
+ * @satisfies {import('@appium/types').ExternalDriver}
9
+ */
10
+ const IMEMixin = {
11
+ async isIMEActivated() {
12
+ // eslint-disable-line require-await
13
+ // IME is always activated on Android devices
14
+ return true;
15
+ },
9
16
 
10
- commands.availableIMEEngines = async function availableIMEEngines () {
11
- this.log.debug('Retrieving available IMEs');
12
- let engines = await this.adb.availableIMEs();
13
- this.log.debug(`Engines: ${JSON.stringify(engines)}`);
14
- return engines;
15
- };
17
+ async availableIMEEngines() {
18
+ this.log.debug('Retrieving available IMEs');
19
+ let engines = await /** @type {ADB} */ (this.adb).availableIMEs();
20
+ this.log.debug(`Engines: ${JSON.stringify(engines)}`);
21
+ return engines;
22
+ },
16
23
 
17
- commands.getActiveIMEEngine = async function getActiveIMEEngine () {
18
- this.log.debug('Retrieving current default IME');
19
- return await this.adb.defaultIME();
20
- };
24
+ async getActiveIMEEngine() {
25
+ this.log.debug('Retrieving current default IME');
26
+ return String(await /** @type {ADB} */ (this.adb).defaultIME());
27
+ },
21
28
 
22
- commands.activateIMEEngine = async function activateIMEEngine (imeId) {
23
- this.log.debug(`Attempting to activate IME ${imeId}`);
24
- let availableEngines = await this.adb.availableIMEs();
25
- if (availableEngines.indexOf(imeId) === -1) {
26
- this.log.debug('IME not found, failing');
27
- throw new errors.IMENotAvailableError();
28
- }
29
- this.log.debug('Found installed IME, attempting to activate');
30
- await this.adb.enableIME(imeId);
31
- await this.adb.setIME(imeId);
32
- };
29
+ async activateIMEEngine(imeId) {
30
+ const adb = /** @type {ADB} */ (this.adb);
31
+ this.log.debug(`Attempting to activate IME ${imeId}`);
32
+ let availableEngines = await adb.availableIMEs();
33
+ if (availableEngines.indexOf(imeId) === -1) {
34
+ this.log.debug('IME not found, failing');
35
+ throw new errors.IMENotAvailableError();
36
+ }
37
+ this.log.debug('Found installed IME, attempting to activate');
38
+ await adb.enableIME(imeId);
39
+ await adb.setIME(imeId);
40
+ },
33
41
 
34
- commands.deactivateIMEEngine = async function deactivateIMEEngine () {
35
- let currentEngine = await this.getActiveIMEEngine();
36
- this.log.debug(`Attempting to deactivate ${currentEngine}`);
37
- await this.adb.disableIME(currentEngine);
42
+ async deactivateIMEEngine() {
43
+ let currentEngine = await this.getActiveIMEEngine();
44
+ // XXX: this allowed 'null' to be passed into `adb.shell`
45
+ if (currentEngine) {
46
+ this.log.debug(`Attempting to deactivate ${currentEngine}`);
47
+ await /** @type {ADB} */ (this.adb).disableIME(currentEngine);
48
+ }
49
+ },
38
50
  };
39
51
 
40
- Object.assign(extensions, commands, helpers);
41
- export { commands, helpers };
42
- export default extensions;
52
+ export default IMEMixin;
53
+
54
+ mixin(IMEMixin);
55
+
56
+ /**
57
+ * @typedef {import('appium-adb').ADB} ADB
58
+ */
@@ -1,32 +1,28 @@
1
- import findCmds from './find';
2
- import generalCmds from './general';
1
+ import actionCmds from './actions';
3
2
  import alertCmds from './alert';
4
- import elementCmds from './element';
3
+ import appManagementCmds from './app-management';
5
4
  import contextCmds from './context';
6
- import actionCmds from './actions';
7
- import touchCmds from './touch';
8
- import imeCmds from './ime';
9
- import networkCmds from './network';
10
- import coverageCmds from './coverage';
11
- import recordscreenCmds from './recordscreen';
12
- import screenStreamCmds from './streamscreen';
13
- import performanceCmds from './performance';
14
- import executeCmds from './execute';
15
- import shellCmds from './shell';
5
+ import elementCmds from './element';
16
6
  import emuConsoleCmds from './emu-console';
7
+ import executeCmds from './execute';
17
8
  import fileActionsCmds from './file-actions';
18
- import appManagementCmds from './app-management';
9
+ import findCmds from './find';
10
+ import generalCmds from './general';
11
+ import imeCmds from './ime';
19
12
  import intentCmds from './intent';
20
- import systemBarsCmds from './system-bars';
13
+ import keyboardCmds from './keyboard';
21
14
  import logCmds from './log';
22
15
  import mediaProjectionCmds from './media-projection';
16
+ import networkCmds from './network';
17
+ import performanceCmds from './performance';
23
18
  import permissionsCmds from './permissions';
24
- import keyboardCmds from './keyboard';
25
-
19
+ import recordscreenCmds from './recordscreen';
20
+ import shellCmds from './shell';
21
+ import screenStreamCmds from './streamscreen';
22
+ import systemBarsCmds from './system-bars';
23
+ import touchCmds from './touch';
26
24
 
27
- let commands = {};
28
- Object.assign(
29
- commands,
25
+ const commands = {
30
26
  findCmds,
31
27
  generalCmds,
32
28
  alertCmds,
@@ -36,7 +32,6 @@ Object.assign(
36
32
  touchCmds,
37
33
  imeCmds,
38
34
  networkCmds,
39
- coverageCmds,
40
35
  recordscreenCmds,
41
36
  intentCmds,
42
37
  screenStreamCmds,
@@ -52,7 +47,8 @@ Object.assign(
52
47
  permissionsCmds,
53
48
  keyboardCmds,
54
49
  // add other command types here
55
- );
50
+ };
51
+
52
+ export {commands};
56
53
 
57
- export { commands };
58
- export default commands;
54
+ export type * from './mixins';
@@ -1,27 +1,37 @@
1
+ // @ts-check
2
+
3
+ import {mixin} from './mixins';
1
4
  import _ from 'lodash';
2
- import { errors } from 'appium/driver';
5
+ import {errors} from 'appium/driver';
3
6
 
4
7
  const NO_VALUE_ARG_TYPE = 'sn';
5
8
  const SUPPORTED_EXTRA_TYPES = [
6
- 's', NO_VALUE_ARG_TYPE, 'z', 'i', 'l', 'f', 'u', 'cn',
7
- 'ia', 'ial', 'la', 'lal', 'fa', 'fal', 'sa', 'sal',
9
+ 's',
10
+ NO_VALUE_ARG_TYPE,
11
+ 'z',
12
+ 'i',
13
+ 'l',
14
+ 'f',
15
+ 'u',
16
+ 'cn',
17
+ 'ia',
18
+ 'ial',
19
+ 'la',
20
+ 'lal',
21
+ 'fa',
22
+ 'fal',
23
+ 'sa',
24
+ 'sal',
8
25
  ];
9
26
  const API_LEVEL_ANDROID_8 = 26;
10
27
 
11
- const commands = {};
12
-
13
- function parseIntentSpec (opts = {}) {
14
- const {
15
- intent,
16
- action,
17
- uri,
18
- mimeType,
19
- identifier,
20
- categories,
21
- component,
22
- extras,
23
- flags,
24
- } = opts;
28
+ /**
29
+ *
30
+ * @param {import('./types').IntentOpts} opts
31
+ * @returns {string[]}
32
+ */
33
+ function parseIntentSpec(opts = {}) {
34
+ const {intent, action, uri, mimeType, identifier, categories, component, extras, flags} = opts;
25
35
  const resultArgs = [];
26
36
  if (intent) {
27
37
  resultArgs.push(intent);
@@ -40,7 +50,7 @@ function parseIntentSpec (opts = {}) {
40
50
  }
41
51
  if (categories) {
42
52
  if (_.isArray(categories)) {
43
- resultArgs.push(...(_.flatMap(categories.map((cName) => ['-c', cName]))));
53
+ resultArgs.push(..._.flatMap(categories.map((cName) => ['-c', cName])));
44
54
  } else {
45
55
  resultArgs.push('-c', categories);
46
56
  }
@@ -63,7 +73,7 @@ function parseIntentSpec (opts = {}) {
63
73
  if (!_.includes(SUPPORTED_EXTRA_TYPES, type)) {
64
74
  throw new errors.InvalidArgumentError(
65
75
  `Extra argument type '${type}' is not known. ` +
66
- `Supported intent argument types are: ${SUPPORTED_EXTRA_TYPES}`
76
+ `Supported intent argument types are: ${SUPPORTED_EXTRA_TYPES}`
67
77
  );
68
78
  }
69
79
  if (_.isEmpty(key) || (_.isString(key) && _.trim(key) === '')) {
@@ -76,7 +86,7 @@ function parseIntentSpec (opts = {}) {
76
86
  } else if (_.isUndefined(value)) {
77
87
  throw new errors.InvalidArgumentError(
78
88
  `Intent argument type '${type}' in '${JSON.stringify(item)}' requires a ` +
79
- `valid value to be provided`
89
+ `valid value to be provided`
80
90
  );
81
91
  } else {
82
92
  resultArgs.push(`--e${type}`, key, value);
@@ -90,242 +100,91 @@ function parseIntentSpec (opts = {}) {
90
100
  }
91
101
 
92
102
  /**
93
- * @typedef {Object} StartActivityOptions
94
- * @property {?string|number} user ['current'] - The user ID for which the service is started.
95
- * The `current` user id is used by default
96
- * @property {?boolean} wait [false] - Set it to `true` if you want to block the method call
97
- * until the activity manager's process returns the control to the system.
98
- * @property {?boolean} stop [false] - Set it to `true` to force stop the target
99
- * app before starting the activity
100
- * @property {?number|string} windowingMode - The windowing mode to launch the activity into.
101
- * Check https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/WindowConfiguration.java
102
- * for more details on possible windowing modes (constants starting with `WINDOWING_MODE_`).
103
- * @property {?number|string} activityType - The activity type to launch the activity as.
104
- * Check https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/WindowConfiguration.java
105
- * for more details on possible activity types (constants starting with `ACTIVITY_TYPE_`).
106
- * @property {?number|string} display - The display identifier to launch the activity into.
107
- * @property {?string} intent - The name of the activity intent to start, for example
108
- * `com.some.package.name/.YourServiceSubClassName`
109
- * @property {?string} action - Action name
110
- * @property {?string} package - Package name
111
- * @property {?string} uri - Unified resource identifier
112
- * @property {?string} mimeType - Mime type
113
- * @property {?string} identifier - Optional identifier
114
- * @property {?string|Array<string>} categories - One or more category names
115
- * @property {?string} component - Component name
116
- * @property {Array<string|Array<string>>} extras - Optional intent arguments. Must be represented
117
- * as array of arrays, where each subarray item contains two or three string items:
118
- * value type, key name and the value itself.
119
- * Supported value types are:
120
- * - s: string. Value must be a valid string
121
- * - sn: null. Value is ignored for this type
122
- * - z: boolean. Value must be either `true` or `false`
123
- * - i: integer. Value must be a valid 4-byte integer number
124
- * - l: long. Value must be a valid 8-byte long number
125
- * - f: float: Value must be a valid float number
126
- * - u: uri. Value must be a valid uniform resource identifier string
127
- * - cn: component name. Value must be a valid component name string
128
- * - ia: Integer[]. Value must be a string of comma-separated integers
129
- * - ial: List<Integer>. Value must be a string of comma-separated integers
130
- * - la: Long[]. Value must be a string of comma-separated long numbers
131
- * - lal: List<Long>. Value must be a string of comma-separated long numbers
132
- * - fa: Float[]. Value must be a string of comma-separated float numbers
133
- * - fal: List<Float>. Value must be a string of comma-separated float numbers
134
- * - sa: String[]. Value must be comma-separated strings. To embed a comma into a string,
135
- * escape it using "\,"
136
- * - sal: List<String>. Value must be comma-separated strings. To embed a comma into a string,
137
- * escape it using "\,"
138
- * For example: [['s', 'varName1', 'My String1'], ['s', 'varName2', 'My String2'], ['ia', 'arrName', '1,2,3,4']]
139
- * @property {?string} flags - Intent startup-specific flags as a hexadecimal string.
140
- * See https://developer.android.com/reference/android/content/Intent.html
141
- * for the list of available flag values (constants starting with FLAG_ACTIVITY_).
142
- * Flag values could be merged using the logical 'or' operation.
143
- * For example, 0x10200000 is the combination of two flags:
144
- * 0x10000000 `FLAG_ACTIVITY_NEW_TASK` | 0x00200000 `FLAG_ACTIVITY_RESET_TASK_IF_NEEDED`
145
- */
146
-
147
- /**
148
- * Starts the given activity intent.
149
- *
150
- * @param {StartActivityOptions} opts
151
- * @returns {string} The command output
152
- * @throws {Error} If there was a failure while starting the activity
153
- * or required options are missing
103
+ * @type {import('./mixins').ActivityMixin & ThisType<import('../driver').AndroidDriver>}
104
+ * @satisfies {import('@appium/types').ExternalDriver}
154
105
  */
155
- commands.mobileStartActivity = async function mobileStartActivity (opts = {}) {
156
- const {
157
- user,
158
- wait,
159
- stop,
160
- windowingMode,
161
- activityType,
162
- display,
163
- } = opts;
164
- const cmd = [
165
- 'am', (await this.adb.getApiLevel() < API_LEVEL_ANDROID_8) ? 'start' : 'start-activity',
166
- ];
167
- if (!_.isNil(user)) {
168
- cmd.push('--user', user);
169
- }
170
- if (wait) {
171
- cmd.push('-W');
172
- }
173
- if (stop) {
174
- cmd.push('-S');
175
- }
176
- if (!_.isNil(windowingMode)) {
177
- cmd.push('--windowingMode', windowingMode);
178
- }
179
- if (!_.isNil(activityType)) {
180
- cmd.push('--activityType', activityType);
181
- }
182
- if (!_.isNil(display)) {
183
- cmd.push('--display', display);
184
- }
185
- cmd.push(...(parseIntentSpec(opts)));
186
- return await this.adb.shell(cmd);
187
- };
106
+ const ActivityMixin = {
107
+ async mobileStartActivity(opts = {}) {
108
+ const {user, wait, stop, windowingMode, activityType, display} = opts;
109
+ const cmd = [
110
+ 'am',
111
+ (await /** @type {ADB} */ (this.adb).getApiLevel()) < API_LEVEL_ANDROID_8
112
+ ? 'start'
113
+ : 'start-activity',
114
+ ];
115
+ if (!_.isNil(user)) {
116
+ cmd.push('--user', String(user));
117
+ }
118
+ if (wait) {
119
+ cmd.push('-W');
120
+ }
121
+ if (stop) {
122
+ cmd.push('-S');
123
+ }
124
+ if (!_.isNil(windowingMode)) {
125
+ cmd.push('--windowingMode', String(windowingMode));
126
+ }
127
+ if (!_.isNil(activityType)) {
128
+ cmd.push('--activityType', String(activityType));
129
+ }
130
+ if (!_.isNil(display)) {
131
+ cmd.push('--display', String(display));
132
+ }
133
+ cmd.push(...parseIntentSpec(opts));
134
+ return await /** @type {ADB} */ (this.adb).shell(cmd);
135
+ },
188
136
 
189
- /**
190
- * @typedef {Object} BroadcastOptions
191
- * @property {?string|number} user ['all'] - The user ID for which the broadcast is sent.
192
- * The `current` alias assumes the current user ID.
193
- * @property {?string} receiverPermission - Require receiver to hold the given permission.
194
- * @property {?boolean} allowBackgroundActivityStarts [false] - Whether the receiver may
195
- * start activities even if in the background.
196
- * @property {?string} intent - The name of the intent to broadcast to, for example
197
- * `com.some.package.name/.YourServiceSubClassName`.
198
- * @property {?string} action - Action name
199
- * @property {?string} uri - Unified resource identifier
200
- * @property {?string} mimeType - Mime type
201
- * @property {?string} identifier - Optional identifier
202
- * @property {?string|Array<string>} categories - One or more category names
203
- * @property {?string} component - Component name
204
- * @property {?string} package - Package name
205
- * @property {Array<Array<string>>} extras - Optional intent arguments.
206
- * See above for the detailed description.
207
- * @property {?string} flags - Intent startup-specific flags as a hexadecimal string.
208
- * See above for the detailed description.
209
- */
137
+ async mobileBroadcast(opts = {}) {
138
+ const {user, receiverPermission, allowBackgroundActivityStarts} = opts;
139
+ const cmd = ['am', 'broadcast'];
140
+ if (!_.isNil(user)) {
141
+ cmd.push('--user', String(user));
142
+ }
143
+ if (receiverPermission) {
144
+ cmd.push('--receiver-permission', receiverPermission);
145
+ }
146
+ if (allowBackgroundActivityStarts) {
147
+ cmd.push('--allow-background-activity-starts');
148
+ }
149
+ cmd.push(...parseIntentSpec(opts));
150
+ return await /** @type {ADB} */ (this.adb).shell(cmd);
151
+ },
210
152
 
153
+ async mobileStartService(opts = {}) {
154
+ const {user, foreground} = opts;
155
+ const cmd = ['am'];
156
+ if ((await /** @type {ADB} */ (this.adb).getApiLevel()) < API_LEVEL_ANDROID_8) {
157
+ cmd.push('startservice');
158
+ } else {
159
+ cmd.push(foreground ? 'start-foreground-service' : 'start-service');
160
+ }
161
+ if (!_.isNil(user)) {
162
+ cmd.push('--user', String(user));
163
+ }
164
+ cmd.push(...parseIntentSpec(opts));
165
+ return await /** @type {ADB} */ (this.adb).shell(cmd);
166
+ },
211
167
 
212
- /**
213
- * Send a broadcast intent.
214
- *
215
- * @param {BroadcastOptions} opts
216
- * @returns {string} The command output
217
- * @throws {Error} If there was a failure while starting the activity
218
- * or required options are missing
219
- */
220
- commands.mobileBroadcast = async function mobileBroadcast (opts = {}) {
221
- const {
222
- user,
223
- receiverPermission,
224
- allowBackgroundActivityStarts,
225
- } = opts;
226
- const cmd = ['am', 'broadcast'];
227
- if (!_.isNil(user)) {
228
- cmd.push('--user', user);
229
- }
230
- if (receiverPermission) {
231
- cmd.push('--receiver-permission', receiverPermission);
232
- }
233
- if (allowBackgroundActivityStarts) {
234
- cmd.push('--allow-background-activity-starts');
235
- }
236
- cmd.push(...(parseIntentSpec(opts)));
237
- return await this.adb.shell(cmd);
168
+ async mobileStopService(opts = {}) {
169
+ const {user} = opts;
170
+ const cmd = [
171
+ 'am',
172
+ (await /** @type {ADB} */ (this.adb).getApiLevel()) < API_LEVEL_ANDROID_8
173
+ ? 'stopservice'
174
+ : 'stop-service',
175
+ ];
176
+ if (!_.isNil(user)) {
177
+ cmd.push('--user', String(user));
178
+ }
179
+ cmd.push(...parseIntentSpec(opts));
180
+ return await /** @type {ADB} */ (this.adb).shell(cmd);
181
+ },
238
182
  };
239
183
 
240
- /**
241
- * @typedef {Object} StartServiceOptions
242
- * @property {?string|number} user ['current'] - The user ID for which the service is started.
243
- * The `current` user id is used by default
244
- * @property {?boolean} foreground [false] - Set it to `true` if your service must be
245
- * started as foreground service. This option is ignored if the API level of the
246
- * device under test is below 26 (Android 8).
247
- * @property {?string} intent - The name of the service intent to start, for example
248
- * `com.some.package.name/.YourServiceSubClassName`.
249
- * @property {?string} action - Action name
250
- * @property {?string} uri - Unified resource identifier
251
- * @property {?string} mimeType - Mime type
252
- * @property {?string} identifier - Optional identifier
253
- * @property {?string|Array<string>} categories - One or more category names
254
- * @property {?string} component - Component name
255
- * @property {?string} package - Package name
256
- * @property {Array<Array<string>>} extras - Optional intent arguments.
257
- * See above for the detailed description.
258
- * @property {?string} flags - Intent startup-specific flags as a hexadecimal string.
259
- * See above for the detailed description.
260
- */
261
-
262
- /**
263
- * Starts the given service intent.
264
- *
265
- * @param {StartServiceOptions} opts
266
- * @returns {string} The command output
267
- * @throws {Error} If there was a failure while starting the service
268
- * or required options are missing
269
- */
270
- commands.mobileStartService = async function mobileStartService (opts = {}) {
271
- const {
272
- user,
273
- foreground,
274
- } = opts;
275
- const cmd = ['am'];
276
- if (await this.adb.getApiLevel() < API_LEVEL_ANDROID_8) {
277
- cmd.push('startservice');
278
- } else {
279
- cmd.push(foreground ? 'start-foreground-service' : 'start-service');
280
- }
281
- if (!_.isNil(user)) {
282
- cmd.push('--user', user);
283
- }
284
- cmd.push(...(parseIntentSpec(opts)));
285
- return await this.adb.shell(cmd);
286
- };
184
+ mixin(ActivityMixin);
287
185
 
288
- /**
289
- * @typedef {Object} StopServiceOptions
290
- * @property {string|number} user ['current'] - The user ID for which the service is running.
291
- * The `current` user id is used by default
292
- * @property {?string} intent - The name of the service intent to stop, for example
293
- * `com.some.package.name/.YourServiceSubClassName`.
294
- * @property {?string} action - Action name
295
- * @property {?string} uri - Unified resource identifier
296
- * @property {?string} mimeType - Mime type
297
- * @property {?string} identifier - Optional identifier
298
- * @property {?string|Array<string>} categories - One or more category names
299
- * @property {?string} component - Component name
300
- * @property {?string} package - Package name
301
- * @property {Array<Array<string>>} extras - Optional intent arguments.
302
- * See above for the detailed description.
303
- * @property {?string} flags - See above for the detailed description.
304
- */
186
+ export default ActivityMixin;
305
187
 
306
188
  /**
307
- * Stops the given service intent.
308
- *
309
- * @param {StopServiceOptions} opts
310
- * @returns {string} The command output
311
- * @throws {Error} If there was a failure while stopping the service
312
- * or required options are missing
189
+ * @typedef {import('appium-adb').ADB} ADB
313
190
  */
314
- commands.mobileStopService = async function mobileStopService (opts = {}) {
315
- const {
316
- user,
317
- } = opts;
318
- const cmd = [
319
- 'am',
320
- (await this.adb.getApiLevel() < API_LEVEL_ANDROID_8) ? 'stopservice' : 'stop-service'
321
- ];
322
- if (!_.isNil(user)) {
323
- cmd.push('--user', user);
324
- }
325
- cmd.push(...(parseIntentSpec(opts)));
326
- return await this.adb.shell(cmd);
327
- };
328
-
329
-
330
- export { commands };
331
- export default commands;
@@ -1,12 +1,24 @@
1
- const commands = {};
1
+ // @ts-check
2
2
 
3
- commands.hideKeyboard = async function hideKeyboard () {
4
- return await this.adb.hideKeyboard();
5
- };
3
+ import {mixin} from './mixins';
4
+
5
+ /**
6
+ * @type {import('./mixins').KeyboardMixin & ThisType<import('../driver').AndroidDriver>}
7
+ * @satisfies {import('@appium/types').ExternalDriver}
8
+ */
9
+ const KeyboardMixin = {
10
+ async hideKeyboard() {
11
+ return await /** @type {import('appium-adb').ADB} */ (this.adb).hideKeyboard();
12
+ },
6
13
 
7
- commands.isKeyboardShown = async function isKeyboardShown () {
8
- const {isKeyboardShown} = await this.adb.isSoftKeyboardPresent();
9
- return isKeyboardShown;
14
+ async isKeyboardShown() {
15
+ const {isKeyboardShown} = await /** @type {import('appium-adb').ADB} */ (
16
+ this.adb
17
+ ).isSoftKeyboardPresent();
18
+ return isKeyboardShown;
19
+ },
10
20
  };
11
21
 
12
- export default commands;
22
+ mixin(KeyboardMixin);
23
+
24
+ export default KeyboardMixin;