appium-android-driver 7.8.3 → 8.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 (261) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/lib/commands/app-management.d.ts +129 -5
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +433 -128
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/appearance.d.ts +17 -4
  7. package/build/lib/commands/appearance.d.ts.map +1 -1
  8. package/build/lib/commands/appearance.js +32 -33
  9. package/build/lib/commands/appearance.js.map +1 -1
  10. package/build/lib/commands/context/cache.d.ts +19 -0
  11. package/build/lib/commands/context/cache.d.ts.map +1 -0
  12. package/build/lib/commands/context/cache.js +32 -0
  13. package/build/lib/commands/context/cache.js.map +1 -0
  14. package/build/lib/commands/context/exports.d.ts +141 -0
  15. package/build/lib/commands/context/exports.d.ts.map +1 -0
  16. package/build/lib/commands/context/exports.js +351 -0
  17. package/build/lib/commands/context/exports.js.map +1 -0
  18. package/build/lib/commands/context/helpers.d.ts +98 -0
  19. package/build/lib/commands/context/helpers.d.ts.map +1 -0
  20. package/build/lib/commands/context/helpers.js +715 -0
  21. package/build/lib/commands/context/helpers.js.map +1 -0
  22. package/build/lib/commands/device/common.d.ts +23 -0
  23. package/build/lib/commands/device/common.d.ts.map +1 -0
  24. package/build/lib/commands/device/common.js +230 -0
  25. package/build/lib/commands/device/common.js.map +1 -0
  26. package/build/lib/commands/device/emulator-actions.d.ts +114 -0
  27. package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
  28. package/build/lib/commands/device/emulator-actions.js +197 -0
  29. package/build/lib/commands/device/emulator-actions.js.map +1 -0
  30. package/build/lib/commands/device/emulator-console.d.ts +7 -0
  31. package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
  32. package/build/lib/commands/device/emulator-console.js +24 -0
  33. package/build/lib/commands/device/emulator-console.js.map +1 -0
  34. package/build/lib/commands/device/utils.d.ts +50 -0
  35. package/build/lib/commands/device/utils.d.ts.map +1 -0
  36. package/build/lib/commands/device/utils.js +238 -0
  37. package/build/lib/commands/device/utils.js.map +1 -0
  38. package/build/lib/commands/deviceidle.d.ts +8 -5
  39. package/build/lib/commands/deviceidle.d.ts.map +1 -1
  40. package/build/lib/commands/deviceidle.js +31 -37
  41. package/build/lib/commands/deviceidle.js.map +1 -1
  42. package/build/lib/commands/element.d.ts +99 -5
  43. package/build/lib/commands/element.d.ts.map +1 -1
  44. package/build/lib/commands/element.js +152 -116
  45. package/build/lib/commands/element.js.map +1 -1
  46. package/build/lib/commands/execute.d.ts +12 -4
  47. package/build/lib/commands/execute.d.ts.map +1 -1
  48. package/build/lib/commands/execute.js +83 -78
  49. package/build/lib/commands/execute.js.map +1 -1
  50. package/build/lib/commands/file-actions.d.ts +42 -5
  51. package/build/lib/commands/file-actions.d.ts.map +1 -1
  52. package/build/lib/commands/file-actions.js +230 -194
  53. package/build/lib/commands/file-actions.js.map +1 -1
  54. package/build/lib/commands/find.d.ts +5 -4
  55. package/build/lib/commands/find.d.ts.map +1 -1
  56. package/build/lib/commands/find.js +7 -10
  57. package/build/lib/commands/find.js.map +1 -1
  58. package/build/lib/commands/geolocation.d.ts +45 -0
  59. package/build/lib/commands/geolocation.d.ts.map +1 -0
  60. package/build/lib/commands/geolocation.js +182 -0
  61. package/build/lib/commands/geolocation.js.map +1 -0
  62. package/build/lib/commands/ime.d.ts +25 -5
  63. package/build/lib/commands/ime.d.ts.map +1 -1
  64. package/build/lib/commands/ime.js +59 -42
  65. package/build/lib/commands/ime.js.map +1 -1
  66. package/build/lib/commands/intent.d.ts +56 -5
  67. package/build/lib/commands/intent.d.ts.map +1 -1
  68. package/build/lib/commands/intent.js +135 -83
  69. package/build/lib/commands/intent.js.map +1 -1
  70. package/build/lib/commands/keyboard.d.ts +58 -4
  71. package/build/lib/commands/keyboard.d.ts.map +1 -1
  72. package/build/lib/commands/keyboard.js +119 -17
  73. package/build/lib/commands/keyboard.js.map +1 -1
  74. package/build/lib/commands/lock/exports.d.ts +301 -0
  75. package/build/lib/commands/lock/exports.d.ts.map +1 -0
  76. package/build/lib/commands/lock/exports.js +121 -0
  77. package/build/lib/commands/lock/exports.js.map +1 -0
  78. package/build/lib/commands/lock/helpers.d.ts +349 -0
  79. package/build/lib/commands/lock/helpers.d.ts.map +1 -0
  80. package/build/lib/commands/lock/helpers.js +375 -0
  81. package/build/lib/commands/lock/helpers.js.map +1 -0
  82. package/build/lib/commands/log.d.ts +59 -5
  83. package/build/lib/commands/log.d.ts.map +1 -1
  84. package/build/lib/commands/log.js +150 -140
  85. package/build/lib/commands/log.js.map +1 -1
  86. package/build/lib/commands/media-projection.d.ts +16 -5
  87. package/build/lib/commands/media-projection.d.ts.map +1 -1
  88. package/build/lib/commands/media-projection.js +69 -58
  89. package/build/lib/commands/media-projection.js.map +1 -1
  90. package/build/lib/commands/memory.d.ts +9 -5
  91. package/build/lib/commands/memory.d.ts.map +1 -1
  92. package/build/lib/commands/memory.js +19 -24
  93. package/build/lib/commands/memory.js.map +1 -1
  94. package/build/lib/commands/misc.d.ts +42 -0
  95. package/build/lib/commands/misc.d.ts.map +1 -0
  96. package/build/lib/commands/misc.js +100 -0
  97. package/build/lib/commands/misc.js.map +1 -0
  98. package/build/lib/commands/network.d.ts +61 -5
  99. package/build/lib/commands/network.d.ts.map +1 -1
  100. package/build/lib/commands/network.js +196 -189
  101. package/build/lib/commands/network.js.map +1 -1
  102. package/build/lib/commands/performance.d.ts +67 -27
  103. package/build/lib/commands/performance.d.ts.map +1 -1
  104. package/build/lib/commands/performance.js +105 -80
  105. package/build/lib/commands/performance.js.map +1 -1
  106. package/build/lib/commands/permissions.d.ts +12 -6
  107. package/build/lib/commands/permissions.d.ts.map +1 -1
  108. package/build/lib/commands/permissions.js +65 -62
  109. package/build/lib/commands/permissions.js.map +1 -1
  110. package/build/lib/commands/recordscreen.d.ts +44 -5
  111. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  112. package/build/lib/commands/recordscreen.js +131 -126
  113. package/build/lib/commands/recordscreen.js.map +1 -1
  114. package/build/lib/commands/resources.d.ts +16 -0
  115. package/build/lib/commands/resources.d.ts.map +1 -0
  116. package/build/lib/commands/resources.js +91 -0
  117. package/build/lib/commands/resources.js.map +1 -0
  118. package/build/lib/commands/shell.d.ts +8 -5
  119. package/build/lib/commands/shell.d.ts.map +1 -1
  120. package/build/lib/commands/shell.js +29 -33
  121. package/build/lib/commands/shell.js.map +1 -1
  122. package/build/lib/commands/streamscreen.d.ts +34 -6
  123. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  124. package/build/lib/commands/streamscreen.js +166 -162
  125. package/build/lib/commands/streamscreen.js.map +1 -1
  126. package/build/lib/commands/system-bars.d.ts +18 -13
  127. package/build/lib/commands/system-bars.d.ts.map +1 -1
  128. package/build/lib/commands/system-bars.js +68 -64
  129. package/build/lib/commands/system-bars.js.map +1 -1
  130. package/build/lib/commands/time.d.ts +14 -0
  131. package/build/lib/commands/time.d.ts.map +1 -0
  132. package/build/lib/commands/time.js +39 -0
  133. package/build/lib/commands/time.js.map +1 -0
  134. package/build/lib/commands/touch.d.ts +99 -6
  135. package/build/lib/commands/touch.d.ts.map +1 -1
  136. package/build/lib/commands/touch.js +399 -280
  137. package/build/lib/commands/touch.js.map +1 -1
  138. package/build/lib/commands/types.d.ts +110 -2
  139. package/build/lib/commands/types.d.ts.map +1 -1
  140. package/build/lib/doctor/checks.d.ts.map +1 -1
  141. package/build/lib/doctor/checks.js +4 -4
  142. package/build/lib/doctor/checks.js.map +1 -1
  143. package/build/lib/driver.d.ts +224 -27
  144. package/build/lib/driver.d.ts.map +1 -1
  145. package/build/lib/driver.js +232 -7
  146. package/build/lib/driver.js.map +1 -1
  147. package/build/lib/index.d.ts +1 -4
  148. package/build/lib/index.d.ts.map +1 -1
  149. package/build/lib/index.js +1 -13
  150. package/build/lib/index.js.map +1 -1
  151. package/build/lib/logger.js.map +1 -1
  152. package/build/lib/method-map.d.ts +0 -23
  153. package/build/lib/method-map.d.ts.map +1 -1
  154. package/build/lib/method-map.js +0 -11
  155. package/build/lib/method-map.js.map +1 -1
  156. package/build/lib/utils.d.ts +12 -0
  157. package/build/lib/utils.d.ts.map +1 -1
  158. package/build/lib/utils.js +38 -2
  159. package/build/lib/utils.js.map +1 -1
  160. package/lib/commands/app-management.js +470 -145
  161. package/lib/commands/appearance.js +29 -36
  162. package/lib/commands/context/cache.js +29 -0
  163. package/lib/commands/context/exports.js +379 -0
  164. package/lib/commands/context/helpers.js +802 -0
  165. package/lib/commands/device/common.js +264 -0
  166. package/lib/commands/device/emulator-actions.js +194 -0
  167. package/lib/commands/device/emulator-console.js +24 -0
  168. package/lib/commands/device/utils.js +285 -0
  169. package/lib/commands/deviceidle.js +31 -44
  170. package/lib/commands/element.js +149 -142
  171. package/lib/commands/execute.js +86 -87
  172. package/lib/commands/file-actions.js +249 -222
  173. package/lib/commands/find.ts +13 -19
  174. package/lib/commands/geolocation.js +179 -0
  175. package/lib/commands/ime.js +53 -45
  176. package/lib/commands/intent.js +149 -91
  177. package/lib/commands/keyboard.js +114 -17
  178. package/lib/commands/lock/exports.js +139 -0
  179. package/lib/commands/lock/helpers.js +379 -0
  180. package/lib/commands/log.js +170 -166
  181. package/lib/commands/media-projection.js +75 -70
  182. package/lib/commands/memory.js +17 -29
  183. package/lib/commands/misc.js +94 -0
  184. package/lib/commands/network.js +209 -223
  185. package/lib/commands/performance.js +88 -73
  186. package/lib/commands/permissions.js +83 -84
  187. package/lib/commands/recordscreen.js +171 -170
  188. package/lib/commands/resources.js +96 -0
  189. package/lib/commands/shell.js +28 -42
  190. package/lib/commands/streamscreen.js +207 -206
  191. package/lib/commands/system-bars.js +76 -77
  192. package/lib/commands/time.js +36 -0
  193. package/lib/commands/touch.js +442 -346
  194. package/lib/commands/types.ts +123 -2
  195. package/lib/doctor/checks.js +24 -16
  196. package/lib/driver.ts +454 -12
  197. package/lib/index.ts +1 -13
  198. package/lib/logger.js +1 -1
  199. package/lib/method-map.js +0 -11
  200. package/lib/utils.js +40 -3
  201. package/package.json +1 -1
  202. package/build/lib/commands/actions.d.ts +0 -8
  203. package/build/lib/commands/actions.d.ts.map +0 -1
  204. package/build/lib/commands/actions.js +0 -207
  205. package/build/lib/commands/actions.js.map +0 -1
  206. package/build/lib/commands/alert.d.ts +0 -8
  207. package/build/lib/commands/alert.d.ts.map +0 -1
  208. package/build/lib/commands/alert.js +0 -29
  209. package/build/lib/commands/alert.js.map +0 -1
  210. package/build/lib/commands/context.d.ts +0 -10
  211. package/build/lib/commands/context.d.ts.map +0 -1
  212. package/build/lib/commands/context.js +0 -431
  213. package/build/lib/commands/context.js.map +0 -1
  214. package/build/lib/commands/emu-console.d.ts +0 -7
  215. package/build/lib/commands/emu-console.d.ts.map +0 -1
  216. package/build/lib/commands/emu-console.js +0 -27
  217. package/build/lib/commands/emu-console.js.map +0 -1
  218. package/build/lib/commands/general.d.ts +0 -9
  219. package/build/lib/commands/general.d.ts.map +0 -1
  220. package/build/lib/commands/general.js +0 -293
  221. package/build/lib/commands/general.js.map +0 -1
  222. package/build/lib/commands/index.d.ts +0 -28
  223. package/build/lib/commands/index.d.ts.map +0 -1
  224. package/build/lib/commands/index.js +0 -57
  225. package/build/lib/commands/index.js.map +0 -1
  226. package/build/lib/commands/mixins.d.ts +0 -747
  227. package/build/lib/commands/mixins.d.ts.map +0 -1
  228. package/build/lib/commands/mixins.js +0 -19
  229. package/build/lib/commands/mixins.js.map +0 -1
  230. package/build/lib/helpers/android.d.ts +0 -163
  231. package/build/lib/helpers/android.d.ts.map +0 -1
  232. package/build/lib/helpers/android.js +0 -818
  233. package/build/lib/helpers/android.js.map +0 -1
  234. package/build/lib/helpers/index.d.ts +0 -7
  235. package/build/lib/helpers/index.d.ts.map +0 -1
  236. package/build/lib/helpers/index.js +0 -29
  237. package/build/lib/helpers/index.js.map +0 -1
  238. package/build/lib/helpers/types.d.ts +0 -122
  239. package/build/lib/helpers/types.d.ts.map +0 -1
  240. package/build/lib/helpers/types.js +0 -3
  241. package/build/lib/helpers/types.js.map +0 -1
  242. package/build/lib/helpers/unlock.d.ts +0 -32
  243. package/build/lib/helpers/unlock.d.ts.map +0 -1
  244. package/build/lib/helpers/unlock.js +0 -273
  245. package/build/lib/helpers/unlock.js.map +0 -1
  246. package/build/lib/helpers/webview.d.ts +0 -74
  247. package/build/lib/helpers/webview.d.ts.map +0 -1
  248. package/build/lib/helpers/webview.js +0 -448
  249. package/build/lib/helpers/webview.js.map +0 -1
  250. package/lib/commands/actions.js +0 -244
  251. package/lib/commands/alert.js +0 -34
  252. package/lib/commands/context.js +0 -507
  253. package/lib/commands/emu-console.js +0 -31
  254. package/lib/commands/general.js +0 -343
  255. package/lib/commands/index.ts +0 -54
  256. package/lib/commands/mixins.ts +0 -976
  257. package/lib/helpers/android.ts +0 -1153
  258. package/lib/helpers/index.ts +0 -6
  259. package/lib/helpers/types.ts +0 -136
  260. package/lib/helpers/unlock.ts +0 -329
  261. package/lib/helpers/webview.ts +0 -610
