Desired Capabilities

Desired capabilities in Appium are a set of key-value pairs that tell the Appium server what kind of automation session to start. They provide essential information such as the platform you are testing (Android/iOS), the device details, the app you want to test, and much more.

In simple terms, Desired Capabilities are the configuration settings that allow you to specify what kind of device, app, and environment you want to use for your mobile test

Why are Desired Capabilities Important?

Desired Capabilities help in:

  • Identifying the Device: Whether it's a physical device or an emulator/simulator.
  • Defining the App: Tells Appium which app to launch on the device.
  • Choosing the Automation Framework: Specifies which automation engine to use (like UiAutomator2 for Android or XCUITest for iOS).
Without setting the correct desired capabilities, the Appium server wouldn’t know what to automate or how to set up the environment.

Basic Structure of Desired Capabilities

In Appium 2.x, Desired Capabilities are passed to the Appium server as part of the session creation request. Depending on the platform (Android or iOS), some capabilities will be different.

Example for Android:

Java
C#
Python
Javascript
Kotlin
Copy
UiAutomator2Options options = new UiAutomator2Options();

options.setPlatformName("Android");  // Specifies that the platform is Android

options.setDeviceName("Pixel_4_Emulator");  // Name of the device/emulator

options.setAutomationName("UiAutomator2");  // Automation engine for Android

options.setApp("/path/to/your/app.apk");  // Path to the APK file of the app you want to test

C# code coming soon
Python code coming soon
Javascript code coming soon
Kotlin code coming soon

Example for iOS:

Java
C#
Python
Javascript
Kotlin
Copy
XCUITestOptions options = new XCUITestOptions();

options.setPlatformName("iOS");  // Specifies that the platform is iOS

options.setDeviceName("iPhone 12");  // Name of the device/simulator

options.setAutomationName("XCUITest");  // Automation engine for iOS

options.setApp("/path/to/your/app.app");  // Path to the iOS app (.app file) you want to test

C# code coming soon
Python code coming soon
Javascript code coming soon
Kotlin code coming soon

Common Desired Capabilities (for Android & iOS)

Here are some commonly used desired capabilities in Appium:
  1. platformName:
    • Specifies the platform to test on, e.g., Android or iOS.
    • Example: options.setPlatformName("Android");
  2. deviceName:
    • The name of the device or emulator/simulator where the app should run.
    • Example: options.setDeviceName("Pixel_4_Emulator");
  3. automationName:
    • Specifies the automation framework to use. For Android, it's typically UiAutomator2, and for iOS, it's XCUITest.
    • Example: options.setAutomationName("UiAutomator2");
  4. app:
    • The path to the application that you want to test. This can be an .apk for Android or a .app file for iOS.
    • Example: options.setApp("/path/to/your/app.apk");
  5. platformVersion:
    • Specifies the OS version of the device or emulator/simulator.
    • Example: options.setPlatformVersion("12.0");
  6. udid (for iOS):
    • The unique device identifier for a real iOS device.
    • Example: options.setUdid("auto-generated-device-id");
  7. browserName:
    • If you're testing a mobile browser (e.g., Safari on iOS or Chrome on Android), you can set this capability to run browser tests.
    • Example: options.setBrowserName("Chrome");
  8. noReset:
    • If set to true, this capability tells Appium not to reset app state between sessions.
    • Example: options.setNoReset(true);

Additional Desired Capabilities for Specific Use Cases

You can also add other capabilities depending on your testing needs:

  1. fullReset:
    • If set to true, the app will be fully uninstalled and reinstalled before every session.
    • Example: options.setFullReset(true);
  2. newCommandTimeout:
    • Sets the timeout for waiting for new commands before ending the session.
    • Example: options.setNewCommandTimeout(300); (300 seconds)
  3. language:
    • Specifies the language to set on the device.
    • Example: options.setLanguage("fr"); (for French)
  4. locale:
    • Specifies the locale for the device, like US for the United States.
    • Example: options.setLocale("US");