appium-android-driver 5.14.7 → 6.0.1

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 (210) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/lib/commands/actions.d.ts +6 -224
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +306 -405
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/alert.d.ts +7 -9
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +24 -18
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +7 -313
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +135 -293
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/context.d.ts +8 -92
  15. package/build/lib/commands/context.d.ts.map +1 -1
  16. package/build/lib/commands/context.js +381 -439
  17. package/build/lib/commands/context.js.map +1 -1
  18. package/build/lib/commands/element.d.ts +8 -35
  19. package/build/lib/commands/element.d.ts.map +1 -1
  20. package/build/lib/commands/element.js +153 -136
  21. package/build/lib/commands/element.js.map +1 -1
  22. package/build/lib/commands/emu-console.d.ts +6 -48
  23. package/build/lib/commands/emu-console.d.ts.map +1 -1
  24. package/build/lib/commands/emu-console.js +19 -34
  25. package/build/lib/commands/emu-console.js.map +1 -1
  26. package/build/lib/commands/execute.d.ts +6 -5
  27. package/build/lib/commands/execute.d.ts.map +1 -1
  28. package/build/lib/commands/execute.js +77 -66
  29. package/build/lib/commands/execute.js.map +1 -1
  30. package/build/lib/commands/file-actions.d.ts +7 -128
  31. package/build/lib/commands/file-actions.d.ts.map +1 -1
  32. package/build/lib/commands/file-actions.js +183 -219
  33. package/build/lib/commands/file-actions.js.map +1 -1
  34. package/build/lib/commands/find.d.ts +8 -12
  35. package/build/lib/commands/find.d.ts.map +1 -1
  36. package/build/lib/commands/find.js +19 -23
  37. package/build/lib/commands/find.js.map +1 -1
  38. package/build/lib/commands/general.d.ts +9 -132
  39. package/build/lib/commands/general.d.ts.map +1 -1
  40. package/build/lib/commands/general.js +281 -312
  41. package/build/lib/commands/general.js.map +1 -1
  42. package/build/lib/commands/ime.d.ts +7 -10
  43. package/build/lib/commands/ime.d.ts.map +1 -1
  44. package/build/lib/commands/ime.js +47 -35
  45. package/build/lib/commands/ime.js.map +1 -1
  46. package/build/lib/commands/index.d.ts +27 -2
  47. package/build/lib/commands/index.d.ts.map +1 -1
  48. package/build/lib/commands/index.js +41 -19
  49. package/build/lib/commands/index.js.map +1 -1
  50. package/build/lib/commands/intent.d.ts +7 -417
  51. package/build/lib/commands/intent.d.ts.map +1 -1
  52. package/build/lib/commands/intent.js +104 -216
  53. package/build/lib/commands/intent.js.map +1 -1
  54. package/build/lib/commands/keyboard.d.ts +6 -5
  55. package/build/lib/commands/keyboard.d.ts.map +1 -1
  56. package/build/lib/commands/keyboard.js +16 -8
  57. package/build/lib/commands/keyboard.js.map +1 -1
  58. package/build/lib/commands/log.d.ts +7 -44
  59. package/build/lib/commands/log.d.ts.map +1 -1
  60. package/build/lib/commands/log.js +146 -108
  61. package/build/lib/commands/log.js.map +1 -1
  62. package/build/lib/commands/media-projection.d.ts +7 -143
  63. package/build/lib/commands/media-projection.d.ts.map +1 -1
  64. package/build/lib/commands/media-projection.js +113 -140
  65. package/build/lib/commands/media-projection.js.map +1 -1
  66. package/build/lib/commands/mixins.d.ts +740 -0
  67. package/build/lib/commands/mixins.d.ts.map +1 -0
  68. package/build/lib/commands/mixins.js +19 -0
  69. package/build/lib/commands/mixins.js.map +1 -0
  70. package/build/lib/commands/network.d.ts +7 -138
  71. package/build/lib/commands/network.d.ts.map +1 -1
  72. package/build/lib/commands/network.js +212 -254
  73. package/build/lib/commands/network.js.map +1 -1
  74. package/build/lib/commands/performance.d.ts +24 -70
  75. package/build/lib/commands/performance.d.ts.map +1 -1
  76. package/build/lib/commands/performance.js +144 -100
  77. package/build/lib/commands/performance.js.map +1 -1
  78. package/build/lib/commands/permissions.d.ts +8 -92
  79. package/build/lib/commands/permissions.d.ts.map +1 -1
  80. package/build/lib/commands/permissions.js +75 -87
  81. package/build/lib/commands/permissions.js.map +1 -1
  82. package/build/lib/commands/recordscreen.d.ts +7 -193
  83. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  84. package/build/lib/commands/recordscreen.js +151 -182
  85. package/build/lib/commands/recordscreen.js.map +1 -1
  86. package/build/lib/commands/shell.d.ts +7 -7
  87. package/build/lib/commands/shell.d.ts.map +1 -1
  88. package/build/lib/commands/shell.js +40 -33
  89. package/build/lib/commands/shell.js.map +1 -1
  90. package/build/lib/commands/streamscreen.d.ts +9 -103
  91. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  92. package/build/lib/commands/streamscreen.js +261 -218
  93. package/build/lib/commands/streamscreen.js.map +1 -1
  94. package/build/lib/commands/system-bars.d.ts +22 -90
  95. package/build/lib/commands/system-bars.d.ts.map +1 -1
  96. package/build/lib/commands/system-bars.js +76 -74
  97. package/build/lib/commands/system-bars.js.map +1 -1
  98. package/build/lib/commands/touch.d.ts +10 -29
  99. package/build/lib/commands/touch.d.ts.map +1 -1
  100. package/build/lib/commands/touch.js +301 -285
  101. package/build/lib/commands/touch.js.map +1 -1
  102. package/build/lib/commands/types.d.ts +978 -0
  103. package/build/lib/commands/types.d.ts.map +1 -0
  104. package/build/lib/commands/types.js +3 -0
  105. package/build/lib/commands/types.js.map +1 -0
  106. package/build/lib/constraints.d.ts +291 -0
  107. package/build/lib/constraints.d.ts.map +1 -0
  108. package/build/lib/{desired-caps.js → constraints.js} +103 -102
  109. package/build/lib/constraints.js.map +1 -0
  110. package/build/lib/driver.d.ts +68 -37
  111. package/build/lib/driver.d.ts.map +1 -1
  112. package/build/lib/driver.js +123 -80
  113. package/build/lib/driver.js.map +1 -1
  114. package/build/lib/helpers/android.d.ts +164 -0
  115. package/build/lib/helpers/android.d.ts.map +1 -0
  116. package/build/lib/helpers/android.js +819 -0
  117. package/build/lib/helpers/android.js.map +1 -0
  118. package/build/lib/helpers/index.d.ts +7 -0
  119. package/build/lib/helpers/index.d.ts.map +1 -0
  120. package/build/lib/helpers/index.js +29 -0
  121. package/build/lib/helpers/index.js.map +1 -0
  122. package/build/lib/helpers/types.d.ts +121 -0
  123. package/build/lib/helpers/types.d.ts.map +1 -0
  124. package/build/lib/helpers/types.js +3 -0
  125. package/build/lib/helpers/types.js.map +1 -0
  126. package/build/lib/helpers/unlock.d.ts +32 -0
  127. package/build/lib/helpers/unlock.d.ts.map +1 -0
  128. package/build/lib/helpers/unlock.js +273 -0
  129. package/build/lib/helpers/unlock.js.map +1 -0
  130. package/build/lib/helpers/webview.d.ts +74 -0
  131. package/build/lib/helpers/webview.d.ts.map +1 -0
  132. package/build/lib/helpers/webview.js +421 -0
  133. package/build/lib/helpers/webview.js.map +1 -0
  134. package/build/lib/index.d.ts +9 -0
  135. package/build/lib/index.d.ts.map +1 -0
  136. package/build/lib/index.js +37 -0
  137. package/build/lib/index.js.map +1 -0
  138. package/build/lib/method-map.d.ts +0 -8
  139. package/build/lib/method-map.d.ts.map +1 -1
  140. package/build/lib/method-map.js +63 -74
  141. package/build/lib/method-map.js.map +1 -1
  142. package/build/lib/stubs.d.ts +0 -1
  143. package/build/lib/stubs.d.ts.map +1 -1
  144. package/build/lib/stubs.js +1 -0
  145. package/build/lib/stubs.js.map +1 -1
  146. package/build/lib/utils.d.ts +1 -1
  147. package/build/lib/utils.d.ts.map +1 -1
  148. package/lib/commands/actions.js +351 -464
  149. package/lib/commands/alert.js +27 -17
  150. package/lib/commands/app-management.js +156 -314
  151. package/lib/commands/context.js +457 -441
  152. package/lib/commands/element.js +201 -157
  153. package/lib/commands/emu-console.js +25 -45
  154. package/lib/commands/execute.js +106 -90
  155. package/lib/commands/file-actions.js +222 -240
  156. package/lib/commands/find.ts +103 -0
  157. package/lib/commands/general.js +327 -339
  158. package/lib/commands/ime.js +50 -34
  159. package/lib/commands/{index.js → index.ts} +20 -24
  160. package/lib/commands/intent.js +108 -249
  161. package/lib/commands/keyboard.js +20 -8
  162. package/lib/commands/log.js +172 -116
  163. package/lib/commands/media-projection.js +134 -161
  164. package/lib/commands/mixins.ts +966 -0
  165. package/lib/commands/network.js +252 -281
  166. package/lib/commands/performance.js +203 -132
  167. package/lib/commands/permissions.js +108 -109
  168. package/lib/commands/recordscreen.js +212 -209
  169. package/lib/commands/shell.js +51 -40
  170. package/lib/commands/streamscreen.js +355 -289
  171. package/lib/commands/system-bars.js +92 -83
  172. package/lib/commands/touch.js +357 -294
  173. package/lib/commands/types.ts +1097 -0
  174. package/lib/{desired-caps.js → constraints.ts} +106 -103
  175. package/lib/{driver.js → driver.ts} +278 -132
  176. package/lib/helpers/android.ts +1143 -0
  177. package/lib/helpers/index.ts +6 -0
  178. package/lib/helpers/types.ts +134 -0
  179. package/lib/helpers/unlock.ts +329 -0
  180. package/lib/helpers/webview.ts +582 -0
  181. package/lib/index.ts +18 -0
  182. package/lib/method-map.js +87 -98
  183. package/lib/stubs.ts +0 -1
  184. package/package.json +26 -19
  185. package/build/index.js +0 -51
  186. package/build/lib/android-helpers.d.ts +0 -136
  187. package/build/lib/android-helpers.d.ts.map +0 -1
  188. package/build/lib/android-helpers.js +0 -855
  189. package/build/lib/android-helpers.js.map +0 -1
  190. package/build/lib/commands/coverage.d.ts +0 -5
  191. package/build/lib/commands/coverage.d.ts.map +0 -1
  192. package/build/lib/commands/coverage.js +0 -19
  193. package/build/lib/commands/coverage.js.map +0 -1
  194. package/build/lib/desired-caps.d.ts +0 -353
  195. package/build/lib/desired-caps.d.ts.map +0 -1
  196. package/build/lib/desired-caps.js.map +0 -1
  197. package/build/lib/unlock-helpers.d.ts +0 -38
  198. package/build/lib/unlock-helpers.d.ts.map +0 -1
  199. package/build/lib/unlock-helpers.js +0 -266
  200. package/build/lib/unlock-helpers.js.map +0 -1
  201. package/build/lib/webview-helpers.d.ts +0 -224
  202. package/build/lib/webview-helpers.d.ts.map +0 -1
  203. package/build/lib/webview-helpers.js +0 -528
  204. package/build/lib/webview-helpers.js.map +0 -1
  205. package/index.js +0 -24
  206. package/lib/android-helpers.js +0 -983
  207. package/lib/commands/coverage.js +0 -18
  208. package/lib/commands/find.js +0 -82
  209. package/lib/unlock-helpers.js +0 -278
  210. package/lib/webview-helpers.js +0 -602
