Understanding Desired Capabilities in Appium

Desired Capabilities in Appium

Ensuring the dependability and error-free nature of the automated approach for testing mobile applications is crucial. An open-source, cross-platform tool for automating mobile applications is called Appium. An effective element is “Desired Capabilities.” When a mobile app is loaded on a device or emulator, these features work as a set of parameters that let users adjust and personalize how the Appium server behaves.

Consider the anticipated features as the guidelines you give Appium to ensure the ideal configuration of the testing environment. They accomplish this by defining a number of attributes, including the automation settings, application, device, and platform, which guarantee that the automation script runs in the proper environment.

Desired capabilities in context to Appium

The Appium server uses desired capabilities as a configuration approach to determine how to set up the automation session. This method specifies the automation engine, timeouts, application path, mobile platform, device information, and other pertinent settings. Usually, at the start of a test script, these key-value pairs are submitted to the Appium server so that the testing circumstances can be customized to meet particular needs.

Desired Capabilities are essential to guarantee that the automation script works with the designated mobile application and platform without a hitch. For thorough mobile app testing, they enable developers and testers to modify the automation process to various devices, operating systems, and application states.

Appium Desired Capabilities for Android and iOS Platforms

When utilizing Appium for Android or iOS automation, you may configure a lot of useful features to customize and personalize your testing environment. Some often requested features for Appium on Android as well as iOS are as follows:
platformName: Denotes the desired mobile platform; for Android automation, “Android” is the default value and for  iOS automation,  “iOS” is the default value.

  capabilities.setCapability("platformName",  "iOS"); 
capabilities.setCapability("platformName", "Android"); 

2 . deviceName: Gives the mobile device or emulator a name or identity.

capabilities.setCapability("deviceName", "your_device_name");

3. platformVersion: signifies the version of your ‘Android’ OS or ‘iOS’ OS    

capabilities.setCapability("platformVersion", "your_android_version");

capabilities.setCapability("platformVersion", "your_ iOS_version");

4. newCommandTimeout: Specifies the amount of time (in seconds) that Appium should wait for a fresh command from the client.

capabilities.setCapability("newCommandTimeout", 120);

   5. app: Indicates the path or Web address of the Android programme (.apk file) or else the path or Web address of the  “iOS” programme (.ipa file) that needs to be examined.

capabilities.setCapability("app", "path/to/your/app.apk");

capabilities.setCapability("app", "path/to/your/app.ipa");

6. appWaitActivity and appWaitPackage: Specifies the package and activity to hold off on till the application launches.

