Desired Capabilities for Appium

Desired Capabilities got introduced in Selenium to work with lot of browser capabilities like handling browser cookies , SSL security popup blah blah.
But why are we using this in Appium?
Using Desired Capabilities we can communicate with Appium server by sending a POST request, saying that I’d like to start a session with so and so platform and platformversion, browser etc…Now the server understands it and starts a session with the capabilities which we have set. Still confused?
Desired capabilities is a JSON object (keys and values pair). So, there are few capabilities in-built. We need to set the capability name as ‘key’ and capability value as ‘value’. The capabilities keys are case sensitive. You need to follow correct syntax to set key and value. Without setting these capabilities, you can’t even establish a session.

Let’s see few capabilities which needs to be used to start a session

androidDeviceReadyTimeout: To set the timeout in seconds for a device to become ready after booting. You need to set ‘androidDeviceReadyTimeout’ as key and desired seconds as ‘value’

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“androidDeviceReadyTimeout”,”20″);

app:  Appium will install the app binary on the appropriate device. You don’t need this capability, if you’re using appPackage & appActivity. You need to pass ‘app’ as key and your local path(/home/test.apk) as value to set the capability”

caps.setCapability(“app”,”/Localpath/Your.apk”);

appActivity: This is to set the Android activity that you want to launch from your package. You need to set ‘appActivity’ as key and ‘com.android.contacts’ as value.

caps.setCapability(“appActivity”, “com.android.calculator2.Calculator”);

appPackage: This capability is for the Java package of the Android app that you want to run. You need to set ‘appPackage’ as key and your package name as value.

caps.setCapability(“appPackage”, “com.android.calculator2”);

appWaitActivity: This is to wait for the activity you’d like to use

caps.setCapability(“appWaitActivity”,”com.android.calculator2.Calculator”);

appWaitPackage: Similar to appWaitActivity, this capability will wait until if finds the desired package

caps.setCapability(“appWaitPackage”,”com.example.android.myApp”);

autoLaunch: This capability is used to install and launch the app automatically. The default value is set to true. We need to set ‘autoLaunch’ as key and value as ‘false’

caps.setCapability(“autoLaunch”,”false”);

automationName: This capability is used to define the automation engine. Here we need to set ‘automationName’ as key and your desired engine (Appium, Selendroid) as value

caps.setCapability(“automationName”,”Selendroid”);

autoWebview: If you are automating hybrid apps and want to move directly into the Webview context, then you can set it by using this capability; the default value is false. You need to set ‘autoWebview’ as key and ‘true’ as value”

caps.setCapability(“autoWebview”, “true”);

avd:  This is to set the name of avd that you want to launch. You need to set ‘avd’ as key and ‘Myavd’ as value.

caps.setCapability(“avd”,”Myavd”);

avdLaunchTimeout: This capability will help you define how long you need to wait. Value should be in milliseconds

caps.setCapability(“avdLaunchTimeout”,”150000″);

browserName:  You need to invoke a browser to automate Mobile web apps. For that you need to set ‘browserName’ as key and your desired browser (chrome, safari..) as value.

caps.setCapability(“browserName”, “Chrome”);

chromedriverExecutable:  You can give the absolute local path to the WebDriver executable.

caps.setCapability(“chromedriverExecutable”,”pathto/webdriver”);

deviceName:  You need to set device name, so that the user agent would be your device name. To know your device name, type ‘adb devices’ in Terminal. Now set the key as ‘deviceName’ as ‘Samsung s5’ as value. If you’re using emulator just set emulator name as value.

caps.setCapability(“deviceName”, “Samsung s5”);

deviceReadyTimeout: You can set the timeout while waiting for the device to be ready.

caps.setCapability(“deviceReadyTimeout”,”15″);

language:  This is used to set the language on the simulator. You need to set ‘language’ as key and ‘en’ as value

caps.setCapability(“language”,”fr”);

locale:  This is used to set the locale for the emulator, for example, fr_CA. This is used in case of I18N, L10N. This is not so helpful unless you knew lil French.

caps.setCapability(“locale”,”fr_CA”);

newCommandTimeout:  We can define timeout for how long  appium server should wait for a new command. You need to set ‘newCommandTimeout’ as key and ’30’ as value. This means, it will wait till 30 seconds.

caps.setCapability(“newCommandTimeout”, “30”);

Orientation: This is used to set orientation for emulator. Maybe LANDSCAPE or PORTRAIT

caps.setCapability(“orientation”, “PORTRAIT”);

platformName: It is used to set the mobile OS platform in which we’re about to start our session. You need to set ‘platformName’ as key and ‘Android’ as a value.

caps.setCapability(“platformName”,”Android”);

platformVersion: It is used to set the mobile OS version. Each Android API has a version. So you need to set ‘platformVersion’ as key and ‘4.4.2’ as value.

caps.setCapability(“platformVersion”,”4.4.2″);

useKeystore: This is to set keystores. You need to set ‘useKeyStore’ as key and ‘false’ as value.

caps.setCapability(“useKeystore”,”false”);

001
Desired Capabilities

These capabilities can be used for Android app Automation. Similarly there’re few capabilities for IOS too. Now you know what is AVD, how to interact AVD using ADB and how to use Desired Capabilities.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s