@@ -3,331 +3,300 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.helpers = exports.commands = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const android_helpers_1 = __importDefault(require("../android-helpers"));
6
+ // @ts-check
9
7
  const support_1 = require("@appium/support");
10
- const moment_1 = __importDefault(require("moment"));
11
8
  const asyncbox_1 = require("asyncbox");
12
- const driver_1 = require("appium/driver");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ const moment_1 = __importDefault(require("moment"));
11
+ const android_1 = __importDefault(require("../helpers/android"));
12
+ const utils_1 = require("../utils");
13
+ const mixins_1 = require("./mixins");
13
14
  const MOMENT_FORMAT_ISO8601 = 'YYYY-MM-DDTHH:mm:ssZ';
14
- let commands = {}, helpers = {}, extensions = {};
15
- exports.commands = commands;
16
- exports.helpers = helpers;
17
- commands.keys = async function keys(keys) {
18
- // Protocol sends an array; rethink approach
19
- keys = lodash_1.default.isArray(keys) ? keys.join('') : keys;
20
- let params = {
21
- text: keys,
22
- replace: false
23
- };
24
- if (this.opts.unicodeKeyboard) {
25
- params.unicodeKeyboard = true;
26
- }
27
- await this.doSendKeys(params);
28
- };
29
- commands.doSendKeys = async function doSendKeys(params) {
30
- return await this.bootstrap.sendAction('setText', params);
31
- };
32
- /**
33
- * Retrieves the current device's timestamp.
34
- *
35
- * @param {string} format - The set of format specifiers. Read
36
- * https://momentjs.com/docs/ to get the full list of supported
37
- * datetime format specifiers. The default format is
38
- * `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601
39
- * @return {string} Formatted datetime string or the raw command output if formatting fails
40
- */
41
- commands.getDeviceTime = async function getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
42
- this.log.debug('Attempting to capture android device date and time. ' +
43
- `The format specifier is '${format}'`);
44
- const deviceTimestamp = (await this.adb.shell(['date', '+%Y-%m-%dT%T%z'])).trim();
45
- this.log.debug(`Got device timestamp: ${deviceTimestamp}`);
46
- const parsedTimestamp = moment_1.default.utc(deviceTimestamp, 'YYYY-MM-DDTHH:mm:ssZZ');
47
- if (!parsedTimestamp.isValid()) {
48
- this.log.warn('Cannot parse the returned timestamp. Returning as is');
49
- return deviceTimestamp;
50
- }
51
- return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
52
- };
53
- /**
54
- * @typedef {Object} DeviceTimeOptions
55
- * @property {string} format [YYYY-MM-DDTHH:mm:ssZ] - See getDeviceTime#format
56
- */
57
15
  /**
58
- * Retrieves the current device time
59
- *
60
- * @param {DeviceTimeOptions} opts
61
- * @return {string} Formatted datetime string or the raw command output if formatting fails
16
+ * @type {import('./mixins').GeneralMixin & ThisType<import('../driver').AndroidDriver>}
17
+ * @satisfies {import('@appium/types').ExternalDriver}
62
18
  */
