@@ -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 } ;
0 commit comments