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,6 +1,9 @@
1
+ // @ts-check
2
+
3
+ import {errors} from 'appium/driver';
1
4
  import _ from 'lodash';
2
- import { requireArgs } from '../utils';
3
- import { errors } from 'appium/driver';
5
+ import {requireArgs} from '../utils';
6
+ import {mixin} from './mixins';
4
7
 
5
8
  const WINDOW_TITLE_PATTERN = /^\s+Window\s#\d+\sWindow\{[0-9a-f]+\s\w+\s([\w-]+)\}:$/;
6
9
  const FRAME_PATTERN = /\bm?[Ff]rame=\[([0-9.-]+),([0-9.-]+)\]\[([0-9.-]+),([0-9.-]+)\]/;
@@ -11,31 +14,23 @@ const STATUS_BAR_WINDOW_NAME_PREFIX = 'StatusBar';
11
14
  const NAVIGATION_BAR_WINDOW_NAME_PREFIX = 'NavigationBar';
12
15
  const DEFAULT_WINDOW_PROPERTIES = {
13
16
  visible: false,
14
- x: 0, y: 0, width: 0, height: 0,
17
+ x: 0,
18
+ y: 0,
19
+ width: 0,
20
+ height: 0,
15
21
  };
16
22
 
17
- const commands = {};
18
-
19
- /**
20
- * @typedef {Object} WindowProperties
21
- * @property {boolean} visible Whether the window is visible
22
- * @property {number} x Window x coordinate
23
- * @property {number} y Window y coordinate
24
- * @property {number} width Window width
25
- * @property {number} height Window height
26
- */
27
-
28
23
  /**
29
24
  * Parses window properties from adb dumpsys output
30
25
  *
31
26
  * @param {string} name The name of the window whose properties are being parsed
32
27
  * @param {Array<string>} props The list of particular window property lines.
33
28
  * Check the corresponding unit tests for more details on the input format.
34
- * @param {Object?} log Logger instance
29
+ * @param {import('@appium/types').AppiumLogger} [log] Logger instance
35
30
  * @returns {WindowProperties} Parsed properties object
36
31
  * @throws {Error} If there was an issue while parsing the properties string
37
32
  */
