appium-webdriveragent 8.4.0 → 8.5.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.
@@ -27,7 +27,19 @@ const WDA_CF_BUNDLE_NAME = 'WebDriverAgentRunner-Runner';
27
27
  const SHARED_RESOURCES_GUARD = new AsyncLock();
28
28
  const RECENT_MODULE_VERSION_ITEM_NAME = 'recentWdaModuleVersion';
29
29
 
30
- class WebDriverAgent {
30
+ export class WebDriverAgent {
31
+ /** @type {string} */
32
+ bootstrapPath;
33
+
34
+ /** @type {string} */
35
+ agentPath;
36
+
37
+ /**
38
+ * @param {import('appium-xcode').XcodeVersion} xcodeVersion
39
+ * // TODO: make args typed
40
+ * @param {import('@appium/types').StringRecord} [args={}]
41
+ * @param {import('@appium/types').AppiumLogger?} [log=null]
42
+ */
31
43
  constructor (xcodeVersion, args = {}, log = null) {
32
44
  this.xcodeVersion = xcodeVersion;
33
45
 
@@ -123,6 +135,10 @@ class WebDriverAgent {
123
135
  return `${this.updatedWDABundleId ? this.updatedWDABundleId : WDA_RUNNER_BUNDLE_ID}${this.updatedWDABundleIdSuffix}`;
124
136
  }
125
137
 
138
+ /**
139
+ * @param {string} [bootstrapPath]
140
+ * @param {string} [agentPath]
141
+ */
126
142
  setWDAPaths (bootstrapPath, agentPath) {
127
143
  // allow the user to specify a place for WDA. This is undocumented and
128
144
  // only here for the purposes of testing development of WDA
@@ -134,8 +150,11 @@ class WebDriverAgent {
134
150
  this.log.info(`Using WDA agent: '${this.agentPath}'`);
135
151
  }
136
152
 
153
+ /**
154
+ * @returns {Promise<void>}
155
+ */
137
156
  async cleanupObsoleteProcesses () {
138
- const obsoletePids = await getPIDsListeningOnPort(this.url.port,
157
+ const obsoletePids = await getPIDsListeningOnPort(/** @type {string} */ (this.url.port),
139
158
  (cmdLine) => cmdLine.includes('/WebDriverAgentRunner') &&
140
159
  !cmdLine.toLowerCase().includes(this.device.udid.toLowerCase()));
141
160
 
@@ -164,6 +183,9 @@ class WebDriverAgent {
164
183
  return !!(await this.getStatus());
165
184
  }
166
185
 
186
+ /**
187
+ * @returns {string}
188
+ */
167
189
  get basePath () {
168
190
  if (this.url.path === '/') {
169
191
  return '';
@@ -243,6 +265,8 @@ class WebDriverAgent {
243
265
  * Uninstall WDAs from the test device.
244
266
  * Over Xcode 11, multiple WDA can be in the device since Xcode 11 generates different WDA.
245
267
  * Appium does not expect multiple WDAs are running on a device.
268
+ *
269
+ * @returns {Promise<void>}
246
270
  */
247
271
  async uninstall () {
248
272
  try {
@@ -476,6 +500,9 @@ class WebDriverAgent {
476
500
  return await this.xcodebuild.start();
477
501
  }
478
502
 
503
+ /**
504
+ * @returns {Promise<void>}
505
+ */
479
506
  async startWithIDB () {
480
507
  this.log.info('Will launch WDA with idb instead of xcodebuild since the corresponding flag is enabled');
481
508
  const {wdaBundleId, testBundleId} = await this.prepareWDA();
@@ -490,6 +517,11 @@ class WebDriverAgent {
490
517
  return await this.idb.runXCUITest(wdaBundleId, wdaBundleId, testBundleId, {env});
491
518
  }
492
519
 
520
+ /**
521
+ *
522
+ * @param {string} wdaBundlePath
523
+ * @returns {Promise<string>}
524
+ */
493
525
  async parseBundleId (wdaBundlePath) {
494
526
  const infoPlistPath = path.join(wdaBundlePath, 'Info.plist');
495
527
  const infoPlist = await plist.parsePlist(await fs.readFile(infoPlistPath));
@@ -499,6 +531,9 @@ class WebDriverAgent {
499
531
  return infoPlist.CFBundleIdentifier;
500
532
  }
501
533
 
534
+ /**
535
+ * @returns {Promise<{wdaBundleId: string, testBundleId: string, wdaBundlePath: string}>}
536
+ */
502
537
  async prepareWDA () {
503
538
  const wdaBundlePath = this.wdaBundlePath || await this.fetchWDABundle();
504
539
  const wdaBundleId = await this.parseBundleId(wdaBundlePath);
@@ -509,9 +544,12 @@ class WebDriverAgent {
509
544
  return {wdaBundleId, testBundleId, wdaBundlePath};
510
545
  }
511
546
 
547
+ /**
548
+ * @returns {Promise<string>}
549
+ */
512
550
  async fetchWDABundle () {
513
551
  if (!this.derivedDataPath) {
514
- return await bundleWDASim(this.xcodebuild);
552
+ return await bundleWDASim(/** @type {XcodeBuild} */ (this.xcodebuild));
515
553
  }
516
554
  const wdaBundlePaths = await fs.glob(`${this.derivedDataPath}/**/*${WDA_RUNNER_APP}/`, {
517
555
  absolute: true,
@@ -522,14 +560,21 @@ class WebDriverAgent {
522
560
  return wdaBundlePaths[0];
523
561
  }
524
562
 
563
+ /**
564
+ * @returns {Promise<boolean>}
565
+ */
525
566
  async isSourceFresh () {
526
567
  const existsPromises = [
527
568
  'Resources',
528
569
  `Resources${path.sep}WebDriverAgent.bundle`,
529
- ].map((subPath) => fs.exists(path.resolve(this.bootstrapPath, subPath)));
570
+ ].map((subPath) => fs.exists(path.resolve(/** @type {String} */ (this.bootstrapPath), subPath)));
530
571
  return (await B.all(existsPromises)).some((v) => v === false);
531
572
  }
532
573
 
574
+ /**
575
+ * @param {string} sessionId
576
+ * @returns {void}
577
+ */
533
578
  setupProxies (sessionId) {
534
579
  const proxyOpts = {
535
580
  log: this.log,
@@ -547,6 +592,9 @@ class WebDriverAgent {
547
592
  this.noSessionProxy = new NoSessionProxy(proxyOpts);
548
593
  }
549
594
 
595
+ /**
596
+ * @returns {Promise<void>}
597
+ */
550
598
  async quit () {
551
599
  if (this.usePreinstalledWDA) {
552
600
  this.log.info('Stopping the XCTest session');
@@ -582,6 +630,9 @@ class WebDriverAgent {
582
630
  }
583
631
  }
584
632
 
633
+ /**
634
+ * @returns {import('url').UrlWithStringQuery}
635
+ */
585
636
  get url () {
586
637
  if (!this._url) {
587
638
  if (this.webDriverAgentUrl) {
@@ -595,30 +646,44 @@ class WebDriverAgent {
595
646
  return this._url;
596
647
  }
597
648
 
649
+ /**
650
+ * @param {string} _url
651
+ * @returns {void}
652
+ */
598
653
  set url (_url) {
599
654
  this._url = url.parse(_url);
600
655
  }
601
656
 
657
+ /**
658
+ * @returns {boolean}
659
+ */
602
660
  get fullyStarted () {
603
661
  return this.started;
604
662
  }
605
663
 
664
+ /**
665
+ * @param {boolean} started
666
+ * @returns {void}s
667
+ */
606
668
  set fullyStarted (started) {
607
669
  this.started = started ?? false;
608
670
  }
609
671
 
672
+ /**
673
+ * @returns {Promise<string|undefined>}
674
+ */
610
675
  async retrieveDerivedDataPath () {
611
676
  if (this.canSkipXcodebuild) {
612
677
  return;
613
678
  }
614
- // @ts-ignore xcodebuild should be set
615
- return await this.xcodebuild.retrieveDerivedDataPath();
679
+ return await /** @type {XcodeBuild} */ (this.xcodebuild).retrieveDerivedDataPath();
616
680
  }
617
681
 
618
682
  /**
619
683
  * Reuse running WDA if it has the same bundle id with updatedWDABundleId.
620
684
  * Or reuse it if it has the default id without updatedWDABundleId.
621
685
  * Uninstall it if the method faces an exception for the above situation.
686
+ * @returns {Promise<void>}
622
687
  */
623
688
  async setupCaching () {
624
689
  const status = await this.getStatus();
@@ -660,6 +725,7 @@ class WebDriverAgent {
660
725
 
661
726
  /**
662
727
  * Quit and uninstall running WDA.
728
+ * @returns {Promise<void>}
663
729
  */
664
730
  async quitAndUninstall () {
665
731
  await this.quit();
@@ -668,4 +734,3 @@ class WebDriverAgent {
668
734
  }
669
735
 
670
736
  export default WebDriverAgent;
671
- export { WebDriverAgent };
package/lib/xcodebuild.js CHANGED
@@ -33,15 +33,16 @@ const LIB_SCHEME_TV = 'WebDriverAgentLib_tvOS';
33
33
  const xcodeLog = logger.getLogger('Xcode');
34
34
 
35
35
 
36
- class XcodeBuild {
36
+ export class XcodeBuild {
37
37
  /** @type {SubProcess} */
38
38
  xcodebuild;
39
39
 
40
40
  /**
41
- * @param {string} xcodeVersion
41
+ * @param {import('appium-xcode').XcodeVersion} xcodeVersion
42
42
  * @param {any} device
43
- * @param {any} args
44
- * @param {import('@appium/types').AppiumLogger?} log
43
+ * // TODO: make args typed
44
+ * @param {import('@appium/types').StringRecord} [args={}]
45
+ * @param {import('@appium/types').AppiumLogger?} [log=null]
45
46
  */
46
47
  constructor (xcodeVersion, device, args = {}, log = null) {
47
48
  this.xcodeVersion = xcodeVersion;
@@ -92,6 +93,11 @@ class XcodeBuild {
92
93
  this._didProcessExit = false;
93
94
  }
94
95
 
96
+ /**
97
+ *
98
+ * @param {any} noSessionProxy
99
+ * @returns {Promise<void>}
100
+ */
95
101
  async init (noSessionProxy) {
96
102
  this.noSessionProxy = noSessionProxy;
97
103
 
@@ -120,6 +126,9 @@ class XcodeBuild {
120
126
  }
121
127
  }
122
128
 
129
+ /**
130
+ * @returns {Promise<string|undefined>}
131
+ */
123
132
  async retrieveDerivedDataPath () {
124
133
  if (this.derivedDataPath) {
125
134
  return this.derivedDataPath;
@@ -154,6 +163,9 @@ class XcodeBuild {
154
163
  return await this._derivedDataPathPromise;
155
164
  }
156
165
 
166
+ /**
167
+ * @returns {Promise<void>}
168
+ */
157
169
  async reset () {
158
170
  // if necessary, reset the bundleId to original value
159
171
  if (this.realDevice && this.updatedWDABundleId) {
@@ -161,6 +173,9 @@ class XcodeBuild {
161
173
  }
162
174
  }
163
175
 
176
+ /**
177
+ * @returns {Promise<void>}
178
+ */
164
179
  async prebuild () {
165
180
  // first do a build phase
166
181
  this.log.debug('Pre-building WDA before launching test');
@@ -173,6 +188,9 @@ class XcodeBuild {
173
188
  }
174
189
  }
175
190
 
191
+ /**
192
+ * @returns {Promise<void>}
193
+ */
176
194
  async cleanProject () {
177
195
  const libScheme = isTvOS(this.platformName) ? LIB_SCHEME_TV : LIB_SCHEME_IOS;
178
196
  const runnerScheme = isTvOS(this.platformName) ? RUNNER_SCHEME_TV : RUNNER_SCHEME_IOS;
@@ -187,18 +205,24 @@ class XcodeBuild {
187
205
  }
188
206
  }
189
207
 
208
+ /**
209
+ *
210
+ * @param {boolean} [buildOnly=false]
211
+ * @returns {{cmd: string, args: string[]}}
212
+ */
190
213
  getCommand (buildOnly = false) {
191
- let cmd = 'xcodebuild';
192
- let args;
214
+ const cmd = 'xcodebuild';
215
+ /** @type {string[]} */
216
+ const args = [];
193
217
 
194
218
  // figure out the targets for xcodebuild
195
219
  const [buildCmd, testCmd] = this.useSimpleBuildTest ? ['build', 'test'] : ['build-for-testing', 'test-without-building'];
196
220
  if (buildOnly) {
197
- args = [buildCmd];
221
+ args.push(buildCmd);
198
222
  } else if (this.usePrebuiltWDA || this.useXctestrunFile) {
199
- args = [testCmd];
223
+ args.push(testCmd);
200
224
  } else {
201
- args = [buildCmd, testCmd];
225
+ args.push(buildCmd, testCmd);
202
226
  }
203
227
 
204
228
  if (this.allowProvisioningDeviceRegistration) {
@@ -260,6 +284,10 @@ class XcodeBuild {
260
284
  return {cmd, args};
261
285
  }
262
286
 
287
+ /**
288
+ * @param {boolean} [buildOnly=false]
289
+ * @returns {Promise<SubProcess>}
290
+ */
263
291
  async createSubProcess (buildOnly = false) {
264
292
  if (!this.useXctestrunFile && this.realDevice) {
265
293
  if (this.keychainPath && this.keychainPassword) {
@@ -321,6 +349,11 @@ class XcodeBuild {
321
349
  return xcodebuild;
322
350
  }
323
351
 
352
+
353
+ /**
354
+ * @param {boolean} [buildOnly=false]
355
+ * @returns {Promise<import('@appium/types').StringRecord>}
356
+ */
324
357
  async start (buildOnly = false) {
325
358
  this.xcodebuild = await this.createSubProcess(buildOnly);
326
359
 
@@ -356,8 +389,7 @@ class XcodeBuild {
356
389
  const timer = new timing.Timer().start();
357
390
  await this.xcodebuild.start(true);
358
391
  if (!buildOnly) {
359
- let status = await this.waitForStart(timer);
360
- resolve(status);
392
+ resolve(/** @type {import('@appium/types').StringRecord} */ (await this.waitForStart(timer)));
361
393
  }
362
394
  } catch (err) {
363
395
  let msg = `Unable to start WebDriverAgent: ${err}`;
@@ -368,6 +400,11 @@ class XcodeBuild {
368
400
  });
369
401
  }
370
402
 
403
+ /**
404
+ *
405
+ * @param {any} timer
406
+ * @returns {Promise<import('@appium/types').StringRecord?>}
407
+ */
371
408
  async waitForStart (timer) {
372
409
  // try to connect once every 0.5 seconds, until `launchTimeout` is up
373
410
  this.log.debug(`Waiting up to ${this.launchTimeout}ms for WebDriverAgent to start`);
@@ -412,10 +449,12 @@ class XcodeBuild {
412
449
  return currentStatus;
413
450
  }
414
451
 
452
+ /**
453
+ * @returns {Promise<void>}
454
+ */
415
455
  async quit () {
416
456
  await killProcess('xcodebuild', this.xcodebuild);
417
457
  }
418
458
  }
419
459
 
420
- export { XcodeBuild };
421
460
  export default XcodeBuild;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "appium-webdriveragent",
3
- "version": "8.4.0",
3
+ "version": "8.5.1",
4
4
  "description": "Package bundling WebDriverAgent",
5
5
  "main": "./build/index.js",
6
+ "types": "./build/index.d.ts",
6
7
  "scripts": {
7
8
  "build": "tsc -b",
8
9
  "dev": "npm run build -- --watch",
@@ -100,9 +101,9 @@
100
101
  "teen_process": "^2.0.0"
101
102
  },
102
103
  "files": [
103
- "index.js",
104
+ "index.ts",
104
105
  "lib",
105
- "build/index.js",
106
+ "build/index.*",
106
107
  "build/lib",
107
108
  "Scripts/build.sh",
108
109
  "Scripts/fetch-prebuilt-wda.js",
package/index.js DELETED
@@ -1,22 +0,0 @@
1
- import * as dependencies from './lib/check-dependencies';
2
- import * as proxies from './lib/no-session-proxy';
3
- import * as driver from './lib/webdriveragent';
4
- import * as constants from './lib/constants';
5
- import * as utils from './lib/utils';
6
-
7
-
8
- const { checkForDependencies, bundleWDASim } = dependencies;
9
- const { NoSessionProxy } = proxies;
10
- const { WebDriverAgent } = driver;
11
- const { WDA_BASE_URL, WDA_RUNNER_BUNDLE_ID, PROJECT_FILE } = constants;
12
- const { resetTestProcesses, BOOTSTRAP_PATH } = utils;
13
-
14
- export {
15
- WebDriverAgent,
16
- NoSessionProxy,
17
- checkForDependencies, bundleWDASim,
18
- resetTestProcesses,
19
- BOOTSTRAP_PATH,
20
- WDA_RUNNER_BUNDLE_ID, PROJECT_FILE,
21
- WDA_BASE_URL,
22
- };