capabilities.setCapability("appWaitActivity", “your.wait.activity");

capabilities.setCapability("appWaitPackage", "your.wait.package");

7. noReset: Should this be set to true, Appium won’t be allowed to reset the application’s state prior to the test. If set to false, the state of the application is cleared.

	capabilities.setCapability("noReset", true);

8. fullReset: If set to true, this command reinstalls the programme and erases all of its data. Cautiously, as it results in an installation that is clean.

	capabilities.setCapability("fullReset", false);

9. keyboard reset and unicodekeyboard: Resetting the keyboard enables Unicode input. Keyboard puts the keyboard back in its original setting.

capabilities.setCapability("unicodeKeyboard", true);

capabilities.setCapability("resetKeyboard", true);

10. appPackage: appPackage provides the package name of the Android as well as iOS app.

capabilities.setCapability("appPackage", "your.app.package");

11. appActivity: This phrase refers to the main purpose of an Android application.

capabilities.setCapability("appActivity", "your.app.activity");

12. automationName: Identifies the automation engine to be utilized. For Android, it is typically set to “UiAutomator2” and for “iOS”, it is typically set to “XCUITest”.

capabilities.setCapability("automationName", "UiAutomator2");
capabilities.setCapability("automationName", "XCUITest");

13. udid: Displays the Unique Device Identifier of the real ‘Android’ and ‘iOS’device.

14. autoGrantPermissions: This feature automatically gives the necessary permissions to the app during installation.

capabilities.setCapability("autoGrantPermissions", true);

15.autoWebview: The application will automatically transition to the webview context if it has one.

	capabilities.setCapability("autoWebview", true);

16.waitForAppScript: Allows for custom configuration by specifying a JavaScript script to run prior to the application being launched.

capabilities.setCapability("waitForAppScript", "your_custom_script");

17. appium:connect Keyboard Hardware: if set to true, connects the hardware keyboard to the simulator.

capabilities.setCapability("appium:connectHardwareKeyboard", true);

18. calendar appiumFormat: Indicates how dates should be transmitted to a mobile application.

capabilities.setCapability("appium:calendarFormat", "gregorian");

19. orientation: Defines the device’s initial orientation (portrait or landscape).

capabilities.setCapability("orientation", "LANDSCAPE");

These are only a few examples; the ideal features you choose will depend on the real requirements and testing environment of your app. It is imperative that you refer to the Appium manual for the most up-to-date and comprehensive list of features that are needed.

Appium desired capabilities for Android

The testing environment can be customized by configuring different desired capabilities when using Appium for android automation. The following are some often requested features for Android’s Appium:

1 . avd: Indicates the Android Virtual Device (AVD) name that will be utilized during the testing process.

capabilities.setCapability("avd", "Pixel_4_API_30");

2. chromedriverExecutable: Indicates the location of the Android web testing ChromeDriver executable file.

capabilities.setCapability("chromedriverExecutable", "/path/to/chromedriver");

3. androidScreenshotPath: Indicates the location on the device where screenshots from the test should be kept.

capabilities.setCapability("androidScreenshotPath", "/sdcard/screenshots");

4. androidScreenshotOnFail: Allows screenshots to be taken automatically when a test fails.

	capabilities.setCapability("androidScreenshotOnFail", true);

5. androidInstallTimeout: Indicates the longest period of time (in milliseconds) that must pass before the Android package is installed.

capabilities.setCapability("chromedriverExecutable", "/path/to/chromedriver");

6. disableWindowAnimation: To expedite the execution of tests, disable window animations on the device.

	capabilities.setCapability("disableWindowAnimation", true);

7. androidCoverage: Indicates the package name for Android that contains the instrumentation tests that need to be run.

capabilities.setCapability("androidCoverage", "com.example.android.test/com.example.android.test.InstrumentationTestRunner");

8. skipUnlock: When initiating an automated session, skips the device’s unlocking process. helpful if the gadget has previously been unlocked.

capabilities.setCapability("skipUnlock", true);

9. skipDeviceInitialization: This feature, which might be helpful for accelerating test setup, skips the device and app initialization.

capabilities.setCapability("skipDeviceInitialization", true);

10. Disable Android watchers: Turns off the apps that keep track of the condition of the device while it’s being tested.

capabilities.setCapability("disableAndroidWatchers", true);

Particularly for Android automation, these required characteristics offer more control and customisation possibilities. Depending on the specifications of your tests, you can modify these features as necessary.

Appium desired capabilities for IOS

When utilizing Appium for iOS automation, the testing environment can be modified by setting up various desired features. The following is a list of some often requested features for Appium for iOS:

  1. startIWDP: Launches the iOS WebKit Debug Proxy, enabling web view inspection.
capabilities.setCapability("startIWDP", true);

2. bundleId: Indicates the iOS application’s bundle identifier.

capabilities.setCapability("bundleId", "your.app.bundle.id");

3. useNewWDA: Replaces the legacy WebDriverAgent (WDA) with the new one.

capabilities.setCapability("useNewWDA", true);

4. xcodeOrgId and xcodeSigningId: For code signing, provide the Xcode organization identification and signing identity.

capabilities.setCapability("xcodeOrgId", "your_xcode_organization_id");
capabilities.setCapability("xcodeSigningId", "your_xcode_signing_id");

5. waitForAppScript: Allows for custom configuration by specifying a JavaScript script to run prior to the application being launched.

capabilities.setCapability("waitForAppScript", "your_custom_script");

6. wdaLocalPort and wdaStartupRetries: Indicate the WebDriverAgent local port and the quantity of startup attempts.

capabilities.setCapability("wdaLocalPort", 8100);
capabilities.setCapability("wdaStartupRetries", 4);

7. autoAcceptAlerts: Automatically accepts native alarms during test execution.

capabilities.setCapability("autoAcceptAlerts", true);

8. wdaLocalPort and wdaStartupRetries: Indicate the WebDriverAgent local port and the quantity of startup attempts.

capabilities.setCapability("wdaLocalPort", 8100);
capabilities.setCapability("wdaStartupRetries", 4);

9. simpleIsVisibleCheck: Makes use of WebDriverAgent (WDA) to perform a less precise but simpler visibility check. While test speed may increase as a result, visibility checks may become less trustworthy.

capabilities.setCapability("simpleIsVisibleCheck", true);

10. maxTypingFrequency: Indicates the highest possible typing rate (measured in keystrokes per minute) while the test is running.

	capabilities.setCapability("maxTypingFrequency", 40);

11. wdaLaunchTimeout: Indicates the WebDriverAgent (WDA) startup timeout (in seconds).

	capabilities.setCapability("wdaLaunchTimeout", 30000); 

12. waitForQuiescence: Prior to initiating the test, waits for the application to go quiescent (no UI events).

	capabilities.setCapability("waitForQuiescence", true);

13. useJSONSource: Retrieves the source data from WebDriverAgent (WDA) in JSON format.

capabilities.setCapability("useJSONSource", true);

These are merely examples; the capabilities that are necessary for your testing scenario and iOS app will depend on their specifics. Consult the Appium handbook at all times for the most complete and current list of features that are desired.

How to set up Appium Inspector and Launch Your First Test

Follow these steps to set up Appium Inspector:

Step 1: Install Appium: The process begins with installing Appium on your computer. At ( http://appium.io/ ), you can download the most recent version of Appium for your operating system.

Step 2: Install Appium Desktop: After installing Appium, you must install Appium Desktop, which includes Appium Inspector. You may install Appium Desktop on your PC by downloading it from the official website.

Step 3: Install Appium server: The next step prior to starting Appium Inspector is installing the Appium server. By pressing the “Start Server” button, the Appium desktop will appear. The Appium server on your computer will start up as a result.

As soon as you will click on the “Start Server” button, it will show three alternatives (ie. Simple, Advance, Present) 

  1. Simple – It uses the default values to start the server using the Host Server Address and Server Port.
image7

2. Advanced: The host server’s unique address and port can be given. The Chrome driver port address will be available for us to use when testing a Web application on Chrome.

image5

3. Presets: This will help us use any preset values which we have used in the Advanced tab. We are saving the new custom Host Server Address and Server Port by using the “Save As Preset” option in the Advanced tab. Then use them back by clicking on them from the Preset tab.

image6 1

Once your server is running you will see a screen similar to this. It will show the Appium version and the server host and the port address.

image3

For us to start the Appium Inspector session we need to click on the magnifying glass button(🔍) on the top panel.

Step 4: Connect your device: Connect your mobile device to your computer with a USB cable. Make sure the device is in developer mode with USB debugging enabled.

The next we need to do is, to configure the application’s capabilities for testing.You should be able to add your capabilities under the Desired Capabilities tab after starting your Appium Inspector session.

Step 5: Setting up the required Capabilities: To connect your device to the Appium server, you need to specify the necessary features. Click the “New Session” Window button on the Appium desktop and enter the required capabilities for your device. On the Appium website, you can find information about the features available for your device.

There are two different ways of adding capabilities in appium inspector:

  1. By using the text boxes for capability names and mentioning the type and value.
image1 1

2. By adding them in JSON format.

image2

Once your capabilities are set, we need to click on the “Start Session” button.

image8

And then the screen looks like below,

image3 1

Conclusion:

During automation, testers can easily locate and interact with app pieces thanks to Appium’s necessary functionalities. The precise app can be found by providing parameters like appActivity and appPackage. Additionally, features like automationName give testers access to robust automation frameworks, making it simple for them to identify items using techniques like accessibility IDs, XPath, or element attributes. Stated differently, the ability to configure Appium to accurately and consistently recognise objects is critical to guaranteeing seamless automation of app interactions.

To put it simply, testers can fine-tune their mobile testing by using Appium’s desired capabilities, which are similar to personalized settings. Testers can alter how their tests behave across various devices and applications by adjusting these variables. They become essential tools for testers since they provide reliability and flexibility in testing across multiple platforms. Testers can guarantee the dependability and effectiveness of their Appium mobile testing setups by comprehending and using these capabilities in the most effective ways.

To put it briefly, these needed characteristics give testers the means to build flexible and dependable Appium environments for mobile testing. They offer a great deal of versatility when utilized properly, which increases the efficacy of automated testing in the dynamic field of mobile app development.

Furthermore, since Appium continues to be the go-to option for cross-platform mobile testing, making efficient use of desired capabilities is essential to the success of automation initiatives. By following industry best practices, testers may maintain scripts that are not only flexible to changing application needs but also dependable and efficient across multiple testing scenarios.

FAQ’s

Q:1 What is Appium?
Ans: Appium is a popular open-source, cross-platform mobile application testing tool that allows testers or developers to write automated tests for native, hybrid, and mobile applications and offers many benefits. Appium supports testing iOS and Android apps using the same API and based on the same framework as Selenium WebDriver.

Q:2  How do I calculate the right numbers to match the features I want in my mobile app?
Ans: The best Desired Capabilities settings can be found by looking over the specifics of your project. Use the ADB tools to acquire package and activity information for Android; use Xcode or the Appium inspector for iOS.

Q:3 How can I make sure my desired capabilities are configured correctly?
Ans: You can check the logs produced at the start of the automated session by the Appium server to verify sure you have the necessary capabilities. Error messages or exceptions may also provide clarification on any difficulties related to the capability.

Q:4 How can I manage app permissions during automation using Desired Capabilities?
Ans: App permissions can be managed using the autoGrantPermissions function, which installs apps automatically and grants the necessary permissions. By making use of the app’s numerous capabilities, you may also regulate how it behaves in terms of permissions.

Q:5 What is the aim of the autoWebview functionality and how does it operate?
Ans: The software can be relocated automatically to a webview context if it has one, thanks to the autoWebview option. This is an excellent tool for testing hybrid mobile apps.

Q:6 What are the recommended methods for putting the required competencies into practice?
Ans: Best practices include things like keeping the capabilities organized, selecting appropriate defaults, and defining their purpose. It’s also a good idea to frequently review the Appium documentation to see if any capabilities have changed.

Q:7 Is it possible to dynamically change the desired capabilities during runtime?
Ans: Yes, you can adjust Desired Capabilities dynamically during script execution by making modifications to the capabilities object. This allows for flexible modification of the test script to account for different scenarios.

Q:8 What are the differences between real devices and emulators/simulators in terms of desired capabilities?
Ans: Desired Certain functions—like udid and avd (Android Virtual Device)—are exclusive to genuine devices, even if the majority of features of emulators and simulators and those of real devices are similar.

Q:9 Is it feasible for me to turn the device during the test using Desired Capabilities?
Ans: Yes, you can use the orientation capability to set the device’s initial orientation. For instance, you can select “PORTRAIT” or “LANDSCAPE” to change the orientation at test start.

Q:10  How do desired capabilities fit into the cross-platform testing process?
Ans: Cross-platform testing requires Desired Capabilities, which let you to provide platform-specific parameters like bundleId for iOS and appPackage and appActivity for Android. This customisation guarantees a smooth platform changeover.