appium-android-driver 5.14.0-alpha.0 → 5.14.0-alpha2

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 (88) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/index.d.ts +282 -0
  3. package/build/index.d.ts.map +1 -0
  4. package/build/index.js +34 -20
  5. package/build/index.js.map +1 -0
  6. package/build/lib/android-helpers.d.ts +136 -0
  7. package/build/lib/android-helpers.d.ts.map +1 -0
  8. package/build/lib/android-helpers.js +855 -0
  9. package/build/lib/android-helpers.js.map +1 -0
  10. package/build/lib/bootstrap.d.ts +2 -2
  11. package/build/lib/commands/actions.d.ts.map +1 -1
  12. package/build/lib/commands/actions.js +4 -0
  13. package/build/lib/commands/actions.js.map +1 -1
  14. package/build/lib/commands/context.js +1 -1
  15. package/build/lib/commands/context.js.map +1 -1
  16. package/build/lib/commands/coverage.d.ts +5 -0
  17. package/build/lib/commands/coverage.d.ts.map +1 -0
  18. package/build/lib/commands/coverage.js +19 -0
  19. package/build/lib/commands/coverage.js.map +1 -0
  20. package/build/lib/commands/execute.d.ts.map +1 -1
  21. package/build/lib/commands/execute.js +4 -3
  22. package/build/lib/commands/execute.js.map +1 -1
  23. package/build/lib/commands/find.d.ts +4 -1
  24. package/build/lib/commands/find.d.ts.map +1 -1
  25. package/build/lib/commands/find.js +1 -0
  26. package/build/lib/commands/find.js.map +1 -1
  27. package/build/lib/commands/index.d.ts +27 -47
  28. package/build/lib/commands/index.d.ts.map +1 -1
  29. package/build/lib/commands/index.js.map +1 -1
  30. package/build/lib/commands/log.d.ts.map +1 -1
  31. package/build/lib/commands/log.js +2 -2
  32. package/build/lib/commands/log.js.map +1 -1
  33. package/build/lib/commands/mixins.d.ts +11 -6
  34. package/build/lib/commands/mixins.d.ts.map +1 -1
  35. package/build/lib/commands/mixins.js.map +1 -1
  36. package/build/lib/commands/performance.d.ts +4 -4
  37. package/build/lib/commands/performance.d.ts.map +1 -1
  38. package/build/lib/commands/types.d.ts +8 -1
  39. package/build/lib/commands/types.d.ts.map +1 -1
  40. package/build/lib/constraints.d.ts +289 -384
  41. package/build/lib/constraints.d.ts.map +1 -1
  42. package/build/lib/constraints.js +2 -9
  43. package/build/lib/constraints.js.map +1 -1
  44. package/build/lib/desired-caps.d.ts +353 -0
  45. package/build/lib/desired-caps.d.ts.map +1 -0
  46. package/build/lib/desired-caps.js +299 -0
  47. package/build/lib/desired-caps.js.map +1 -0
  48. package/build/lib/driver.d.ts +50 -403
  49. package/build/lib/driver.d.ts.map +1 -1
  50. package/build/lib/driver.js +67 -127
  51. package/build/lib/driver.js.map +1 -1
  52. package/build/lib/helpers/android.d.ts +11 -11
  53. package/build/lib/helpers/android.d.ts.map +1 -1
  54. package/build/lib/helpers/android.js.map +1 -1
  55. package/build/lib/helpers/unlock.d.ts +2 -1
  56. package/build/lib/helpers/unlock.d.ts.map +1 -1
  57. package/build/lib/helpers/unlock.js.map +1 -1
  58. package/build/lib/index.d.ts +9 -0
  59. package/build/lib/index.d.ts.map +1 -0
  60. package/build/lib/index.js +37 -0
  61. package/build/lib/index.js.map +1 -0
  62. package/build/lib/uiautomator.d.ts +6 -6
  63. package/build/lib/unlock-helpers.d.ts +38 -0
  64. package/build/lib/unlock-helpers.d.ts.map +1 -0
  65. package/build/lib/unlock-helpers.js +266 -0
  66. package/build/lib/unlock-helpers.js.map +1 -0
  67. package/build/lib/webview-helpers.d.ts +223 -0
  68. package/build/lib/webview-helpers.d.ts.map +1 -0
  69. package/build/lib/webview-helpers.js +530 -0
  70. package/build/lib/webview-helpers.js.map +1 -0
  71. package/lib/commands/actions.js +5 -0
  72. package/lib/commands/context.js +1 -1
  73. package/lib/commands/execute.js +7 -3
  74. package/lib/commands/find.ts +2 -0
  75. package/lib/commands/{index.js → index.ts} +2 -0
  76. package/lib/commands/log.js +6 -4
  77. package/lib/commands/mixins.ts +11 -7
  78. package/lib/commands/types.ts +9 -1
  79. package/lib/{constraints.js → constraints.ts} +6 -9
  80. package/lib/{driver.js → driver.ts} +143 -183
  81. package/lib/helpers/android.ts +31 -14
  82. package/lib/helpers/unlock.ts +2 -1
  83. package/lib/index.ts +18 -0
  84. package/package.json +14 -14
  85. package/build/lib/commands/mixin.d.ts +0 -3
  86. package/build/lib/commands/mixin.d.ts.map +0 -1
  87. package/build/lib/commands/mixin.js +0 -6
  88. package/build/lib/commands/mixin.js.map +0 -1