@@ -3,7 +3,6 @@
3
3
  import {errors} from 'appium/driver';
4
4
  import _ from 'lodash';
5
5
  import {requireArgs} from '../utils';
6
- import {mixin} from './mixins';
7
6
 
8
7
  const WINDOW_TITLE_PATTERN = /^\s+Window\s#\d+\sWindow\{[0-9a-f]+\s\w+\s([\w-]+)\}:$/;
9
8
  const FRAME_PATTERN = /\bm?[Ff]rame=\[([0-9.-]+),([0-9.-]+)\]\[([0-9.-]+),([0-9.-]+)\]/;
@@ -20,22 +19,86 @@ const DEFAULT_WINDOW_PROPERTIES = {
20
19
  height: 0,
21
20
  };
22
21
 
22
+ /**
23
+ * @this {import('../driver').AndroidDriver}
24
+ * @returns {Promise<StringRecord>}
25
+ */
26
+ export async function getSystemBars() {
27
+ /** @type {string} */
28
+ let stdout;
29
+ try {
30
+ stdout = await this.adb.shell(['dumpsys', 'window', 'windows']);
31
+ } catch (e) {
32
+ throw new Error(
33
+ `Cannot retrieve system bars details. Original error: ${/** @type {Error} */ (e).message}`,
34
+ );
35
+ }
36
+ return parseWindows.bind(this)(stdout);
37
+ }
38
+
39
+ /**
40
+ * @this {import('../driver').AndroidDriver}
41
+ * @param {import('./types').StatusBarCommandOpts} opts
42
+ * @returns {Promise<string>}
43
+ */
44
+ export async function mobilePerformStatusBarCommand(opts) {
45
+ const {command} = requireArgs('command', opts);
46
+
47
+ /**
48
+ *
49
+ * @param {string} cmd
50
+ * @param {(() => string[]|string)} [argsCallable]
51
+ * @returns
52
+ */
53
+ const toStatusBarCommandCallable = (cmd, argsCallable) => async () =>
54
+ await this.adb.shell([
55
+ 'cmd',
56
+ 'statusbar',
57
+ cmd,
58
+ ...(argsCallable ? _.castArray(argsCallable()) : []),
59
+ ]);
60
+ const tileCommandArgsCallable = () =>
61
+ /** @type {string} */ (requireArgs('component', opts).component);
62
+ const statusBarCommands = _.fromPairs(
63
+ /** @type {const} */ ([
64
+ ['expandNotifications', ['expand-notifications']],
65
+ ['expandSettings', ['expand-settings']],
66
+ ['collapse', ['collapse']],
67
+ ['addTile', ['add-tile', tileCommandArgsCallable]],
68
+ ['removeTile', ['remove-tile', tileCommandArgsCallable]],
69
+ ['clickTile', ['click-tile', tileCommandArgsCallable]],
70
+ ['getStatusIcons', ['get-status-icons']],
71
+ ]).map(([name, args]) => [name, toStatusBarCommandCallable(args[0], args[1])]),
72
+ );
73
+
74
+ const action = statusBarCommands[command];
75
+ if (!action) {
76
+ throw new errors.InvalidArgumentError(
77
+ `The '${command}' status bar command is unknown. Only the following commands ` +
78
+ `are supported: ${_.keys(statusBarCommands)}`,
79
+ );
80
+ }
81
+ return await action();
82
+ }
83
+
84
+ // #region Internal helpers
85
+
23
86
  /**
24
87
  * Parses window properties from adb dumpsys output
25
88
  *
89
+ * @this {import('../driver').AndroidDriver}
26
90
  * @param {string} name The name of the window whose properties are being parsed
27
91
  * @param {Array<string>} props The list of particular window property lines.
28
92
  * Check the corresponding unit tests for more details on the input format.
29
- * @param {import('@appium/types').AppiumLogger} [log] Logger instance
30
93
  * @returns {WindowProperties} Parsed properties object
31
94
  * @throws {Error} If there was an issue while parsing the properties string
32
95
  */
