@@ -30,7 +30,8 @@ import {
3030 encodeImageToBase64 ,
3131 ensureReportsDirExists ,
3232 checkImageLogType ,
33- adbShellCommand
33+ adbShellCommand ,
34+ logWarn
3435} from "./utils" ;
3536
3637import { INsCapabilities } from "./interfaces/ns-capabilities" ;
@@ -167,6 +168,11 @@ export class AppiumDriver {
167168 }
168169
169170 public async navBack ( ) {
171+ if ( this . isAndroid ) {
172+ logInfo ( "=== Navigate back with hardware button!" ) ;
173+ } else {
174+ logInfo ( "=== Navigate back." ) ;
175+ }
170176 return await this . _driver . back ( ) ;
171177 }
172178
@@ -244,7 +250,7 @@ export class AppiumDriver {
244250 prepareApp ( args ) ;
245251 if ( ! args . device ) {
246252 if ( args . isAndroid ) {
247- args . device = DeviceManager . getDefaultDevice ( args , sessionInfo . capabilities . desired . deviceName , sessionInfo . capabilities . deviceUDID . replace ( "emulator-" , "" ) , sessionInfo . capabilities . deviceUDID . includes ( "emulator" ) ? DeviceType . EMULATOR : DeviceType . SIMULATOR , sessionInfo . capabilities . desired . platformVersion || sessionInfo . capabilities . platformVersion ) ;
253+ args . device = DeviceManager . getDefaultDevice ( args , sessionInfo . capabilities . desired . deviceName , sessionInfo . capabilities . deviceUDID . replace ( "emulator-" , "" ) , sessionInfo . capabilities . deviceUDID . includes ( "emulator" ) ? DeviceType . EMULATOR : DeviceType . SIMULATOR , sessionInfo . capabilities . deviceApiLevel || sessionInfo . capabilities . platformVersion ) ;
248254 } else {
249255 args . device = DeviceManager . getDefaultDevice ( args ) ;
250256 }
@@ -257,6 +263,8 @@ export class AppiumDriver {
257263 }
258264 } catch ( error ) {
259265 args . verbose = true ;
266+ console . log ( "===============================" ) ;
267+ console . log ( "" , error )
260268 if ( ! args . ignoreDeviceController && error && error . message && error . message . includes ( "Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]" ) ) {
261269 await DeviceManager . kill ( args . device ) ;
262270 await DeviceController . startDevice ( args . device ) ;
@@ -280,11 +288,11 @@ export class AppiumDriver {
280288 console . log ( "Retry launching appium driver!" ) ;
281289 hasStarted = false ;
282290
283- if ( error && error . message && error . message . includes ( "WebDriverAgent" ) ) {
284- const freePort = await findFreePort ( 100 , args . wdaLocalPort ) ;
285- console . log ( "args.appiumCaps['wdaLocalPort']" , freePort ) ;
286- args . appiumCaps [ "wdaLocalPort" ] = freePort ;
287- }
291+ // if (error && error.message && error.message.includes("WebDriverAgent")) {
292+ // const freePort = await findFreePort(100, args.wdaLocalPort);
293+ // console.log("args.appiumCaps['wdaLocalPort']", freePort);
294+ // args.appiumCaps["wdaLocalPort"] = freePort;
295+ // }
288296 }
289297
290298 if ( hasStarted ) {
@@ -491,7 +499,7 @@ export class AppiumDriver {
491499 * @param xOffset
492500 */
493501 public async scroll ( direction : Direction , y : number , x : number , yOffset : number , xOffset : number = 0 ) {
494- await scroll ( this . _wd , this . _driver , direction , this . _webio . isIOS , y , x , yOffset , xOffset , this . _args . verbose ) ;
502+ await scroll ( this . _wd , this . _driver , direction , this . _webio . isIOS , y , x , yOffset , xOffset ) ;
495503 }
496504
497505 /**
@@ -509,13 +517,15 @@ export class AppiumDriver {
509517 while ( ( el === null || ! isDisplayed ) && retryCount > 0 ) {
510518 try {
511519 el = await element ( ) ;
512- isDisplayed = await el . isDisplayed ( ) ;
520+ isDisplayed = el && await el . isDisplayed ( ) ;
513521 if ( ! isDisplayed ) {
514- await scroll ( this . _wd , this . _driver , direction , this . _webio . isIOS , startPoint . y , startPoint . x , offsetPoint . x , offsetPoint . y , this . _args . verbose ) ;
522+ await scroll ( this . _wd , this . _driver , direction , this . _webio . isIOS , startPoint . y , startPoint . x , offsetPoint . y , offsetPoint . x ) ;
515523 el = null ;
516524 }
517525 } catch ( error ) {
518526 console . log ( "scrollTo Error: " + error ) ;
527+ await scroll ( this . _wd , this . _driver , direction , this . _webio . isIOS , startPoint . y , startPoint . x , offsetPoint . y , offsetPoint . x ) ;
528+ el = null ;
519529 }
520530
521531 retryCount -- ;
@@ -864,7 +874,7 @@ export class AppiumDriver {
864874 }
865875 }
866876
867- private static async applyAdditionalSettings ( args ) {
877+ private static async applyAdditionalSettings ( args : INsCapabilities ) {
868878 if ( args . isSauceLab ) return ;
869879
870880 args . appiumCaps [ 'udid' ] = args . appiumCaps [ 'udid' ] || args . device . token ;
@@ -881,6 +891,11 @@ export class AppiumDriver {
881891 args . appiumCaps [ "wdaStartupRetries" ] = 5 ;
882892 args . appiumCaps [ "shouldUseSingletonTestManager" ] = args . appiumCaps . shouldUseSingletonTestManager ;
883893
894+ if ( args . derivedDataPath ) {
895+ args . appiumCaps [ "derivedDataPath" ] = `${ args . derivedDataPath } /${ args . device . token } ` ;
896+ logWarn ( 'Changed derivedDataPath to: ' , args . appiumCaps [ "derivedDataPath" ] ) ;
897+ }
898+
884899 // It looks we need it for XCTest (iOS 10+ automation)
885900 if ( args . appiumCaps . platformVersion >= 10 && args . wdaLocalPort ) {
886901 console . log ( `args.appiumCaps['wdaLocalPort']: ${ args . wdaLocalPort } ` ) ;
0 commit comments