11import * as parser from "./parser"
2- import { INsCapabilities } from "./interfaces/ns-capabilities" ;
2+ import { INsCapabilities , AutomationName } from "./interfaces/ns-capabilities" ;
33import { resolveCapabilities } from "./capabilities-helper" ;
44import { getAppPath , fileExists , logErr } from "./utils" ;
55import { IDevice } from "mobile-devices-controller" ;
@@ -26,6 +26,7 @@ export class NsCapabilities implements INsCapabilities {
2626 private _appPath : string ;
2727 private _path : string ;
2828 private _emulatorOptions : string ;
29+ private _automationName : AutomationName ;
2930 private _device : IDevice ;
3031 private _ignoreDeviceController : boolean ;
3132 private _wdaLocalPort : number ;
@@ -53,6 +54,7 @@ export class NsCapabilities implements INsCapabilities {
5354 this . _ignoreDeviceController = parser . ignoreDeviceController ;
5455 this . _wdaLocalPort = parser . wdaLocalPort ;
5556 this . _path = parser . path ;
57+ this . setAutomationName ( ) ;
5658 this . resolveApplication ( ) ;
5759 this . checkMandatoryCapabiliies ( ) ;
5860 this . throwExceptions ( ) ;
@@ -76,6 +78,7 @@ export class NsCapabilities implements INsCapabilities {
7678 get isAndroid ( ) { return this . _isAndroid ; }
7779 get isIOS ( ) { return this . _isIOS ; }
7880 get isSauceLab ( ) { return this . _isSauceLab ; }
81+ get automationName ( ) { return this . _automationName ; }
7982 get appPath ( ) { return this . _appPath ; }
8083 get appName ( ) { return this . _appName ; }
8184 set appName ( appName : string ) { this . _appName = appName ; }
@@ -88,6 +91,40 @@ export class NsCapabilities implements INsCapabilities {
8891
8992 private isAndroidPlatform ( ) { return this . _appiumCaps . platformName . toLowerCase ( ) . includes ( "android" ) ; }
9093
94+ private setAutomationName ( ) {
95+ if ( this . appiumCaps [ "automationName" ] ) {
96+ switch ( this . appiumCaps [ "automationName" ] ) {
97+ case AutomationName . UiAutomator2 . toString ( ) :
98+ this . _automationName = AutomationName . UiAutomator2 ; break ;
99+ case AutomationName . Appium . toString ( ) :
100+ this . _automationName = AutomationName . Appium ; break ;
101+ case AutomationName . XCUITest . toString ( ) :
102+ this . _automationName = AutomationName . XCUITest ; break ;
103+ }
104+ } else {
105+ if ( this . _isAndroid ) {
106+ if ( this . tryGetAndroidApiLevel ( ) > 24 || ( this . appiumCaps [ "apiLevel" ] && this . appiumCaps [ "apiLevel" ] . toLowerCase ( ) . includes ( "p" ) ) ) {
107+ this . _automationName = AutomationName . UiAutomator2 ;
108+ }
109+ }
110+ }
111+
112+ if ( this . _automationName ) {
113+ this . appiumCaps [ "automationName" ] = this . _automationName . toString ( ) ;
114+ console . log ( `Automation name set to: ${ this . appiumCaps [ "automationName" ] } ` ) ;
115+ console . log ( `To change automation name, you need to set it in appium capabilities!` ) ;
116+ } else {
117+ console . log ( `Appium will use default automation name` ) ;
118+ }
119+ }
120+
121+ tryGetAndroidApiLevel ( ) {
122+ try {
123+ return parseInt ( this . appiumCaps [ "platformVersion" ] ) ;
124+ } catch ( error ) {
125+ }
126+ }
127+
91128 private resolveApplication ( ) {
92129 if ( this . isSauceLab ) {
93130 this . _appiumCaps . app = `sauce-storage:${ this . appPath } `
0 commit comments