63
- commands.mobileGetDeviceTime = async function mobileGetDeviceTime(opts = {}) {
64
- return await this.getDeviceTime(opts.format);
65
- };
66
- commands.getPageSource = async function getPageSource() {
67
- return await this.bootstrap.sendAction('source');
68
- };
69
- commands.back = async function back() {
70
- return await this.bootstrap.sendAction('pressBack');
71
- };
72
- commands.openSettingsActivity = async function openSettingsActivity(setting) {
73
- let { appPackage, appActivity } = await this.adb.getFocusedPackageAndActivity();
74
- await this.adb.shell(['am', 'start', '-a', `android.settings.${setting}`]);
75
- await this.adb.waitForNotActivity(appPackage, appActivity, 5000);
76
- };
77
- commands.getWindowSize = async function getWindowSize() {
78
- return await this.bootstrap.sendAction('getDeviceSize');
79
- };
80
- // For W3C
81
- commands.getWindowRect = async function getWindowRect() {
82
- const { width, height } = await this.getWindowSize();
83
- return {
84
- width,
85
- height,
86
- x: 0,
87
- y: 0
88
- };
89
- };
90
- commands.getCurrentActivity = async function getCurrentActivity() {
91
- return (await this.adb.getFocusedPackageAndActivity()).appActivity;
92
- };
93
- commands.getCurrentPackage = async function getCurrentPackage() {
94
- return (await this.adb.getFocusedPackageAndActivity()).appPackage;
95
- };
96
- commands.background = async function background(seconds) {
97
- if (seconds < 0) {
98
- // if user passes in a negative seconds value, interpret that as the instruction
99
- // to not bring the app back at all
100
- await this.adb.goToHome();
101
- return true;
102
- }
103
- let { appPackage, appActivity } = await this.adb.getFocusedPackageAndActivity();
104
- await this.adb.goToHome();
105
- // people can wait for a long time, so to be safe let's use the longSleep function and log
106
- // progress periodically.
107
- const sleepMs = seconds * 1000;
108
- const thresholdMs = 30 * 1000; // use the spin-wait for anything over this threshold
109
- // for our spin interval, use 1% of the total wait time, but nothing bigger than 30s
110
- const intervalMs = lodash_1.default.min([30 * 1000, parseInt(sleepMs / 100, 10)]);
111
- const progressCb = ({ elapsedMs, progress }) => {
112
- const waitSecs = (elapsedMs / 1000).toFixed(0);
113
- const progressPct = (progress * 100).toFixed(2);
114
- this.log.debug(`Waited ${waitSecs}s so far (${progressPct}%)`);
115
- };
116
- await (0, asyncbox_1.longSleep)(sleepMs, { thresholdMs, intervalMs, progressCb });
117
- let args;
118
- if (this._cachedActivityArgs && this._cachedActivityArgs[`${appPackage}/${appActivity}`]) {
119
- // the activity was started with `startActivity`, so use those args to restart
120
- args = this._cachedActivityArgs[`${appPackage}/${appActivity}`];
121
- }
122
- else {
123
- try {
124
- this.log.debug(`Activating app '${appPackage}' in order to restore it`);
125
- await this.activateApp(appPackage);
19
+ const GeneralMixin = {
20
+ _cachedActivityArgs: {},
21
+ async keys(keys) {
22
+ // Protocol sends an array; rethink approach
23
+ keys = lodash_1.default.isArray(keys) ? keys.join('') : keys;
24
+ /**
25
+ * @type {import('./types').SendKeysOpts}
26
+ */
27
+ const params = {
28
+ text: keys,
29
+ replace: false,
30
+ };
31
+ if (this.opts.unicodeKeyboard) {
32
+ params.unicodeKeyboard = true;
33
+ }
34
+ await this.doSendKeys(params);
35
+ },
36
+ async doSendKeys(params) {
37
+ return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('setText', params);
38
+ },
39
+ async getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
40
+ this.log.debug('Attempting to capture android device date and time. ' + `The format specifier is '${format}'`);
41
+ const deviceTimestamp = (await /** @type {ADB} */ (this.adb).shell(['date', '+%Y-%m-%dT%T%z'])).trim();
42
+ this.log.debug(`Got device timestamp: ${deviceTimestamp}`);
43
+ const parsedTimestamp = moment_1.default.utc(deviceTimestamp, 'YYYY-MM-DDTHH:mm:ssZZ');
44
+ if (!parsedTimestamp.isValid()) {
45
+ this.log.warn('Cannot parse the returned timestamp. Returning as is');
46
+ return deviceTimestamp;
47
+ }
48
+ // @ts-expect-error private API
49
+ return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
50
+ },
51
+ async mobileGetDeviceTime(opts = {}) {
52
+ return await this.getDeviceTime(opts.format);
53
+ },
54
+ async getPageSource() {
55
+ return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('source');
56
+ },
57
+ async back() {
58
+ return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('pressBack');
59
+ },
60
+ async openSettingsActivity(setting) {
61
+ const adb = /** @type {ADB} */ (this.adb);
62
+ let { appPackage, appActivity } = await adb.getFocusedPackageAndActivity();
63
+ await adb.shell(['am', 'start', '-a', `android.settings.${setting}`]);
64
+ await adb.waitForNotActivity(/** @type {string} */ (appPackage), appActivity, 5000);
65
+ },
66
+ async getWindowSize() {
67
+ return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('getDeviceSize');
68
+ },
69
+ // For W3C
70
+ async getWindowRect() {
71
+ const { width, height } = await this.getWindowSize();
72
+ return {
73
+ width,
74
+ height,
75
+ x: 0,
76
+ y: 0,
77
+ };
78
+ },
79
+ async getCurrentActivity() {
80
+ return (await /** @type {ADB} */ (this.adb).getFocusedPackageAndActivity()).appActivity;
81
+ },
82
+ async getCurrentPackage() {
83
+ return (await /** @type {ADB} */ (this.adb).getFocusedPackageAndActivity()).appPackage;
84
+ },
85
+ async background(seconds) {
86
+ const adb = /** @type {ADB} */ (this.adb);
87
+ if (seconds < 0) {
88
+ // if user passes in a negative seconds value, interpret that as the instruction
89
+ // to not bring the app back at all
90
+ await adb.goToHome();
126
91
  return true;
127
92
  }
128
- catch (ign) { }
129
- args = ((appPackage === this.opts.appPackage && appActivity === this.opts.appActivity) ||
130
- (appPackage === this.opts.appWaitPackage && (this.opts.appWaitActivity || '').split(',').includes(appActivity)))
131
- ? {
132
- pkg: this.opts.appPackage,
133
- activity: this.opts.appActivity,
134
- action: this.opts.intentAction,
135
- category: this.opts.intentCategory,
136
- flags: this.opts.intentFlags,
137
- waitPkg: this.opts.appWaitPackage,
138
- waitActivity: this.opts.appWaitActivity,
139
- waitForLaunch: this.opts.appWaitForLaunch,
140
- waitDuration: this.opts.appWaitDuration,
141
- optionalIntentArguments: this.opts.optionalIntentArguments,
142
- stopApp: false,
143
- user: this.opts.userProfile
93
+ let { appPackage, appActivity } = await adb.getFocusedPackageAndActivity();
94
+ await adb.goToHome();
95
+ // people can wait for a long time, so to be safe let's use the longSleep function and log
96
+ // progress periodically.
97
+ const sleepMs = seconds * 1000;
98
+ const thresholdMs = 30 * 1000; // use the spin-wait for anything over this threshold
99
+ // for our spin interval, use 1% of the total wait time, but nothing bigger than 30s
100
+ const intervalMs = lodash_1.default.min([30 * 1000, parseInt(String(sleepMs / 100), 10)]);
101
+ /**
102
+ *
103
+ * @param {{elapsedMs: number, progress: number}} param0
104
+ */
105
+ const progressCb = ({ elapsedMs, progress }) => {
106
+ const waitSecs = (elapsedMs / 1000).toFixed(0);
107
+ const progressPct = (progress * 100).toFixed(2);
108
+ this.log.debug(`Waited ${waitSecs}s so far (${progressPct}%)`);
109
+ };
110
+ await (0, asyncbox_1.longSleep)(sleepMs, { thresholdMs, intervalMs, progressCb });
111
+ /** @type {import('appium-adb').StartAppOptions} */
112
+ let args;
113
+ if (this._cachedActivityArgs && this._cachedActivityArgs[`${appPackage}/${appActivity}`]) {
114
+ // the activity was started with `startActivity`, so use those args to restart
115
+ args = this._cachedActivityArgs[`${appPackage}/${appActivity}`];
116
+ }
117
+ else {
118
+ try {
119
+ this.log.debug(`Activating app '${appPackage}' in order to restore it`);
120
+ await this.activateApp(/** @type {string} */ (appPackage));
121
+ return true;
144
122
  }
145
- : {
146
- pkg: appPackage,
147
- activity: appActivity,
148
- waitPkg: appPackage,
149
- waitActivity: appActivity,
150
- stopApp: false
151
- };
152
- }
153
- args = await support_1.util.filterObject(args);
154
- this.log.debug(`Bringing application back to foreground with arguments: ${JSON.stringify(args)}`);
155
- return await this.adb.startApp(args);
156
- };
157
- commands.getStrings = async function getStrings(language) {
158
- if (!language) {
159
- language = await this.adb.getDeviceLanguage();
160
- this.log.info(`No language specified, returning strings for: ${language}`);
161
- }
162
- // Clients require the resulting mapping to have both keys
163
- // and values of type string
164
- const preprocessStringsMap = (mapping) => {
165
- const result = {};
166
- for (const [key, value] of lodash_1.default.toPairs(mapping)) {
167
- result[key] = lodash_1.default.isString(value) ? value : JSON.stringify(value);
123
+ catch (ign) { }
124
+ args =
125
+ (appPackage === this.opts.appPackage && appActivity === this.opts.appActivity) ||
126
+ (appPackage === this.opts.appWaitPackage &&
127
+ (this.opts.appWaitActivity || '').split(',').includes(String(appActivity)))
128
+ ? {
129
+ // the activity is the original session activity, so use the original args
130
+ pkg: /** @type {string} */ (this.opts.appPackage),
131
+ activity: this.opts.appActivity,
132
+ action: this.opts.intentAction,
133
+ category: this.opts.intentCategory,
134
+ flags: this.opts.intentFlags,
135
+ waitPkg: this.opts.appWaitPackage,
136
+ waitActivity: this.opts.appWaitActivity,
137
+ waitForLaunch: this.opts.appWaitForLaunch,
138
+ waitDuration: this.opts.appWaitDuration,
139
+ optionalIntentArguments: this.opts.optionalIntentArguments,
140
+ stopApp: false,
141
+ user: this.opts.userProfile,
142
+ }
143
+ : {
144
+ // the activity was started some other way, so use defaults
145
+ pkg: /** @type {string} */ (appPackage),
146
+ activity: appActivity,
147
+ waitPkg: appPackage,
148
+ waitActivity: appActivity,
149
+ stopApp: false,
150
+ };
151
+ }
152
+ args = /** @type {import('appium-adb').StartAppOptions} */ (lodash_1.default.pickBy(args, (value) => !lodash_1.default.isUndefined(value)));
153
+ this.log.debug(`Bringing application back to foreground with arguments: ${JSON.stringify(args)}`);
154
+ return await adb.startApp(args);
155
+ },
156
+ async getStrings(language) {
157
+ const adb = /** @type {ADB} */ (this.adb);
158
+ if (!language) {
159
+ language = await adb.getDeviceLanguage();
160
+ this.log.info(`No language specified, returning strings for: ${language}`);
161
+ }
162
+ // Clients require the resulting mapping to have both keys
163
+ // and values of type string
164
+ /** @param {StringRecord} mapping */
165
+ const preprocessStringsMap = (mapping) => {
166
+ /** @type {StringRecord} */
167
+ const result = {};
168
+ for (const [key, value] of lodash_1.default.toPairs(mapping)) {
169
+ result[key] = lodash_1.default.isString(value) ? value : JSON.stringify(value);
170
+ }
171
+ return result;
172
+ };
173
+ if (this.apkStrings[language]) {
174
+ // Return cached strings
175
+ return preprocessStringsMap(this.apkStrings[language]);
176
+ }
177
+ this.apkStrings[language] = await android_1.default.pushStrings(language, adb, this.opts);
178
+ if (this.bootstrap) {
179
+ // TODO: This is mutating the current language, but it's how appium currently works
180
+ await this.bootstrap.sendAction('updateStrings');
168
181
  }
169
- return result;
170
- };
171
- if (this.apkStrings[language]) {
172
- // Return cached strings
173
182
  return preprocessStringsMap(this.apkStrings[language]);
174
- }
175
- this.apkStrings[language] = await android_helpers_1.default.pushStrings(language, this.adb, this.opts);
176
- if (this.bootstrap) {
177
- // TODO: This is mutating the current language, but it's how appium currently works
178
- await this.bootstrap.sendAction('updateStrings');
179
- }
180
- return preprocessStringsMap(this.apkStrings[language]);
181
- };
182
- commands.launchApp = async function launchApp() {
183
- await this.initAUT();
184
- await this.startAUT();
185
- };
186
- commands.startActivity = async function startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset) {
187
- this.log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);
188
- // dontStopAppOnReset is both an argument here, and a desired capability
189
- // if the argument is set, use it, otherwise use the cap
190
- if (!support_1.util.hasValue(dontStopAppOnReset)) {
191
- dontStopAppOnReset = !!this.opts.dontStopAppOnReset;
192
- }
193
- let args = {
194
- pkg: appPackage,
195
- activity: appActivity,
196
- waitPkg: appWaitPackage || appPackage,
197
- waitActivity: appWaitActivity || appActivity,
198
- action: intentAction,
199
- category: intentCategory,
200
- flags: intentFlags,
201
- optionalIntentArguments,
202
- stopApp: !dontStopAppOnReset
203
- };
204
- this._cachedActivityArgs = this._cachedActivityArgs || {};
205
- this._cachedActivityArgs[`${args.waitPkg}/${args.waitActivity}`] = args;
206
- await this.adb.startApp(args);
207
- };
208
- commands.reset = async function reset() {
209
- await android_helpers_1.default.resetApp(this.adb, Object.assign({}, this.opts, { fastReset: true }));
210
- // reset context since we don't know what kind on context we will end up after app launch.
211
- await this.setContext();
212
- return await this.isChromeSession ? this.startChromeSession() : this.startAUT();
213
- };
214
- commands.startAUT = async function startAUT() {
215
- await this.adb.startApp({
216
- pkg: this.opts.appPackage,
217
- activity: this.opts.appActivity,
218
- action: this.opts.intentAction,
219
- category: this.opts.intentCategory,
220
- flags: this.opts.intentFlags,
221
- waitPkg: this.opts.appWaitPackage,
222
- waitActivity: this.opts.appWaitActivity,
223
- waitForLaunch: this.opts.appWaitForLaunch,
224
- waitDuration: this.opts.appWaitDuration,
225
- optionalIntentArguments: this.opts.optionalIntentArguments,
226
- stopApp: !this.opts.dontStopAppOnReset,
227
- user: this.opts.userProfile,
228
- });
229
- };
230
- // we override setUrl to take an android URI which can be used for deep-linking
231
- // inside an app, similar to starting an intent
232
- commands.setUrl = async function setUrl(uri) {
233
- await this.adb.startUri(uri, this.opts.appPackage);
234
- };
235
- // closing app using force stop
236
- commands.closeApp = async function closeApp() {
237
- await this.adb.forceStop(this.opts.appPackage);
238
- // reset context since we don't know what kind on context we will end up after app launch.
239
- await this.setContext();
240
- };
241
- commands.getDisplayDensity = async function getDisplayDensity() {
242
- // first try the property for devices
243
- let out = await this.adb.shell(['getprop', 'ro.sf.lcd_density']);
244
- if (out) {
245
- let val = parseInt(out, 10);
246
- // if the value is NaN, try getting the emulator property
247
- if (!isNaN(val)) {
248
- return val;
183
+ },
184
+ async launchApp() {
185
+ await this.initAUT();
186
+ await this.startAUT();
187
+ },
188
+ async startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset) {
189
+ this.log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);
190
+ // dontStopAppOnReset is both an argument here, and a desired capability
191
+ // if the argument is set, use it, otherwise use the cap
192
+ if (!support_1.util.hasValue(dontStopAppOnReset)) {
193
+ dontStopAppOnReset = !!this.opts.dontStopAppOnReset;
249
194
  }
250
- this.log.debug(`Parsed density value was NaN: "${out}"`);
251
- }
252
- // fallback to trying property for emulators
253
- out = await this.adb.shell(['getprop', 'qemu.sf.lcd_density']);
254
- if (out) {
255
- let val = parseInt(out, 10);
256
- if (!isNaN(val)) {
257
- return val;
195
+ /** @type {import('appium-adb').StartAppOptions} */
196
+ let args = {
197
+ pkg: appPackage,
198
+ activity: appActivity,
199
+ waitPkg: appWaitPackage || appPackage,
200
+ waitActivity: appWaitActivity || appActivity,
201
+ action: intentAction,
202
+ category: intentCategory,
203
+ flags: intentFlags,
204
+ optionalIntentArguments,
205
+ stopApp: !dontStopAppOnReset,
206
+ };
207
+ this._cachedActivityArgs = this._cachedActivityArgs || {};
208
+ this._cachedActivityArgs[`${args.waitPkg}/${args.waitActivity}`] = args;
209
+ await /** @type {ADB} */ (this.adb).startApp(args);
210
+ },
211
+ async reset() {
212
+ await android_1.default.resetApp(
213
+ /** @type {ADB} */ (this.adb), Object.assign({}, this.opts, { fastReset: true }));
214
+ // reset context since we don't know what kind on context we will end up after app launch.
215
+ await this.setContext();
216
+ return this.isChromeSession ? this.startChromeSession() : this.startAUT();
217
+ },
218
+ async startAUT() {
219
+ await /** @type {ADB} */ (this.adb).startApp({
220
+ pkg: /** @type {string} */ (this.opts.appPackage),
221
+ activity: this.opts.appActivity,
222
+ action: this.opts.intentAction,
223
+ category: this.opts.intentCategory,
224
+ flags: this.opts.intentFlags,
225
+ waitPkg: this.opts.appWaitPackage,
226
+ waitActivity: this.opts.appWaitActivity,
227
+ waitForLaunch: this.opts.appWaitForLaunch,
228
+ waitDuration: this.opts.appWaitDuration,
229
+ optionalIntentArguments: this.opts.optionalIntentArguments,
230
+ stopApp: !this.opts.dontStopAppOnReset,
231
+ user: this.opts.userProfile,
232
+ });
233
+ },
234
+ // we override setUrl to take an android URI which can be used for deep-linking
235
+ // inside an app, similar to starting an intent
236
+ async setUrl(uri) {
237
+ await /** @type {ADB} */ (this.adb).startUri(uri, /** @type {string} */ (this.opts.appPackage));
238
+ },
239
+ // closing app using force stop
240
+ async closeApp() {
241
+ await /** @type {ADB} */ (this.adb).forceStop(/** @type {string} */ (this.opts.appPackage));
242
+ // reset context since we don't know what kind on context we will end up after app launch.
243
+ await this.setContext();
244
+ },
245
+ async getDisplayDensity() {
246
+ // first try the property for devices
247
+ let out = await /** @type {ADB} */ (this.adb).shell(['getprop', 'ro.sf.lcd_density']);
248
+ if (out) {
249
+ let val = parseInt(out, 10);
250
+ // if the value is NaN, try getting the emulator property
251
+ if (!isNaN(val)) {
252
+ return val;
253
+ }
254
+ this.log.debug(`Parsed density value was NaN: "${out}"`);
258
255
  }
259
- this.log.debug(`Parsed density value was NaN: "${out}"`);
260
- }
261
- // couldn't get anything, so error out
262
- this.log.errorAndThrow('Failed to get display density property.');
263
- };
264
- commands.mobilePerformEditorAction = async function mobilePerformEditorAction(opts = {}) {
265
- const { action } = opts;
266
- if (!support_1.util.hasValue(action)) {
267
- throw new driver_1.errors.InvalidArgumentError(`'action' argument is required`);
268
- }
269
- await this.adb.performEditorAction(action);
270
- };
271
- /**
272
- * Retrieves the list of recent system notifications.
273
- *
274
- * @returns {Object} See the documentation on `adb.getNotifications` for
275
- * more details
276
- */
277
- commands.mobileGetNotifications = async function mobileGetNotifications() {
278
- return await this.adb.getNotifications();
279
- };
280
- /**
281
- * @typedef {Object} SmsListOptions
282
- * @property {number} max [100] - The maximum count of recent SMS messages
283
- * to retrieve
284
- */
285
- /**
286
- * Retrieves the list of recent SMS messages with their properties.
287
- *
288
- * @param {SmsListOptions} opts
289
- * @returns {Object} See the documentation on `adb.getSmsList` for
290
- * more details
291
- */
292
- commands.mobileListSms = async function mobileListSms(opts = {}) {
293
- return await this.adb.getSmsList(opts);
256
+ // fallback to trying property for emulators
257
+ out = await /** @type {ADB} */ (this.adb).shell(['getprop', 'qemu.sf.lcd_density']);
258
+ if (out) {
259
+ let val = parseInt(out, 10);
260
+ if (!isNaN(val)) {
261
+ return val;
262
+ }
263
+ this.log.debug(`Parsed density value was NaN: "${out}"`);
264
+ }
265
+ // couldn't get anything, so error out
266
+ this.log.errorAndThrow('Failed to get display density property.');
267
+ throw new Error(); // unreachable
268
+ },
269
+ async mobilePerformEditorAction(opts) {
270
+ const { action } = (0, utils_1.requireArgs)('action', opts);
271
+ await /** @type {ADB} */ (this.adb).performEditorAction(action);
272
+ },
273
+ async mobileGetNotifications() {
274
+ return await /** @type {ADB} */ (this.adb).getNotifications();
275
+ },
276
+ async mobileListSms(opts) {
277
+ return await /** @type {ADB} */ (this.adb).getSmsList(opts);
278
+ },
279
+ async mobileUnlock(opts = {}) {
280
+ const { key, type, strategy, timeoutMs } = opts;
281
+ if (!key && !type) {
282
+ await this.unlock();
283
+ }
284
+ else {
285
+ // @ts-expect-error XXX: these caps should be defined in the constraints!!
286
+ await android_1.default.unlock(this, /** @type {ADB} */ (this.adb), {
287
+ unlockKey: key,
288
+ unlockType: type,
289
+ unlockStrategy: strategy,
290
+ unlockSuccessTimeout: timeoutMs,
291
+ });
292
+ }
293
+ },
294
294
  };
295
+ (0, mixins_1.mixin)(GeneralMixin);
296
+ exports.default = GeneralMixin;
295
297
  /**
296
- * @typedef {Object} UnlockOptions
297
- * @property {string?} key The unlock key. The value of this key depends
298
- * on the actual unlock type and could be a pin/password/pattern value or
299
- * a biometric finger id.
300
- * If not provided then the corresponding value from session capabilities is used.
301
- * @property {string?} type The unlock type. The following unlock types
302
- * are supported: `pin`, `pinWithKeyEvent`, `password`, `pattern` and `fingerprint`.
303
- * If not provided then the corresponding value from session capabilities is used.
304
- * @property {string?} strategy Either 'locksettings' (default) or 'uiautomator'.
305
- * Setting it to 'uiautomator' will enforce the driver to avoid using special
306
- * ADB shortcuts in order to speed up the unlock procedure.
307
- * @property {number?} timeoutMs [2000] The maximum time in milliseconds
308
- * to wait until the screen gets unlocked
309
- */
310
- /**
311
- * Unlocks the device if it is locked. Noop if the device's screen is not locked.
312
- *
313
- * @param {UnlockOptions} opts
314
- * @throws {Error} if unlock operation fails or the provided
315
- * arguments are not valid
298
+ * @typedef {import('../bootstrap').AndroidBootstrap} AndroidBootstrap
299
+ * @typedef {import('appium-adb').ADB} ADB
300
+ * @typedef {import('@appium/types').StringRecord} StringRecord
316
301
  */
317
- commands.mobileUnlock = async function mobileUnlock(opts = {}) {
318
- const { key, type, strategy, timeoutMs } = opts;
319
- if (!key && !type) {
320
- await this.unlock();
321
- }
322
- else {
323
- await android_helpers_1.default.unlock(this, this.adb, {
324
- unlockKey: key,
325
- unlockType: type,
326
- unlockStrategy: strategy,
327
- unlockSuccessTimeout: timeoutMs,
328
- });
329
- }
330
- };
331
- Object.assign(extensions, commands, helpers);
332
- exports.default = extensions;
333
302
  //# sourceMappingURL=general.js.map