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
1Enhancing Game Quality with Tencent's automated testing platform UDT, a case study of mobile RPG game project We are thrilled to present a real-world case study that illustrates how our UDT platform and private cloud for remote devices empowered an RPG action game with efficient and high-standard automated testing. This endeavor led to a substantial uplift in both testing quality and productivity.
2How can Mini Program Reinforcement in 5 levels improve the security of a Chinese bank mini program? Let's see how Level-5 expert mini-reinforcement service significantly improves the bank mini program's code security and protect sensitive personal information from attackers.
3How UDT Helps Tencent Achieve Remote Device Management and Automated Testing Efficiency Let's see how UDT helps multiple teams within Tencent achieve agile and efficient collaboration and realize efficient sharing of local devices.
4WeTest showed PC & Console Game QA services and PerfDog at Gamescom 2024 Exhibited at Gamescom 2024 with Industry-leading PC & Console Game QA Solution and PerfDog
5Purchase option change notification Effective from September 1, 2024, the following list represents purchase options will be removed.