Desired capabilities
Desired capabilities is a JSON object (a set of keys and values) sent by the client to the server. It describes the capabilities for the automation session in which we are interested.
Let's discuss the capabilities one by one; first, we will see the Appium server's capabilities:
We need to import "import org.openqa.Selenium.remote.DesiredCapabilities
" library for Java to work with the desired capabilities.
Capability |
Explanation |
---|---|
|
This capability is used to define the automation engine. If you want to work with an Android SDK version less than 17, then you need to define the value as DesiredCapabilities caps = new DesiredCapabilities(); // creating an object caps.setCapability("automationName","Selendroid"); // to set capability value We can also set the capabilities using Appium's client library. For this, users need to import " caps.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Selendroid");
There's no need to use this capability in the case of iOS. |
|
It is used to set the mobile OS platform. It uses the value as
caps.setCapability("platformName","Android"); In case of the Appium client library, you can use this: caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
|
|
To set the mobile OS version, for example,
caps.setCapability("platformVersion","4.4.4"); Alternatively, you can use the following command as well: caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.4"); |
|
We can define the type of mobile device or emulator to use, using the following command, for example, caps.setCapability("deviceName", "Nexus 5"); You can use the following command as well: caps.setCapability(MobileCapabilityType.DEVICE_NAME,"Nexus 5"); |
|
We can add the absolute local path or remote HTTP URL of the caps.setCapability("app","/apps/demo/demo.apk or http://app.com/app.ipa"); Alternatively, you can use the following command: caps.setCapability(MobileCapabilityType.APP,"/apps/demo/demo.apk or http://app.com/app.ipa"); |
|
If you want to automate mobile web applications, then you have to use this capability to define the browser. For Safari on iOS, you can use this: caps.setCapability("browserName", "Safari"); Also, you can use the following command: caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari"); For Chrome on Android, you can use this: caps.setCapability("browserName", "Chrome"); Alternatively, you can use the following command: caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); |
|
To end the session, Appium will wait for a few seconds for a new command from the client before assuming that the client quit. The default value is caps.setCapability("newCommandTimeout", "30"); You can also use this command to end the session: caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,"30"); |
|
This capability is used to install and launch the app automatically. The default value is set to caps.setCapability("autoLaunch","false"); |
|
This is used to set the language on the simulator/emulator, for example, caps.setCapability("language","fr"); |
|
This is used to set the locale for the simulator/emulator, for example, caps.setCapability("locale","fr_CA"); |
|
A unique device identifier ( caps.setCapability("udid", "1be204387fc072g1be204387fc072g4387fc072g"); |
|
This is used to start in a certain orientation in simulator/emulator only, for example, caps.setCapability("orientation", "PORTRAIT"); |
|
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 caps.setCapability("autoWebview", "true"); |
|
This capability is used to reset the app's state before the session starts; the default value is caps.setCapability("noReset"-," true"); |
|
In iOS, this will delete the entire simulator folder. In Android, you can reset the app's state by uninstalling the app instead of clearing the app data; also, it will remove the app after the session is complete. The default value is caps.setCapability("fullReset", "true"); |
Android capabilities
Now, let's discuss the Android capabilities, as shown in the following table:
Capability |
Explanation |
---|---|
|
This capability is for the Java package of the Android app that you want to run, for example, caps.setCapability("appPackage", "com.android.calculator2"); Alternatively, you can use this command: caps.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2"); |
|
By using this capability, you can specify the Android activity that you want to launch from your package, for example, caps.setCapability("appActivity", "com.android.calculator2.Calculator"); You can also use the following command: caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); |
|
Android activity for which the user wants to wait can be defined using this capability: caps.setCapability("appWaitActivity","com.android.calculator2.Calculator"); Alternatively, you can also use this command: caps.setCapability(MobileCapabilityType.APP_WAIT_ACTIVITY,"com.android.calculator2.Calculator"); |
|
The Java package of the Android app you want to wait for can be defined using the following capability, for example, caps.setCapability("appWaitPackage","com.example.android.myApp"); |
|
You can set the timeout (in seconds) while waiting for the device to be ready, as follows; the default value is caps.setCapability("deviceReadyTimeout","10"); Alternatively, you can also use this command: caps.setCapability(MobileCapabilityType.DEVICE_READY_TIMEOUT,"10"); |
|
You can enable the Chrome driver's performance logging by the use of this capability. It will enable logging only for Chrome and web view; the default value is caps.setCapability("enablePerformanceLogging", "true"); |
|
To set the timeout in seconds for a device to become ready after booting, you can use the following capability: caps.setCapability("androidDeviceReadyTimeout","20"); |
|
This capability is used to set DevTools socket name. It is only needed when an app is a Chromium-embedding browser. The socket is opened by the browser and the ChromeDriver connects to it as a DevTools client, for example, caps.setCapability("androidDeviceSocket","chrome_DevTools_remote"); |
|
Using this capability, you can specify the name of caps.setCapability("avd","AVD_NEXUS_5"); |
|
This capability will help you define how long you need to wait (in milliseconds) for an caps.setCapability("avdLaunchTimeout","230000"); |
|
You can specify the wait time (in milliseconds) for an caps.setCapability("avdReadyTimeout","240000"); |
|
To pass the additional emulator arguments when launching an caps.setCapability("avdArgs","netfast"); |
|
You can give the absolute local path to the WebDriver executable (if the Chromium embedder provides its own WebDriver, it should be used instead of the original ChromeDriver bundled with Appium) using the following capability: caps.setCapability("chromedriverExecutable","/abs/path/to/webdriver"); |
|
The following capability allows you to set the time (in milliseconds) for which you need to wait for the Webview context to become active; the default value is caps.setCapability("autoWebviewTimeout","3000"); |
|
Intent action is basically used to start an activity, as shown in the following code. The default value is caps.setCapability("intentAction","android.intent.action.VIEW"); |
|
This provides the intent category that will be used to start the activity (the default is caps.setCapability("intentCategory","android.intent.category.APP_CONTACTS"); |
|
Flags are used to start an activity (the default is caps.setCapability("intentFlags","0x10200000"); |
|
You can enable Unicode input by using the following code; the default value is caps.setCapability("unicodeKeyboard","true"); |
|
You can reset the keyboard to its original state by using this capability. The default value is caps.setCapability("resetKeyboard","true"); |
iOS capabilities
Let's discuss the iOS capabilities, as shown in the following table:
Capability |
Explanation |
---|---|
|
This is used to set the calendar format for the iOS simulator. It applies only to a simulator, for example, caps.setCapability("calendarFormat"," Gregorian"); |
|
caps.setCapability("bundleId"," io.appium.TestApp"); |
|
This is used to specify the amount of time (in millisecond) you need to wait for Instruments before assuming that it hung and the session failed. This can be done using the following command: caps.setCapability("launchTimeout","30000"); |
|
This capability is used to enable location services. You can apply it only on a simulator; you can give the Boolean value, as follows: caps.setCapability("locationServicesEnabled","false"); |
|
If you want to use this capability, you must provide the caps.setCapability("locationServicesAuthorized","true"); |
|
Using this capability, you can accept privacy permission alerts automatically, such as location, contacts, photos, and so on, if they arise; the default value is caps.setCapability("autoAcceptAlerts","true"); |
|
You can use the native instruments library by setting up this capability: caps.setCapability("nativeInstrumentsLib","true"); |
|
This can be used to enable real web taps in Safari, which are non-JavaScript based. The default value is caps.setCapability("nativeWebTap","false"); |
|
You can use this capability on a simulator only. It allows JavaScript to open new windows in Safari. The default is the current simulator setting. To do this, you can use the following command: caps.setCapability("safariAllowPopups","false"); |
|
This capability can be used only on a simulator. It prohibits Safari from displaying a fraudulent website warning. The default value is the current simulator setting, as follows: caps.setCapability("safariIgnoreFraudWarning","false"); |
|
This capability enables Safari to open links in new windows; the default keeps the current simulator settings: caps.setCapability("safariOpenLinksInBackground","true"); |
|
Whether you need to keep keychains (Library/Keychains) when an Appium session is started/finished can be defined using this capability. You can apply it on a simulator, as follows: caps.setCapability("keepKeyChains","true"); |
|
This capability allows you to pass arguments while AUT using instruments, for example, caps.setCapability("processArguments","myflag"); |
|
You can delay the keystrokes sent to an element when typing uses this capability. It takes the value in milliseconds: caps.setCapability("interKeyDelay","100"); |
We have seen all the desired capabilities that are used in Appium. Now, we will talk in brief about the Appium server and its client library.