Pricing

Appium Desired Capabilities: What Are They and How to Launch?

Appium desired capabilities can help us modify the behavior of the server during automation. Understanding and learning how to use it is important for app automation testing. In this blog, we will dive into this concept.

What is Appium?

Appium is a cross-platform mobile automation testing tool that enables the convenient creation of automated test cases for iOS and Android platforms. It can simulate various factions within an app, such as clicking, swiping, and text input, accomplishing any actions that would typically require manual intervention.

What are Appium desired capabilities

Desired Capabilities in Appium serve as a configuration mechanism, carrying essential information in key-value pairs. Essentially, it can be understood as a map in Java, a dictionary in Python, a hash in Ruby, or a JSON object in JavaScript. When transmitted, Desired Capabilities are represented as JSON objects.

The primary purpose of Desired Capabilities is to provide the necessary context for the Appium server to execute the current test.

Key details to consider when configuring Desired Capabilities are as follows:

 

1. automationName: Specifies the automation engine to use, either Appium (default) or Selendroid.

2. platformName: Indicates the name of the platform being used, such as iOS, Android, or FirefoxOS.

3. platformVersion: Refers to the version number of the mobile device's operating system, for example, 7.1 or 4.4.

4. deviceName: Represents the name of the device. For Android, this can be any arbitrary name. For iOS, it can be obtained using the command "instruments -s devices."

5. udid: Provides a unique identifier for the connected physical device, which can be obtained using the command "adb devices."

6. app: Specifies the absolute local path or a remote HTTP URL pointing to an installation package (.ipa, .apk, or .zip file). Appium installs this package on the appropriate device. For Android, this parameter is not required if the appPackage and appActivity parameters are provided. This parameter is not compatible with browserName. (Often used together with the noSign property.)

7. browserName: Specifies the H5 web browser to be tested. If testing an app, this can be ignored.

8. newCommandTimeout: Represents the time (in seconds) that Appium waits for the client to send a new command before exiting or ending the session.

9. noReset: When set to true, it prevents the app's state from being reset before the current session. By default, it is set to false.

10. fullReset: (iOS) Deletes all simulator folders. (Android) To clear the app's data, the app must be uninstalled to achieve the reset effect. In Android, the app is also uninstalled after the session is completed. The default value is false.

 

Specific to Android, the following additional key-value pairs are commonly used:

 

1. appPackage: Specifies the package name of the Android app to be executed. If testing an H5 webpage, this property can be ignored.

2. appActivity: Refers to the name of the Activity to be launched from the app package. Usually, it needs to be prefixed with a dot ('.'). If testing an H5 webpage, this property can be ignored.

3. unicodeKeyboard: When set to true, it enables the use of the Unicode input method. The default value is false.

4. resetKeyboard: After using the Unicode keyboard in a Unicode test, this property, when set to true, resets the input method to its original state. If used alone, it will be ignored. The default value is false.

5. noSign: When set to true, it skips the checking and debugging signature steps for the application. Only applicable to UiAutomator and not for Selendroid. The default value is false. (Usually used together with the app property.)

 

Here's a simple example of using Appium desired capabilities to launch the Calculator app on an Android device:

from appium import webdriver
 
# Desired Capabilities for Android
desired_caps = {
    'platformName': 'Android',
    'platformVersion': '9.0',
    'deviceName': 'Android Emulator',
    'appPackage': 'com.android.calculator2',   # Package name of the Calculator app
    'appActivity': 'com.android.calculator2.Calculator',   # Activity name of the Calculator app
    'automationName': 'Appium',   # Default automation engine
}
 
# Appium server URL (replace with your server address)
appium_server_url = 'http://127.0.0.1:4723/wd/hub'
 
# Start an Appium session
driver = webdriver.Remote(appium_server_url, desired_caps)
 
# Perform some actions on the Calculator app
driver.find_element_by_id('digit_1').click()
driver.find_element_by_id('op_add').click()
driver.find_element_by_id('digit_2').click()
driver.find_element_by_id('eq').click()
 
# Get the result and print it
result = driver.find_element_by_id('result').text
print(f"The result is: {result}")
 
# Close the Appium session
driver.quit()

 

In this example, we use Appium with Python to automate the Calculator app on an Android device. By defining the Desired Capabilities, we specify essential configurations like the platform name (Android), platform version (9.0), and the Calculator app's package name and activity name. Establishing a connection to the Appium server, we launch the app on the device and proceed to interact with it by finding elements and performing actions, such as clicking buttons to perform addition. We then retrieve and print the result displayed on the Calculator app.

Final words

The fierce competition in the market pushes developers to optimize the quality of their products and provide cross-platform quality services. Based on real devices, WeTest Automation brings you fast and efficient testing solutions that simplify and accelerate the testing cycle, and help your products stand out in the market.

 

订阅新功能推广裂变活动
Latest Posts
1Steam Deck Compatible Games | Overview Find out about the expanding assemblage of steam deck compatible games that work perfectly on the interactive Steam Deck and provide portable gaming experiences in a variety of genres.
2Mastering PlayStation Portal Games Compatibility | Detailed Roadmap Are playstation portal compatible games? Find out the PlayStation Portal game compatibility which is important for the developers and the testers.
3Are Playstation Games Backwards Compatible | Detailed Explanation Are playstation games backwards compatible? Backward compatibility for PlayStation games is an essential feature and game testers must ensure this by following rigorous compatibility testing steps.
4Are Nintendo Switch Games Compatible With Switch Lite?  Are nintendo switch games compatible with switch lite? Find out the Nintendo Switch game compatibility with the Switch Lite which is important for the developers and the testers.
5This is QA on Easy Mode, Why Should You Try WeTest Automation Testing? With WeTest’s unique automated testing solutions, you can streamline your testing processes, ensure high-quality deliverables, and stay ahead in a competitive market.