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();
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”
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.
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.
appWaitActivity: This is to wait for the activity you’d like to use
appWaitPackage: Similar to appWaitActivity, this capability will wait until if finds the desired package
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’
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
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”
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.
avdLaunchTimeout: This capability will help you define how long you need to wait. Value should be in milliseconds
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.
chromedriverExecutable: You can give the absolute local path to the WebDriver executable.
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.
language: This is used to set the language on the simulator. You need to set ‘language’ as key and ‘en’ as value
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.
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.
Orientation: This is used to set orientation for emulator. Maybe LANDSCAPE or 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.
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.
useKeystore: This is to set keystores. You need to set ‘useKeyStore’ as key and ‘false’ as value.
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.