11import * as parser from "./parser"
22import { INsCapabilities , AutomationName } from "./interfaces/ns-capabilities" ;
33import { resolveCapabilities } from "./capabilities-helper" ;
4- import { getAppPath , fileExists , logErr } from "./utils" ;
4+ import { getAppPath , fileExists , logErr , logInfo , logError } from "./utils" ;
55import { IDevice } from "mobile-devices-controller" ;
66
77export class NsCapabilities implements INsCapabilities {
@@ -108,7 +108,7 @@ export class NsCapabilities implements INsCapabilities {
108108
109109 private isAndroidPlatform ( ) { return this . _appiumCaps . platformName . toLowerCase ( ) . includes ( "android" ) ; }
110110
111- private shouldSetFullResetOption ( ) {
111+ private shouldSetFullResetOption ( ) {
112112 if ( this . _ignoreDeviceController ) {
113113 this . appiumCaps [ "fullReset" ] = true ;
114114 this . appiumCaps [ "noReset" ] = false ;
@@ -123,84 +123,83 @@ export class NsCapabilities implements INsCapabilities {
123123 }
124124
125125 private setAutomationName ( ) {
126- if ( this . appiumCaps [ "automationName" ] ) {
127- switch ( this . appiumCaps [ "automationName" ] . toLowerCase ( ) ) {
128- case AutomationName . UiAutomator2 . toString ( ) . toLowerCase ( ) :
129- this . _automationName = AutomationName . UiAutomator2 ; break ;
130- case AutomationName . Appium . toString ( ) . toLowerCase ( ) :
131- this . _automationName = AutomationName . Appium ; break ;
132- case AutomationName . XCUITest . toString ( ) . toLowerCase ( ) :
133- this . _automationName = AutomationName . XCUITest ; break ;
134- }
135- } else {
136- if ( this . _isAndroid ) {
137- if ( this . tryGetAndroidApiLevel ( ) > 6 || ( this . appiumCaps [ "apiLevel" ] && this . appiumCaps [ "apiLevel" ] . toLowerCase ( ) . includes ( "p" ) ) ) {
138- this . _automationName = AutomationName . UiAutomator2 ;
126+ if ( this . appiumCaps [ "automationName" ] ) {
127+ switch ( this . appiumCaps [ "automationName" ] . toLowerCase ( ) ) {
128+ case AutomationName . UiAutomator2 . toString ( ) . toLowerCase ( ) :
129+ this . _automationName = AutomationName . UiAutomator2 ; break ;
130+ case AutomationName . Appium . toString ( ) . toLowerCase ( ) :
131+ this . _automationName = AutomationName . Appium ; break ;
132+ case AutomationName . XCUITest . toString ( ) . toLowerCase ( ) :
133+ this . _automationName = AutomationName . XCUITest ; break ;
134+ }
135+ } else {
136+ if ( this . _isAndroid ) {
137+ if ( this . tryGetAndroidApiLevel ( ) > 6 || ( this . appiumCaps [ "apiLevel" ] && this . appiumCaps [ "apiLevel" ] . toLowerCase ( ) . includes ( "p" ) ) ) {
138+ this . _automationName = AutomationName . UiAutomator2 ;
139+ }
139140 }
140141 }
141- }
142142
143- if ( this . _automationName ) {
144- this . appiumCaps [ "automationName" ] = this . _automationName . toString ( ) ;
145- console . log ( `Automation name set to: ${ this . appiumCaps [ "automationName" ] } ` ) ;
146- console . log ( `To change automation name, you need to set it in appium capabilities!` ) ;
147- } else {
148- console . log ( `Appium will use default automation name` ) ;
143+ if ( this . _automationName ) {
144+ this . appiumCaps [ "automationName" ] = this . _automationName . toString ( ) ;
145+ logInfo ( `Automation name set to: ${ this . appiumCaps [ "automationName" ] } ` ) ;
146+ console . log ( `To change automation name, you need to set it in appium capabilities!` ) ;
147+ } else {
148+ console . log ( `Appium will use default automation name` ) ;
149+ }
149150 }
150- }
151151
152- tryGetAndroidApiLevel ( ) {
153- try {
154- if ( this . appiumCaps [ "platformVersion" ] ) {
155- const apiLevel = this . appiumCaps [ "platformVersion" ] . split ( "." ) . splice ( 0 , 2 ) . join ( '.' ) ;
156- return parseFloat ( apiLevel ) ;
157- }
158- } catch ( error ) { }
159- return undefined ;
160- }
152+ tryGetAndroidApiLevel ( ) {
153+ try {
154+ if ( this . appiumCaps [ "platformVersion" ] ) {
155+ const apiLevel = this . appiumCaps [ "platformVersion" ] . split ( "." ) . splice ( 0 , 2 ) . join ( '.' ) ;
156+ return parseFloat ( apiLevel ) ;
157+ }
158+ } catch ( error ) { }
159+ return undefined ;
160+ }
161161
162162 private resolveApplication ( ) {
163- if ( this . isSauceLab ) {
164- this . _appiumCaps . app = `sauce-storage:${ this . appPath } `
165- this . _ignoreDeviceController = true ;
166- console . log ( "Using Sauce Labs. The application path is changed to: " + this . appPath ) ;
167- } else {
168- this . appiumCaps . app = getAppPath ( this ) ;
169- this . _appPath = this . _appiumCaps . app ;
170- console . log ( "Application full path: " + this . _appiumCaps . app ) ;
163+ if ( this . isSauceLab ) {
164+ this . _appiumCaps . app = `sauce-storage:${ this . appPath } `
165+ this . _ignoreDeviceController = true ;
166+ console . log ( "Using Sauce Labs. The application path is changed to: " + this . appPath ) ;
167+ } else {
168+ this . appiumCaps . app = getAppPath ( this ) ;
169+ this . _appPath = this . _appiumCaps . app ;
170+ console . log ( "Application full path: " + this . _appiumCaps . app ) ;
171+ }
171172 }
172- }
173173
174174 private checkMandatoryCapabiliies ( ) {
175- if ( ! this . isSauceLab && ! fileExists ( this . _appiumCaps . app ) ) {
176- this . exceptions . push ( "The application folder doesn't exist!" ) ;
177- }
175+ if ( ! this . isSauceLab && ! fileExists ( this . _appiumCaps . app ) ) {
176+ this . exceptions . push ( "The application folder doesn't exist!" ) ;
177+ }
178178
179- if ( ! this . _runType ) {
180- this . exceptions . push ( "Missing runType! Please select one from appium capabilities file!" ) ;
181- }
179+ if ( ! this . _runType ) {
180+ this . exceptions . push ( "Missing runType! Please select one from appium capabilities file!" ) ;
181+ }
182182
183- if ( ! this . _appiumCaps . platformName ) {
184- this . exceptions . push ( "Platform name is missing! Please, check appium capabilities file!" ) ;
185- }
183+ if ( ! this . _appiumCaps . platformName ) {
184+ this . exceptions . push ( "Platform name is missing! Please, check appium capabilities file!" ) ;
185+ }
186186
187- if ( ! this . _appiumCaps . platformVersion ) {
188- console . warn ( "Platform version is missing! You'd better to set it in order to use the correct device" ) ;
189- }
187+ if ( ! this . _appiumCaps . platformVersion ) {
188+ console . warn ( "Platform version is missing! You'd better to set it in order to use the correct device" ) ;
189+ }
190190
191- if ( ! this . _appiumCaps . deviceName && ! this . _appiumCaps . udid ) {
192- this . exceptions . push ( "The device name or udid are missing! Please, check appium capabilities file!" ) ;
191+ if ( ! this . _appiumCaps . deviceName && ! this . _appiumCaps . udid ) {
192+ this . exceptions . push ( "The device name or udid are missing! Please, check appium capabilities file!" ) ;
193+ }
193194 }
194- }
195195
196196 private throwExceptions ( ) {
197- this . exceptions . forEach ( msg => {
198- logErr ( msg , true ) ;
199- } ) ;
197+ this . exceptions . forEach ( msg => {
198+ logError ( msg ) ;
199+ } ) ;
200200
201- if ( this . exceptions . length > 0 ) {
202- const messagesString = this . exceptions . length > 1 ? "messages" : "message" ;
203- throw new Error ( `See the ${ messagesString } above and fullfill the conditions!!!` ) ;
201+ if ( this . exceptions . length > 0 ) {
202+ process . exit ( 1 ) ;
203+ }
204204 }
205- }
206205}
0 commit comments