38
- function parseWindowProperties (name, props, log = null) {
33
+ function parseWindowProperties(name, props, log) {
39
34
  const result = _.cloneDeep(DEFAULT_WINDOW_PROPERTIES);
40
35
  const propLines = props.join('\n');
41
36
  const frameMatch = FRAME_PATTERN.exec(propLines);
@@ -59,14 +54,17 @@ function parseWindowProperties (name, props, log = null) {
59
54
  /**
60
55
  * Extracts status and navigation bar information from the window manager output.
61
56
  *
62
- * @param {Array<string>} lines Output from dumpsys command.
57
+ * @param {string} lines Output from dumpsys command.
63
58
  * Check the corresponding unit tests for more details on the input format.
64
- * @param {Object?} log Logger instance
65
- * @return {Object} An object containing two items where keys are statusBar and navigationBar,
59
+ * @param {import('@appium/types').AppiumLogger} [log] Logger instance
60
+ * @return {StringRecord} An object containing two items where keys are statusBar and navigationBar,
66
61
  * and values are corresponding WindowProperties objects
67
62
  * @throws {Error} If no window properties could be parsed
68
63
  */
69
- function parseWindows (lines, log = null) {
64
+ function parseWindows(lines, log) {
65
+ /**
66
+ * @type {StringRecord}
67
+ */
70
68
  const windows = {};
71
69
  let currentWindowName = null;
72
70
  for (const line of lines.split('\n').map(_.trimEnd)) {
@@ -86,11 +84,12 @@ function parseWindows (lines, log = null) {
86
84
  }
87
85
  }
88
86
  if (_.isEmpty(windows)) {
89
- log?.debug(lines.join('\n'));
87
+ log?.debug(lines);
90
88
  throw new Error('Cannot parse any window information from the dumpsys output');
91
89
  }
92
90
 
93
- const result = {statusBar: null, navigationBar: null};
91
+ /** @type {{statusBar?: WindowProperties, navigationBar?: WindowProperties}} */
92
+ const result = {};
94
93
  for (const [name, props] of _.toPairs(windows)) {
95
94
  if (name.startsWith(STATUS_BAR_WINDOW_NAME_PREFIX)) {
96
95
  result.statusBar = parseWindowProperties(name, props, log);
@@ -98,79 +97,89 @@ function parseWindows (lines, log = null) {
98
97
  result.navigationBar = parseWindowProperties(name, props, log);
99
98
  }
100
99
  }
101
- const unmatchedWindows = [
100
+ const unmatchedWindows = /** @type {const} */ ([
102
101
  ['statusBar', STATUS_BAR_WINDOW_NAME_PREFIX],
103
- ['navigationBar', NAVIGATION_BAR_WINDOW_NAME_PREFIX]
104
- ].filter(([name]) => _.isNil(result[name]));
102
+ ['navigationBar', NAVIGATION_BAR_WINDOW_NAME_PREFIX],
103
+ ]).filter(([name]) => _.isNil(result[name]));
105
104
  for (const [window, namePrefix] of unmatchedWindows) {
106
- log?.info(`No windows have been found whose title matches to ` +
107
- `'${namePrefix}'. Assuming it is invisible. ` +
108
- `Only the following windows are available: ${_.keys(windows)}`);
105
+ log?.info(
106
+ `No windows have been found whose title matches to ` +
107
+ `'${namePrefix}'. Assuming it is invisible. ` +
108
+ `Only the following windows are available: ${_.keys(windows)}`
109
+ );
109
110
  result[window] = _.cloneDeep(DEFAULT_WINDOW_PROPERTIES);
110
111
  }
111
112
  return result;
112
113
  }
113
114
 
114
- commands.getSystemBars = async function getSystemBars () {
115
- let stdout;
116
- try {
117
- stdout = await this.adb.shell(['dumpsys', 'window', 'windows']);
118
- } catch (e) {
119
- throw new Error(`Cannot retrieve system bars details. Original error: ${e.message}`);
120
- }
121
- return parseWindows(stdout, this.log);
122
- };
123
-
124
- /**
125
- * @typedef {Object} StatusBarCommandOptions
126
- * @property {string} command One of supported status bar commands:
127
- * - expandNotifications: Open the notifications panel.
128
- * - expandSettings: Open the notifications panel and expand quick settings if present.
129
- * - collapse: Collapse the notifications and settings panel.
130
- * - addTile: Add a TileService of the specified component.
131
- * - removeTile: Remove a TileService of the specified component.
132
- * - clickTile: Click on a TileService of the specified component.
133
- * - getStatusIcons: Print the list of status bar icons and the order they appear in.
134
- * Each list item is separated with a new line character.
135
- * @property {string?} component The name of the tile component.
136
- * It is only required for (add|remove|click)Tile commands.
137
- * Example value: com.package.name/.service.QuickSettingsTileComponent
138
- */
139
-
140
115
  /**
141
- * Performs commands on the system status bar. A thin wrapper over
142
- * 'adb shell cmd statusbar' CLI. Works on Android Oreo and newer.
143
- *
144
- * @param {StatusBarCommandOptions} opts
145
- * @returns {Promise<string>} The actual output of the downstream console command.
116
+ * @type {import('./mixins').SystemBarsMixin & ThisType<import('../driver').AndroidDriver>}
117
+ * @satisfies {import('@appium/types').ExternalDriver}
146
118
  */
147
- commands.mobilePerformStatusBarCommand = async function mobilePerformStatusBarCommand (opts = {}) {
148
- const {command} = requireArgs('command', opts);
119
+ const SystemBarsMixin = {
120
+ async getSystemBars() {
121
+ /** @type {string} */
122
+ let stdout;
123
+ try {
124
+ stdout = await /** @type {ADB} */ (this.adb).shell(['dumpsys', 'window', 'windows']);
125
+ } catch (e) {
126
+ throw new Error(
127
+ `Cannot retrieve system bars details. Original error: ${/** @type {Error} */ (e).message}`
128
+ );
129
+ }
130
+ return parseWindows(stdout, this.log);
131
+ },
149
132
 
150
- const toStatusBarCommandCallable = (cmd, argsCallable = null) => async () => await this.adb.shell([
151
- 'cmd', 'statusbar', cmd, ...(argsCallable ? argsCallable() : [])
152
- ]);
153
- const tileCommandArgsCallable = () => requireArgs('component', opts).component;
154
- const statusBarCommands = _.fromPairs([
155
- ['expandNotifications', ['expand-notifications']],
156
- ['expandSettings', ['expand-settings']],
157
- ['collapse', ['collapse']],
158
- ['addTile', ['add-tile', tileCommandArgsCallable]],
159
- ['removeTile', ['remove-tile', tileCommandArgsCallable]],
160
- ['clickTile', ['click-tile', tileCommandArgsCallable]],
161
- ['getStatusIcons', ['get-status-icons']],
162
- ].map(([name, args]) => [name, toStatusBarCommandCallable(...args)]));
133
+ async mobilePerformStatusBarCommand(opts) {
134
+ const {command} = requireArgs('command', opts);
163
135
 
164
- const action = statusBarCommands[command];
165
- if (!action) {
166
- throw new errors.InvalidArgumentError(
167
- `The '${command}' status bar command is unknown. Only the following commands ` +
168
- `are supported: ${_.keys(statusBarCommands)}`
136
+ /**
137
+ *
138
+ * @param {string} cmd
139
+ * @param {(() => string[]|string)} [argsCallable]
140
+ * @returns
141
+ */
142
+ const toStatusBarCommandCallable = (cmd, argsCallable) => async () =>
143
+ await /** @type {ADB} */ (this.adb).shell([
144
+ 'cmd',
145
+ 'statusbar',
146
+ cmd,
147
+ ...(argsCallable ? _.castArray(argsCallable()) : []),
148
+ ]);
149
+ const tileCommandArgsCallable = () =>
150
+ /** @type {string} */ (requireArgs('component', opts).component);
151
+ const statusBarCommands = _.fromPairs(
152
+ /** @type {const} */ ([
153
+ ['expandNotifications', ['expand-notifications']],
154
+ ['expandSettings', ['expand-settings']],
155
+ ['collapse', ['collapse']],
156
+ ['addTile', ['add-tile', tileCommandArgsCallable]],
157
+ ['removeTile', ['remove-tile', tileCommandArgsCallable]],
158
+ ['clickTile', ['click-tile', tileCommandArgsCallable]],
159
+ ['getStatusIcons', ['get-status-icons']],
160
+ ]).map(([name, args]) => [name, toStatusBarCommandCallable(args[0], args[1])])
169
161
  );
170
- }
171
- return await action();
162
+
163
+ const action = statusBarCommands[command];
164
+ if (!action) {
165
+ throw new errors.InvalidArgumentError(
166
+ `The '${command}' status bar command is unknown. Only the following commands ` +
167
+ `are supported: ${_.keys(statusBarCommands)}`
168
+ );
169
+ }
170
+ return await action();
171
+ },
172
172
  };
173
173
 
174
+ mixin(SystemBarsMixin);
175
+
174
176
  // for unit tests
175
- export { parseWindows, parseWindowProperties };
176
- export default commands;
177
+ export {parseWindowProperties, parseWindows};
178
+
179
+ export default SystemBarsMixin;
180
+
181
+ /**
182
+ * @typedef {import('appium-adb').ADB} ADB
183
+ * @typedef {import('@appium/types').StringRecord} StringRecord
184
+ * @typedef {import('./types').WindowProperties} WindowProperties
185
+ */