@@ -0,0 +1,530 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KNOWN_CHROME_PACKAGE_NAMES = exports.CHROMIUM_WIN = exports.WEBVIEW_BASE = exports.WEBVIEW_WIN = exports.NATIVE_WIN = exports.helpers = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const logger_1 = __importDefault(require("./logger"));
9
+ const axios_1 = __importDefault(require("axios"));
10
+ const support_1 = require("@appium/support");
11
+ const portscanner_1 = require("portscanner");
12
+ const lru_cache_1 = __importDefault(require("lru-cache"));
13
+ const bluebird_1 = __importDefault(require("bluebird"));
14
+ const path_1 = __importDefault(require("path"));
15
+ const os_1 = __importDefault(require("os"));
16
+ const NATIVE_WIN = 'NATIVE_APP';
17
+ exports.NATIVE_WIN = NATIVE_WIN;
18
+ const WEBVIEW_WIN = 'WEBVIEW';
19
+ exports.WEBVIEW_WIN = WEBVIEW_WIN;
20
+ const CHROMIUM_WIN = 'CHROMIUM';
21
+ exports.CHROMIUM_WIN = CHROMIUM_WIN;
22
+ const WEBVIEW_BASE = `${WEBVIEW_WIN}_`;
23
+ exports.WEBVIEW_BASE = WEBVIEW_BASE;
24
+ const WEBVIEW_PID_PATTERN = new RegExp(`^${WEBVIEW_BASE}(\\d+)`);
25
+ const WEBVIEW_PKG_PATTERN = new RegExp(`^${WEBVIEW_BASE}([^\\d\\s][\\w.]*)`);
26
+ const DEVTOOLS_SOCKET_PATTERN = /@[\w.]+_devtools_remote_?(\d+)?\b/;
27
+ const CROSSWALK_SOCKET_PATTERN = /@([\w.]+)_devtools_remote\b/;
28
+ const CHROMIUM_DEVTOOLS_SOCKET = 'chrome_devtools_remote';
29
+ const CHROME_PACKAGE_NAME = 'com.android.chrome';
30
+ const KNOWN_CHROME_PACKAGE_NAMES = [
31
+ CHROME_PACKAGE_NAME,
32
+ 'com.chrome.beta',
33
+ 'com.chrome.dev',
34
+ 'com.chrome.canary',
35
+ ];
36
+ exports.KNOWN_CHROME_PACKAGE_NAMES = KNOWN_CHROME_PACKAGE_NAMES;
37
+ const DEVTOOLS_PORTS_RANGE = [10900, 11000];
38
+ const WEBVIEWS_DETAILS_CACHE = new lru_cache_1.default({
39
+ max: 100,
40
+ updateAgeOnGet: true,
41
+ });
42
+ const CDP_REQ_TIMEOUT = 2000; // ms
43
+ const DEVTOOLS_PORT_ALLOCATION_GUARD = support_1.util.getLockFileGuard(path_1.default.resolve(os_1.default.tmpdir(), 'android_devtools_port_guard'), { timeout: 7, tryRecovery: true });
44
+ const helpers = {};
45
+ exports.helpers = helpers;
46
+ function toDetailsCacheKey(adb, webview) {
47
+ return `${adb?.curDeviceId}:${webview}`;
48
+ }
49
+ /**
50
+ * This function gets a list of android system processes and returns ones
51
+ * that look like webviews
52
+ * See https://cs.chromium.org/chromium/src/chrome/browser/devtools/device/android_device_info_query.cc
53
+ * for more details
54
+ *
55
+ * @param {object} adb - an ADB instance
56
+ *
57
+ * @return {Array.<string>} - a list of matching webview socket names (including the leading '@')
58
+ */
59
+ async function getPotentialWebviewProcs(adb) {
60
+ const out = await adb.shell(['cat', '/proc/net/unix']);
61
+ const names = [];
62
+ const allMatches = [];
63
+ for (const line of out.split('\n')) {
64
+ // Num RefCount Protocol Flags Type St Inode Path
65
+ const [, , , flags, , st, , sockPath] = line.trim().split(/\s+/);
66
+ if (!sockPath) {
67
+ continue;
68
+ }
69
+ if (sockPath.startsWith('@')) {
70
+ allMatches.push(line.trim());
71
+ }
72
+ if (flags !== '00010000' || st !== '01') {
73
+ continue;
74
+ }
75
+ if (!DEVTOOLS_SOCKET_PATTERN.test(sockPath)) {
76
+ continue;
77
+ }
78
+ names.push(sockPath);
79
+ }
80
+ if (lodash_1.default.isEmpty(names)) {
81
+ logger_1.default.debug('Found no active devtools sockets');
82
+ if (!lodash_1.default.isEmpty(allMatches)) {
83
+ logger_1.default.debug(`Other sockets are: ${JSON.stringify(allMatches, null, 2)}`);
84
+ }
85
+ }
86
+ else {
87
+ logger_1.default.debug(`Parsed ${names.length} active devtools ${support_1.util.pluralize('socket', names.length, false)}: ` +
88
+ JSON.stringify(names));
89
+ }
90
+ // sometimes the webview process shows up multiple times per app
91
+ return lodash_1.default.uniq(names);
92
+ }
93
+ /**
94
+ * @typedef {Object} WebviewProc
95
+ * @property {string} proc - The webview process name (as returned by
96
+ * getPotentialWebviewProcs
97
+ * @property {string} webview - The actual webview context name
98
+ */
99
+ /**
100
+ * This function retrieves a list of system processes that look like webviews,
101
+ * and returns them along with the webview context name appropriate for it.
102
+ * If we pass in a deviceSocket, we only attempt to find webviews which match
103
+ * that socket name (this is for apps which embed Chromium, which isn't the
104
+ * same as chrome-backed webviews).
105
+ *
106
+ * @param {object} adb - an ADB instance
107
+ * @param {?string} deviceSocket - the explictly-named device socket to use
108
+ *
109
+ * @return {Array.<WebviewProc>}
110
+ */
111
+ async function webviewsFromProcs(adb, deviceSocket = null) {
112
+ const socketNames = await getPotentialWebviewProcs(adb);
113
+ const webviews = [];
114
+ for (const socketName of socketNames) {
115
+ if (deviceSocket === CHROMIUM_DEVTOOLS_SOCKET && socketName === `@${deviceSocket}`) {
116
+ webviews.push({
117
+ proc: socketName,
118
+ webview: CHROMIUM_WIN,
119
+ });
120
+ continue;
121
+ }
122
+ const socketNameMatch = DEVTOOLS_SOCKET_PATTERN.exec(socketName);
123
+ if (!socketNameMatch) {
124
+ continue;
125
+ }
126
+ const crosswalkMatch = CROSSWALK_SOCKET_PATTERN.exec(socketName);
127
+ if (!socketNameMatch[1] && !crosswalkMatch) {
128
+ continue;
129
+ }
130
+ if (deviceSocket && socketName === `@${deviceSocket}` || !deviceSocket) {
131
+ webviews.push({
132
+ proc: socketName,
133
+ webview: socketNameMatch[1]
134
+ ? `${WEBVIEW_BASE}${socketNameMatch[1]}`
135
+ : `${WEBVIEW_BASE}${crosswalkMatch[1]}`,
136
+ });
137
+ }
138
+ }
139
+ return webviews;
140
+ }
141
+ /**
142
+ * Allocates a local port for devtools communication
143
+ *
144
+ * @param {ADB} adb ADB instance
145
+ * @param {string} socketName The remote Unix socket name
146
+ * @param {?number} webviewDevtoolsPort The local port number or null to apply
147
+ * autodetection
148
+ * @returns {number} The local port number if the remote socket has been forwarded
149
+ * successfully or `null` otherwise
150
+ * @throws {Error} If there was an error while allocating the local port
151
+ */
152
+ async function allocateDevtoolsPort(adb, socketName, webviewDevtoolsPort = null) {
153
+ // socket names come with '@', but this should not be a part of the abstract
154
+ // remote port, so remove it
155
+ const remotePort = socketName.replace(/^@/, '');
156
+ let [startPort, endPort] = DEVTOOLS_PORTS_RANGE;
157
+ if (webviewDevtoolsPort) {
158
+ endPort = webviewDevtoolsPort + (endPort - startPort);
159
+ startPort = webviewDevtoolsPort;
160
+ }
161
+ logger_1.default.debug(`Forwarding remote port ${remotePort} to a local ` +
162
+ `port in range ${startPort}..${endPort}`);
163
+ if (!webviewDevtoolsPort) {
164
+ logger_1.default.debug(`You could use the 'webviewDevtoolsPort' capability to customize ` +
165
+ `the starting port number`);
166
+ }
167
+ return await DEVTOOLS_PORT_ALLOCATION_GUARD(async () => {
168
+ let localPort;
169
+ try {
170
+ localPort = await (0, portscanner_1.findAPortNotInUse)(startPort, endPort);
171
+ }
172
+ catch (e) {
173
+ throw new Error(`Cannot find any free port to forward the Devtools socket ` +
174
+ `in range ${startPort}..${endPort}. You could set the starting port number ` +
175
+ `manually by providing the 'webviewDevtoolsPort' capability`);
176
+ }
177
+ await adb.adbExec(['forward', `tcp:${localPort}`, `localabstract:${remotePort}`]);
178
+ return localPort;
179
+ });
180
+ }
181
+ /**
182
+ * @typedef {Object} WebviewProps
183
+ * @property {string} proc The name of the Devtools Unix socket
184
+ * @property {string} webview The web view alias. Looks like `WEBVIEW_`
185
+ * prefix plus PID or package name
186
+ * @property {?Object} info Webview information as it is retrieved by
187
+ * /json/version CDP endpoint
188
+ * @property {?Array<Object>} pages Webview pages list as it is retrieved by
189
+ * /json/list CDP endpoint
190
+ */
191
+ /**
192
+ * @typedef {Object} DetailCollectionOptions
193
+ * @property {?string|number} webviewDevtoolsPort The starting port to use for webview page
194
+ * presence check (if not the default of 9222).
195
+ * @property {?boolean} ensureWebviewsHavePages Whether to check for webview
196
+ * pages presence
197
+ * @property {boolean} enableWebviewDetailsCollection Whether to collect
198
+ * web view details and send them to Chromedriver constructor, so it could
199
+ * select a binary more precisely based on this info.
200
+ */
201
+ /**
202
+ * This is a wrapper for Chrome Debugger Protocol data collection.
203
+ * No error is thrown if CDP request fails - in such case no data will be
204
+ * recorded into the corresponding `webviewsMapping` item.
205
+ *
206
+ * @param {ADB} adb The ADB instance
207
+ * @param {Array<WebviewProps>} webviewsMapping The current webviews mapping
208
+ * !!! Each item of this array gets mutated (`info`/`pages` properties get added
209
+ * based on the provided `opts`) if the requested details have been
210
+ * successfully retrieved for it !!!
211
+ * @param {DetailCollectionOptions} opts If both `ensureWebviewsHavePages` and
212
+ * `enableWebviewDetailsCollection` properties are falsy then no details collection
213
+ * is performed
214
+ */
215
+ async function collectWebviewsDetails(adb, webviewsMapping, opts = {}) {
216
+ if (lodash_1.default.isEmpty(webviewsMapping)) {
217
+ return;
218
+ }
219
+ const { webviewDevtoolsPort = null, ensureWebviewsHavePages = null, enableWebviewDetailsCollection = null, } = opts;
220
+ if (!ensureWebviewsHavePages) {
221
+ logger_1.default.info(`Not checking whether webviews have active pages; use the ` +
222
+ `'ensureWebviewsHavePages' cap to turn this check on`);
223
+ }
224
+ if (!enableWebviewDetailsCollection) {
225
+ logger_1.default.info(`Not collecting web view details. Details collection might help ` +
226
+ `to make Chromedriver initialization more precise. Use the 'enableWebviewDetailsCollection' ` +
227
+ `cap to turn it on`);
228
+ }
229
+ if (!ensureWebviewsHavePages && !enableWebviewDetailsCollection) {
230
+ return;
231
+ }
232
+ // Connect to each devtools socket and retrieve web view details
233
+ logger_1.default.debug(`Collecting CDP data of ${support_1.util.pluralize('webview', webviewsMapping.length, true)}`);
234
+ const detailCollectors = [];
235
+ for (const item of webviewsMapping) {
236
+ detailCollectors.push((async () => {
237
+ let localPort;
238
+ try {
239
+ localPort = await allocateDevtoolsPort(adb, item.proc, webviewDevtoolsPort);
240
+ if (enableWebviewDetailsCollection) {
241
+ item.info = await cdpInfo(localPort);
242
+ }
243
+ if (ensureWebviewsHavePages) {
244
+ item.pages = await cdpList(localPort);
245
+ }
246
+ }
247
+ catch (e) {
248
+ logger_1.default.debug(e);
249
+ }
250
+ finally {
251
+ if (localPort) {
252
+ try {
253
+ await adb.removePortForward(localPort);
254
+ }
255
+ catch (e) {
256
+ logger_1.default.debug(e);
257
+ }
258
+ }
259
+ }
260
+ })());
261
+ }
262
+ await bluebird_1.default.all(detailCollectors);
263
+ logger_1.default.debug(`CDP data collection completed`);
264
+ }
265
+ // https://chromedevtools.github.io/devtools-protocol/
266
+ async function cdpList(localPort) {
267
+ return (await (0, axios_1.default)({
268
+ url: `http://127.0.0.1:${localPort}/json/list`,
269
+ timeout: CDP_REQ_TIMEOUT,
270
+ })).data;
271
+ }
272
+ // https://chromedevtools.github.io/devtools-protocol/
273
+ async function cdpInfo(localPort) {
274
+ return (await (0, axios_1.default)({
275
+ url: `http://127.0.0.1:${localPort}/json/version`,
276
+ timeout: CDP_REQ_TIMEOUT,
277
+ })).data;
278
+ }
279
+ /**
280
+ * Take a webview name like WEBVIEW_4296 and use 'adb shell ps' to figure out
281
+ * which app package is associated with that webview. One of the reasons we
282
+ * want to do this is to make sure we're listing webviews for the actual AUT,
283
+ * not some other running app
284
+ *
285
+ * @param {object} adb - an ADB instance
286
+ * @param {string} webview - a webview process name
287
+ *
288
+ * @returns {string} - the package name of the app running the webview
289
+ * @throws {Error} If there was a failure while retrieving the process name
290
+ */
291
+ helpers.procFromWebview = async function procFromWebview(adb, webview) {
292
+ const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);
293
+ if (!pidMatch) {
294
+ throw new Error(`Could not find PID for webview '${webview}'`);
295
+ }
296
+ const pid = pidMatch[1];
297
+ logger_1.default.debug(`${webview} mapped to pid ${pid}`);
298
+ logger_1.default.debug(`Getting process name for webview '${webview}'`);
299
+ const pkg = await adb.getNameByPid(pid);
300
+ logger_1.default.debug(`Got process name: '${pkg}'`);
301
+ return pkg;
302
+ };
303
+ /**
304
+ * Parse webview names for getContexts
305
+ *
306
+ * @param {Array<WebviewsMapping>} webviewsMapping See note on getWebViewsMapping
307
+ * @param {GetWebviewsOpts} opts See note on getWebViewsMapping
308
+ * @return {Array.<string>} - a list of webview names
309
+ */
310
+ helpers.parseWebviewNames = function parseWebviewNames(webviewsMapping, { ensureWebviewsHavePages = true, isChromeSession = false } = {}) {
311
+ if (isChromeSession) {
312
+ return [CHROMIUM_WIN];
313
+ }
314
+ const result = [];
315
+ for (const { webview, pages, proc, webviewName } of webviewsMapping) {
316
+ if (ensureWebviewsHavePages && pages?.length === 0) {
317
+ logger_1.default.info(`Skipping the webview '${webview}' at '${proc}' ` +
318
+ `since it has reported having zero pages`);
319
+ continue;
320
+ }
321
+ if (webviewName) {
322
+ result.push(webviewName);
323
+ }
324
+ }
325
+ logger_1.default.debug(`Found ${support_1.util.pluralize('webview', result.length, true)}: ${JSON.stringify(result)}`);
326
+ return result;
327
+ };
328
+ /**
329
+ * @typedef {Object} GetWebviewsOpts
330
+ * @property {string} androidDeviceSocket [null] - device socket name
331
+ * @property {boolean} ensureWebviewsHavePages [true] - whether to check for webview
332
+ * page presence
333
+ * @property {number} webviewDevtoolsPort [9222] - port to use for webview page
334
+ * presence check.
335
+ * @property {boolean} enableWebviewDetailsCollection [true] - whether to collect
336
+ * web view details and send them to Chromedriver constructor, so it could
337
+ * select a binary more precisely based on this info.
338
+ */
339
+ /**
340
+ * @typedef {Object} WebviewsMapping
341
+ * @property {string} proc See note on WebviewProps
342
+ * @property {string} webview See note on WebviewProps
343
+ * @property {?Object} info See note on WebviewProps
344
+ * @property {?Array<Object>} pages See note on WebviewProps
345
+ * @propery {?string} webviewName An actual webview name for switching context
346
+ */
347
+ /**
348
+ * Get a list of available webviews mapping by introspecting processes with adb,
349
+ * where webviews are listed. It's possible to pass in a 'deviceSocket' arg, which
350
+ * limits the webview possibilities to the one running on the Chromium devtools
351
+ * socket we're interested in (see note on webviewsFromProcs). We can also
352
+ * direct this method to verify whether a particular webview process actually
353
+ * has any pages (if a process exists but no pages are found, Chromedriver will
354
+ * not actually be able to connect to it, so this serves as a guard for that
355
+ * strange failure mode). The strategy for checking whether any pages are
356
+ * active involves sending a request to the remote debug server on the device,
357
+ * hence it is also possible to specify the port on the host machine which
358
+ * should be used for this communication.
359
+ *
360
+ * @param {object} adb - an ADB instance
361
+ * @param {GetWebviewsOpts} opts
362
+ *
363
+ * @return {Array<WebviewsMapping>} webviewsMapping
364
+ */
365
+ helpers.getWebViewsMapping = async function getWebViewsMapping(adb, { androidDeviceSocket = null, ensureWebviewsHavePages = true, webviewDevtoolsPort = null, enableWebviewDetailsCollection = true } = {}) {
366
+ logger_1.default.debug('Getting a list of available webviews');
367
+ const webviewsMapping = await webviewsFromProcs(adb, androidDeviceSocket);
368
+ await collectWebviewsDetails(adb, webviewsMapping, {
369
+ ensureWebviewsHavePages,
370
+ enableWebviewDetailsCollection,
371
+ webviewDevtoolsPort,
372
+ });
373
+ for (const webviewMapping of webviewsMapping) {
374
+ const { webview, info } = webviewMapping;
375
+ webviewMapping.webviewName = null;
376
+ let wvName = webview;
377
+ let process = undefined;
378
+ if (!androidDeviceSocket) {
379
+ const pkgMatch = WEBVIEW_PKG_PATTERN.exec(webview);
380
+ try {
381
+ // web view name could either be suffixed with PID or the package name
382
+ // package names could not start with a digit
383
+ const pkg = pkgMatch ? pkgMatch[1] : await helpers.procFromWebview(adb, webview);
384
+ wvName = `${WEBVIEW_BASE}${pkg}`;
385
+ const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);
386
+ process = {
387
+ name: pkg,
388
+ id: pidMatch ? pidMatch[1] : null,
389
+ };
390
+ }
391
+ catch (e) {
392
+ logger_1.default.warn(e.message);
393
+ continue;
394
+ }
395
+ }
396
+ webviewMapping.webviewName = wvName;
397
+ const key = toDetailsCacheKey(adb, wvName);
398
+ if (info || process) {
399
+ WEBVIEWS_DETAILS_CACHE.set(key, { info, process });
400
+ }
401
+ else if (WEBVIEWS_DETAILS_CACHE.has(key)) {
402
+ WEBVIEWS_DETAILS_CACHE.delete(key);
403
+ }
404
+ }
405
+ return webviewsMapping;
406
+ };
407
+ /**
408
+ * @typedef {Object} ProcessInfo
409
+ * @property {string} name The process name
410
+ * @property {?string} id The process id (if could be retrieved)
411
+ */
412
+ /**
413
+ * @typedef {Object} WebViewDetails
414
+ * @property {?ProcessInfo} process - Web view process details
415
+ * @property {Object} info - Web view details as returned by /json/version CDP endpoint, for example:
416
+ * {
417
+ * "Browser": "Chrome/72.0.3601.0",
418
+ * "Protocol-Version": "1.3",
419
+ * "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3601.0 Safari/537.36",
420
+ * "V8-Version": "7.2.233",
421
+ * "WebKit-Version": "537.36 (@cfede9db1d154de0468cb0538479f34c0755a0f4)",
422
+ * "webSocketDebuggerUrl": "ws://localhost:9222/devtools/browser/b0b8a4fb-bb17-4359-9533-a8d9f3908bd8"
423
+ * }
424
+ */
425
+ /**
426
+ * Retrieves web view details previously cached by `getWebviews` call
427
+ *
428
+ * @param {ADB} adb ADB instance
429
+ * @param {string} webview The name of the web view
430
+ * @returns {?WebViewDetails} Either `undefined` or the recent web view details
431
+ */
432
+ helpers.getWebviewDetails = function getWebviewDetails(adb, webview) {
433
+ const key = toDetailsCacheKey(adb, webview);
434
+ return WEBVIEWS_DETAILS_CACHE.get(key);
435
+ };
436
+ /**
437
+ * Create Chrome driver capabilities based on the provided
438
+ * Appium capabilities
439
+ *
440
+ * @param {Object} opts User-provided capabilities object
441
+ * @param {string} deviceId The identifier of the Android device under test
442
+ * @param {?WebViewDetails} webViewDetails
443
+ * @returns {Object} The capabilities object.
444
+ * See https://chromedriver.chromium.org/capabilities for more details.
445
+ */
446
+ helpers.createChromedriverCaps = function createChromedriverCaps(opts, deviceId, webViewDetails) {
447
+ const caps = { chromeOptions: {} };
448
+ const androidPackage = opts.chromeOptions?.androidPackage
449
+ || opts.appPackage
450
+ || webViewDetails?.info?.['Android-Package'];
451
+ if (androidPackage) {
452
+ // chromedriver raises an invalid argument error when androidPackage is 'null'
453
+ caps.chromeOptions.androidPackage = androidPackage;
454
+ }
455
+ if (lodash_1.default.isBoolean(opts.chromeUseRunningApp)) {
456
+ caps.chromeOptions.androidUseRunningApp = opts.chromeUseRunningApp;
457
+ }
458
+ if (opts.chromeAndroidPackage) {
459
+ caps.chromeOptions.androidPackage = opts.chromeAndroidPackage;
460
+ }
461
+ if (opts.chromeAndroidActivity) {
462
+ caps.chromeOptions.androidActivity = opts.chromeAndroidActivity;
463
+ }
464
+ if (opts.chromeAndroidProcess) {
465
+ caps.chromeOptions.androidProcess = opts.chromeAndroidProcess;
466
+ }
467
+ else if (webViewDetails?.process?.name && webViewDetails?.process?.id) {
468
+ caps.chromeOptions.androidProcess = webViewDetails.process.name;
469
+ }
470
+ if (lodash_1.default.toLower(opts.browserName) === 'chromium-webview') {
471
+ caps.chromeOptions.androidActivity = opts.appActivity;
472
+ }
473
+ if (opts.pageLoadStrategy) {
474
+ caps.pageLoadStrategy = opts.pageLoadStrategy;
475
+ }
476
+ const isChrome = lodash_1.default.toLower(caps.chromeOptions.androidPackage) === 'chrome';
477
+ if (lodash_1.default.includes(KNOWN_CHROME_PACKAGE_NAMES, caps.chromeOptions.androidPackage) || isChrome) {
478
+ // if we have extracted package from context name, it could come in as bare
479
+ // "chrome", and so we should make sure the details are correct, including
480
+ // not using an activity or process id
481
+ if (isChrome) {
482
+ caps.chromeOptions.androidPackage = CHROME_PACKAGE_NAME;
483
+ }
484
+ delete caps.chromeOptions.androidActivity;
485
+ delete caps.chromeOptions.androidProcess;
486
+ }
487
+ // add device id from adb
488
+ caps.chromeOptions.androidDeviceSerial = deviceId;
489
+ if (lodash_1.default.isPlainObject(opts.loggingPrefs) || lodash_1.default.isPlainObject(opts.chromeLoggingPrefs)) {
490
+ if (opts.loggingPrefs) {
491
+ logger_1.default.warn(`The 'loggingPrefs' cap is deprecated; use the 'chromeLoggingPrefs' cap instead`);
492
+ }
493
+ caps.loggingPrefs = opts.chromeLoggingPrefs || opts.loggingPrefs;
494
+ }
495
+ if (opts.enablePerformanceLogging) {
496
+ logger_1.default.warn(`The 'enablePerformanceLogging' cap is deprecated; simply use ` +
497
+ `the 'chromeLoggingPrefs' cap instead, with a 'performance' key set to 'ALL'`);
498
+ const newPref = { performance: 'ALL' };
499
+ // don't overwrite other logging prefs that have been sent in if they exist
500
+ caps.loggingPrefs = caps.loggingPrefs
501
+ ? Object.assign({}, caps.loggingPrefs, newPref)
502
+ : newPref;
503
+ }
504
+ if (opts.chromeOptions?.Arguments) {
505
+ // merge `Arguments` and `args`
506
+ opts.chromeOptions.args = [...(opts.chromeOptions.args || []), ...opts.chromeOptions.Arguments];
507
+ delete opts.chromeOptions.Arguments;
508
+ }
509
+ logger_1.default.debug('Precalculated Chromedriver capabilities: ' +
510
+ JSON.stringify(caps.chromeOptions, null, 2));
511
+ const protectedCapNames = [];
512
+ for (const [opt, val] of lodash_1.default.toPairs(opts.chromeOptions)) {
513
+ if (lodash_1.default.isUndefined(caps.chromeOptions[opt])) {
514
+ caps.chromeOptions[opt] = val;
515
+ }
516
+ else {
517
+ protectedCapNames.push(opt);
518
+ }
519
+ }
520
+ if (!lodash_1.default.isEmpty(protectedCapNames)) {
521
+ logger_1.default.info('The following Chromedriver capabilities cannot be overridden ' +
522
+ 'by the provided chromeOptions:');
523
+ for (const optName of protectedCapNames) {
524
+ logger_1.default.info(` ${optName} (${JSON.stringify(opts.chromeOptions[optName])})`);
525
+ }
526
+ }
527
+ return caps;
528
+ };
529
+ exports.default = helpers;
530
+ //# sourceMappingURL=webview-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webview-helpers.js","sourceRoot":"","sources":["../../lib/webview-helpers.js"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,sDAA8B;AAC9B,kDAA0B;AAC1B,6CAAuC;AACvC,6CAAgD;AAChD,0DAA4B;AAC5B,wDAAyB;AACzB,gDAAwB;AACxB,4CAAoB;AAEpB,MAAM,UAAU,GAAG,YAAY,CAAC;AA0iBd,gCAAU;AAziB5B,MAAM,WAAW,GAAG,SAAS,CAAC;AAyiBA,kCAAW;AAxiBzC,MAAM,YAAY,GAAG,UAAU,CAAC;AAwiByB,oCAAY;AAviBrE,MAAM,YAAY,GAAG,GAAG,WAAW,GAAG,CAAC;AAuiBI,oCAAY;AAtiBvD,MAAM,mBAAmB,GAAG,IAAI,MAAM,CAAC,IAAI,YAAY,QAAQ,CAAC,CAAC;AACjE,MAAM,mBAAmB,GAAG,IAAI,MAAM,CAAC,IAAI,YAAY,oBAAoB,CAAC,CAAC;AAC7E,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AACpE,MAAM,wBAAwB,GAAG,6BAA6B,CAAC;AAC/D,MAAM,wBAAwB,GAAG,wBAAwB,CAAC;AAC1D,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACjD,MAAM,0BAA0B,GAAG;IACjC,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,mBAAmB;CACpB,CAAC;AA2hBqE,gEAA0B;AA1hBjG,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5C,MAA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I,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC;KACrC;IAED,gBAAM,CAAC,KAAK,CAAC,2CAA2C;QACtD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/C,MAAM,iBAAiB,GAAG,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,gBAAC,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;QACtD,IAAI,gBAAC,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE;YAC1C,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;SAC/B;aAAM;YACL,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAC7B;KACF;IACD,IAAI,CAAC,gBAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE;QACjC,gBAAM,CAAC,IAAI,CAAC,+DAA+D;YACzE,gCAAgC,CAAC,CAAC;QACpC,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE;YACvC,gBAAM,CAAC,IAAI,CAAC,KAAK,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;SAC9E;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -157,6 +157,11 @@ const ActionsMixin = {
157
157
  }
