1
1
import * as parser from "./parser"
2
- import { INsCapabilities } from "./interfaces/ns-capabilities" ;
2
+ import { INsCapabilities , AutomationName } from "./interfaces/ns-capabilities" ;
3
3
import { resolveCapabilities } from "./capabilities-helper" ;
4
4
import { getAppPath , fileExists , logErr } from "./utils" ;
5
5
import { IDevice } from "mobile-devices-controller" ;
@@ -26,6 +26,7 @@ export class NsCapabilities implements INsCapabilities {
26
26
private _appPath : string ;
27
27
private _path : string ;
28
28
private _emulatorOptions : string ;
29
+ private _automationName : AutomationName ;
29
30
private _device : IDevice ;
30
31
private _ignoreDeviceController : boolean ;
31
32
private _wdaLocalPort : number ;
@@ -53,6 +54,7 @@ export class NsCapabilities implements INsCapabilities {
53
54
this . _ignoreDeviceController = parser . ignoreDeviceController ;
54
55
this . _wdaLocalPort = parser . wdaLocalPort ;
55
56
this . _path = parser . path ;
57
+ this . setAutomationName ( ) ;
56
58
this . resolveApplication ( ) ;
57
59
this . checkMandatoryCapabiliies ( ) ;
58
60
this . throwExceptions ( ) ;
@@ -76,6 +78,7 @@ export class NsCapabilities implements INsCapabilities {
76
78
get isAndroid ( ) { return this . _isAndroid ; }
77
79
get isIOS ( ) { return this . _isIOS ; }
78
80
get isSauceLab ( ) { return this . _isSauceLab ; }
81
+ get automationName ( ) { return this . _automationName ; }
79
82
get appPath ( ) { return this . _appPath ; }
80
83
get appName ( ) { return this . _appName ; }
81
84
set appName ( appName : string ) { this . _appName = appName ; }
@@ -88,6 +91,40 @@ export class NsCapabilities implements INsCapabilities {
88
91
89
92
private isAndroidPlatform ( ) { return this . _appiumCaps . platformName . toLowerCase ( ) . includes ( "android" ) ; }
90
93
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
+
91
128
private resolveApplication ( ) {
92
129
if ( this . isSauceLab ) {
93
130
this . _appiumCaps . app = `sauce-storage:${ this . appPath } `
0 commit comments