Configuring App Activity in Appium
Configuring the App Activity in Appium is a straightforward process that is easily replicable. To demonstrate the application of App Activity in Appium, here is the documentation of a sample UI Test using UIAutomator2 in Android:
1. Installing The Dependency
To incorporate Appium into an Android app, here is the dependency that needs to be implemented in the build.gradle.kts (app) file:
Kotlin
implementation( "io.appium:java-client:9.1.0" ) { exclude(group = "com.google.guava" ) } implementation( "com.google.guava:guava:30.1-jre" ) |
To prevent version conflicts, Guava has been excluded from the Appium dependency and has been set up on its own instead.
2. Setting Up Appium
As documented by Appium, the Appium Server should be installed using the npm i -g appium command after which its installation can be confirmed using the appium command to get the following output:
Once the Appium Server has been set up, it is time to install the UIAutomator2 Driver. It will be used to perform the Automated UI Test. To install it, the appium driver install uiautomator2 command is used and when appium is run to start the Appium Server again, part of its output should contain:
3. Setting Up The Options
Once everything has been correctly set up and the Appium Server is up and running, it is time to write out the attributes that represent the specifications for the Appium Test. Here is an example of such a configuration:
In the example displayed above, here are the attributes that have been used:
- setAutomationName: It is used to define the UI Test Automation Tool being used, in this case, UIAutomator2.
- setPlatformName: It is used to declare the target platform of the UI Test, which in this case is Android.
- setApp: It is used to locate the .apk file to be tested using its absolute path.
- setAppActivity: It is the attribute used to select the main Activity of the UI Test, that is the Activity that the test will begin from.
- setDeviceName: If the UI Test is done using a physical Android Device, then the device name is specified using this attribute. The name can be obtained by checking the displayed name under Device Manager on the right tab of Android Studio. If a virtual device is used, the command adb devices can be used to check its id alongside the setUdid attribute.
To connect the Appium configuration to the Appium Server, use the AndroidDriver class and define the URL displayed in the Appium Server’s log after Appium was previously run to start the Appium Server. The URL is typically http://127.0.0.1:4723/ as it represents the host’s local address. The driver variable can also be used to perform interactive actions on the screen during the UI Test by calling functions such as .findElement() to locate and interact with UI Elements. For simplicity, the example used has simulated the startup and closure of the Android app using TimeUnit introducing a 5-second delay during the app’s launch and termination. Once the tests have been run, the driver is closed using .quit() to preserve limited resources.
4. Running The Test
Finally, the test is run by clicking the green icon beside the fun main(). The script is executed and the Android app should be launched and any UI Tests conducted automatically. If the test is successful, the following should be the output on the console:
To confirm the execution of the UI Test, the Appium Server should also have 200 displayed within its logs as it represents a successful network request between the client (Android app) and itself, which is equivalent to the Status Code 200 (OK).
Understanding App Activity in Appium | How it Works, Importance, Best Practices
Appium is integral to UI Automation within different domains in Tech: Mobile, Web, and even Desktop. The platform aims to streamline Software Testing through the following goals as outlined by its creators:
- Make platform-specific automation capabilities available under a cross-platform, standard API.
- Allow easy access to this API from any programming language.
- Provide tools to enable convenient community development of Appium extensions.
Appium is a suitable choice for Mobile Developers who want to benefit from the automation of UI Testing due to its ease of use and versatility. This article seeks to define what App Activity is in the context of Appium and Android.
Contact Us