158
158
  },
159
159
 
160
+ async mobileLock(opts = {}) {
161
+ const {seconds} = opts;
162
+ return await this.lock(seconds);
163
+ },
164
+
160
165
  async lock(seconds) {
161
166
  await /** @type {ADB} */ (this.adb).lock();
162
167
  if (Number.isNaN(seconds)) {
@@ -226,7 +226,7 @@ const ContextMixin = {
226
226
 
227
227
  // Stop proxying to any Chromedriver
228
228
  suspendChromedriverProxy() {
229
- this.chromedriver = null;
229
+ this.chromedriver = undefined;
230
230
  this.proxyReqRes = undefined;
231
231
  this.proxyCommand = undefined;
232
232
  this.jwpProxyActive = false;
@@ -13,17 +13,20 @@ const ExecuteMixin = {
13
13
  if (script.match(/^mobile:/)) {
14
14
  this.log.info(`Executing native command '${script}'`);
15
15
  script = script.replace(/^mobile:/, '').trim();
16
- return await this.executeMobile(script, _.isArray(args) ? args[0] : args);
16
+ return await this.executeMobile(
17
+ script,
18
+ _.isArray(args) ? /** @type {import('@appium/types').StringRecord} */ (args[0]) : args
19
+ );
17
20
  }
18
21
  if (!this.isWebContext()) {
19
22
  throw new errors.NotImplementedError();
20
23
  }
21
24
  const endpoint =
22
- /** @type {import('appium-chromedriver').default} */ (this.chromedriver).jwproxy
25
+ /** @type {import('appium-chromedriver').Chromedriver} */ (this.chromedriver).jwproxy
23
26
  .downstreamProtocol === PROTOCOLS.MJSONWP
24
27
  ? '/execute'
25
28
  : '/execute/sync';
26
- return await /** @type {import('appium-chromedriver').default} */ (
29
+ return await /** @type {import('appium-chromedriver').Chromedriver} */ (
27
30
  this.chromedriver
28
31
  ).jwproxy.command(endpoint, 'POST', {
29
32
  script,
@@ -76,6 +79,7 @@ const ExecuteMixin = {
76
79
 
77
80
  getContexts: 'mobileGetContexts',
78
81
 
82
+ lock: 'mobileLock',
79
83
  unlock: 'mobileUnlock',
80
84
 
81
85
  refreshGpsCache: 'mobileRefreshGpsCache',
@@ -99,3 +99,5 @@ const FindMixin: FindMixin & ThisType<AndroidDriver> = {
99
99
  };
100
100
 
101
101
  mixin(FindMixin);
102
+
103
+ export default FindMixin;
@@ -50,3 +50,5 @@ const commands = {
50
50
  };
51
51
 
52
52
  export {commands};
53
+
54
+ export type * from './mixins';
@@ -170,9 +170,11 @@ const LogMixin = {
170
170
  // XXX why doesn't `super` work here?
171
171
  const nativeLogTypes = await BaseDriver.prototype.getLogTypes.call(this);
172
172
  if (this.isWebContext()) {
173
- const webLogTypes = await /** @type {import('appium-chromedriver').default} */ (
174
- this.chromedriver
175
- ).jwproxy.command('/log/types', 'GET');
173
+ const webLogTypes = /** @type {string[]} */ (
174
+ await /** @type {import('appium-chromedriver').Chromedriver} */ (
175
+ this.chromedriver
176
+ ).jwproxy.command('/log/types', 'GET')
177
+ );
176
178
  return [...nativeLogTypes, ...webLogTypes];
177
179
  }
178
180
  return nativeLogTypes;
@@ -180,7 +182,7 @@ const LogMixin = {
180
182
 
181
183
  async getLog(logType) {
182
184
  if (this.isWebContext() && !_.keys(this.supportedLogTypes).includes(logType)) {
183
- return await /** @type {import('appium-chromedriver').default} */ (
185
+ return await /** @type {import('appium-chromedriver').Chromedriver} */ (
184
186
  this.chromedriver
185
187
  ).jwproxy.command('/log', 'POST', {type: logType});
186
188
  }