@@ -22,6 +22,8 @@ import {
2222} from './constants' ;
2323import { strongbox } from '@appium/strongbox' ;
2424import type { WebDriverAgentArgs , AppleDevice } from './types' ;
25+ import type { Simctl } from 'node-simctl' ;
26+ import type { Devicectl } from 'node-devicectl' ;
2527
2628const WDA_LAUNCH_TIMEOUT = 60 * 1000 ;
2729const WDA_AGENT_PORT = 8100 ;
@@ -361,7 +363,11 @@ export class WebDriverAgent {
361363 if ( this . usePreinstalledWDA ) {
362364 this . log . info ( 'Stopping the XCTest session' ) ;
363365 try {
364- await this . device . simctl . terminateApp ( this . bundleIdForXctest ) ;
366+ if ( this . device . simctl ) {
367+ await this . device . simctl . terminateApp ( this . bundleIdForXctest ) ;
368+ } else if ( this . device . devicectl ) {
369+ await this . device . devicectl . terminateApp ( this . bundleIdForXctest ) ;
370+ }
365371 } catch ( e : any ) {
366372 this . log . warn ( e . message ) ;
367373 }
@@ -372,8 +378,7 @@ export class WebDriverAgent {
372378 }
373379 } else {
374380 this . log . debug (
375- 'Do not stop xcodebuild nor XCTest session ' +
376- 'since the WDA session is managed by outside this driver.' ,
381+ 'Stopping neither xcodebuild nor XCTest session since WDA lifecycle is not managed by this driver' ,
377382 ) ;
378383 }
379384
@@ -662,7 +667,7 @@ export class WebDriverAgent {
662667 ) : Promise < void > {
663668 const { env} = opts ;
664669
665- await this . device . devicectl . launchApp ( this . bundleIdForXctest , { env, terminateExisting : true } ) ;
670+ await ( this . device . devicectl as Devicectl ) . launchApp ( this . bundleIdForXctest , { env, terminateExisting : true } ) ;
666671 }
667672
668673 /**
@@ -684,7 +689,7 @@ export class WebDriverAgent {
684689 if ( this . isRealDevice ) {
685690 await this . _launchViaDevicectl ( { env : xctestEnv } ) ;
686691 } else {
687- await this . device . simctl . exec ( 'launch' , {
692+ await ( this . device . simctl as Simctl ) . exec ( 'launch' , {
688693 args : [ '--terminate-running-process' , this . device . udid , this . bundleIdForXctest ] ,
689694 env : xctestEnv ,
690695 } ) ;
0 commit comments