33
- function parseWindowProperties(name, props, log) {
96
+ export function parseWindowProperties(name, props) {
34
97
  const result = _.cloneDeep(DEFAULT_WINDOW_PROPERTIES);
35
98
  const propLines = props.join('\n');
36
99
  const frameMatch = FRAME_PATTERN.exec(propLines);
37
100
  if (!frameMatch) {
38
- log?.debug(propLines);
101
+ this.log.debug(propLines);
39
102
  throw new Error(`Cannot parse the frame size from '${name}' window properties`);
40
103
  }
41
104
  result.x = parseFloat(frameMatch[1]);
@@ -44,7 +107,7 @@ function parseWindowProperties(name, props, log) {
44
107
  result.height = parseFloat(frameMatch[4]) - result.y;
45
108
  const visibilityMatch = VIEW_VISIBILITY_PATTERN.exec(propLines);
46
109
  if (!visibilityMatch) {
47
- log?.debug(propLines);
110
+ this.log.debug(propLines);
48
111
  throw new Error(`Cannot parse the visibility value from '${name}' window properties`);
49
112
  }
50
113
  result.visible = parseInt(visibilityMatch[1], 16) === VIEW_VISIBLE;
@@ -54,14 +117,14 @@ function parseWindowProperties(name, props, log) {
54
117
  /**
55
118
  * Extracts status and navigation bar information from the window manager output.
56
119
  *
120
+ * @this {import('../driver').AndroidDriver}
57
121
  * @param {string} lines Output from dumpsys command.
58
122
  * Check the corresponding unit tests for more details on the input format.
59
- * @param {import('@appium/types').AppiumLogger} [log] Logger instance
60
123
  * @return {StringRecord} An object containing two items where keys are statusBar and navigationBar,
61
124
  * and values are corresponding WindowProperties objects
62
125
  * @throws {Error} If no window properties could be parsed
63
126
  */
64
- function parseWindows(lines, log) {
127
+ export function parseWindows(lines) {
65
128
  /**
66
129
  * @type {StringRecord}
67
130
  */
@@ -84,7 +147,7 @@ function parseWindows(lines, log) {
84
147
  }
85
148
  }
86
149
  if (_.isEmpty(windows)) {
87
- log?.debug(lines);
150
+ this.log.debug(lines);
88
151
  throw new Error('Cannot parse any window information from the dumpsys output');
89
152
  }
90
153
 
@@ -92,9 +155,9 @@ function parseWindows(lines, log) {
92
155
  const result = {};
93
156
  for (const [name, props] of _.toPairs(windows)) {
94
157
  if (name.startsWith(STATUS_BAR_WINDOW_NAME_PREFIX)) {
95
- result.statusBar = parseWindowProperties(name, props, log);
158
+ result.statusBar = parseWindowProperties.bind(this)(name, props);
96
159
  } else if (name.startsWith(NAVIGATION_BAR_WINDOW_NAME_PREFIX)) {
97
- result.navigationBar = parseWindowProperties(name, props, log);
160
+ result.navigationBar = parseWindowProperties.bind(this)(name, props);
98
161
  }
99
162
  }
100
163
  const unmatchedWindows = /** @type {const} */ ([
@@ -102,81 +165,17 @@ function parseWindows(lines, log) {
102
165
  ['navigationBar', NAVIGATION_BAR_WINDOW_NAME_PREFIX],
103
166
  ]).filter(([name]) => _.isNil(result[name]));
104
167
  for (const [window, namePrefix] of unmatchedWindows) {
105
- log?.info(
168
+ this.log.info(
106
169
  `No windows have been found whose title matches to ` +
107
170
  `'${namePrefix}'. Assuming it is invisible. ` +
108
- `Only the following windows are available: ${_.keys(windows)}`
171
+ `Only the following windows are available: ${_.keys(windows)}`,
109
172
  );
110
173
  result[window] = _.cloneDeep(DEFAULT_WINDOW_PROPERTIES);
111
174
  }
112
175
  return result;
113
176
  }
114
177
 
115
- /**
116
- * @type {import('./mixins').SystemBarsMixin & ThisType<import('../driver').AndroidDriver>}
117
- * @satisfies {import('@appium/types').ExternalDriver}
118
- */
119
- const SystemBarsMixin = {
120
- async getSystemBars() {
121
- /** @type {string} */
122
- let stdout;
123
- try {
124
- stdout = await 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
- },
132
-
133
- async mobilePerformStatusBarCommand(opts) {
134
- const {command} = requireArgs('command', opts);
135
-
136
- /**
137
- *
138
- * @param {string} cmd
139
- * @param {(() => string[]|string)} [argsCallable]
140
- * @returns
141
- */
142
- const toStatusBarCommandCallable = (cmd, argsCallable) => async () =>
143
- await 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])])
161
- );
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
- };
173
-
174
- mixin(SystemBarsMixin);
175
-
176
- // for unit tests
177
- export {parseWindowProperties, parseWindows};
178
-
179
- export default SystemBarsMixin;
178
+ // #endregion
180
179
 
181
180
  /**
182
181
  * @typedef {import('appium-adb').ADB} ADB
@@ -0,0 +1,36 @@
1
+ import moment from 'moment';
2
+
3
+ const MOMENT_FORMAT_ISO8601 = 'YYYY-MM-DDTHH:mm:ssZ';
4
+
5
+ /**
6
+ * @this {import('../driver').AndroidDriver}
7
+ * @param {string} [format=MOMENT_FORMAT_ISO8601]
8
+ * @returns {Promise<string>}
9
+ */
10
+ export async function getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
11
+ this.log.debug(
12
+ 'Attempting to capture android device date and time. ' + `The format specifier is '${format}'`,
13
+ );
14
+ const deviceTimestamp = (await this.adb.shell(['date', '+%Y-%m-%dT%T%z'])).trim();
15
+ this.log.debug(`Got device timestamp: ${deviceTimestamp}`);
16
+ const parsedTimestamp = moment.utc(deviceTimestamp, 'YYYY-MM-DDTHH:mm:ssZZ');
17
+ if (!parsedTimestamp.isValid()) {
18
+ this.log.warn('Cannot parse the returned timestamp. Returning as is');
19
+ return deviceTimestamp;
20
+ }
21
+ // @ts-expect-error private API
22
+ return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
23
+ }
24
+
25
+ /**
26
+ * @this {import('../driver').AndroidDriver}
27
+ * @param {import('./types').DeviceTimeOpts} [opts={}]
28
+ * @returns {Promise<string>}
29
+ */
30
+ export async function mobileGetDeviceTime(opts = {}) {
31
+ return await this.getDeviceTime(opts.format);
32
+ }
33
+
34
+ /**
35
+ * @typedef {import('appium-adb').ADB} ADB
36
+ */