Manual testing is an essential part of Android application testing that involves a tester manually going through an application to ensure that it meets the desired specifications and quality standards. However, this process can become monotonous and repetitive, leading to a decrease in the tester's attention span and motivation. As a result, the testing process can become less effective, and the quality of the application can suffer. This is where Appium comes in, offering a solution to this problem by handling repetitive tasks and freeing up the tester's time and energy to focus on more complex and creative aspects of testing.
Appium is an open-source tool for automating native, mobile web, and hybrid applications. It allows you to write tests in multiple programming languages such as Java, Ruby, Python, etc. With Appium, you can write tests that simulate user interactions on an Android device, which can help test the functionality of your application.
Furthermore, Appium uses the standard WebDriver API, so you can leverage the wide range of WebDriver-based tools and libraries available in the market. One of the major advantages of Appium is it can be integrated easily with other testing frameworks, such as Selenium, allowing testers to leverage existing test scripts and frameworks for mobile app testing.
By the end of this article, you will have a thorough understanding of how to get started with Android test automation using Appium and Java. Furthermore, you will be able to automate a feature of the Calculator app, putting into practice what you've learned. Before we get started the reader should have a basic knowledge of Java programming language and Selenium. We’ll cover the following topics:
Setting up Appium for Android test automation
Getting appPackage and appActivity
Writing your first Appium test
1. Setting up Appium for Android test automation
Setting up Appium for Android test automation is a straightforward process. I will be showing the setup in macOS for this article. You can check the installation in Windows from here. Here’s how you can get started:
Install Homebrew: Homebrew is a package manager for Mac OS X that makes it easy to install and manage open-source software. You can install Homebrew by following the instructions on the Homebrew website.
Install Node.js: Appium is built on Node.js, so you’ll need to install Node.js on your Macbook. You can install Node.js by running the following command in your terminal:
brew install node
Install Appium: Once you have installed Node.js, you can install Appium by running the following command in your terminal:
npm install -g appium
Install Android Studio: You’ll also need to install Android Studio on your Macbook. The Android Studio provides the tools and APIs required to develop, test, and debug Android applications. You can download the Android Studio from the Android developer website.
Setup SDK Platforms and Tools: Once downloaded and installed, open Android Studio, click on Configure, and then SDK Manager.
You can download any desired SDK Tools from here. Also can upgrade any required updates from Android SDK settings. We’ll select the defaults for now.
Set up Environment Variable: To run Appium tests on an Android device, you need to set up environment variables that tell the Appium server where to find the Android SDK and other tools like the emulator and platform tools. This is necessary to ensure that Appium can access these tools and run tests correctly.
To accomplish this, we can include the following variables in the system environment.
To add environment variables for Android Studio, you need to edit the shell profile file for your chosen shell. For Bash, this is usually the .bash_profile file, while for Zsh it's the .zshrc file.
Set up the Android emulator: Once you have installed the Android SDK, you can set up an Android emulator to test your application. The Android emulator is a software tool that allows you to run a virtual Android device on your computer. This virtual device can be used to test your applications without the need for a physical Android device.
Open Android Studio
Click on AVD Manager
To create an Android emulator, you need to launch the Virtual Device Configuration flow, which is accessible from within Android Studio.
When creating an Android emulator, it's important to consider which Play Store services are available, as certain apps may require the latest version of these services to be installed. Select the operating system and all the necessary stuff and complete creating the virtual device.
After creating our emulator, we can start it up by tapping the Play icon under the Actions section.
Start the Appium server: Once you have completed all of the above steps, you can start the Appium server by running the following command in your terminal:
That’s it! You have successfully set up Appium for Android test automation on your Macbook. You can now write and run Appium tests for your Android application.
This test uses the Appium Java client library and launches the Calculator app on an Android device, performs some basic calculations, and verifies the result. It uses the AndroidDriver class to interact with the mobile device, and DesiredCapabilities to set the device's capabilities.
Run the test: Run the test from your IDE, and it will execute the test on the connected mobile device or emulator.
Note: Ensure the Appium server is running and listening to the correct port before executing the test.
Here are some Top Appium Installation Hacks that's can make your Appium installation easier:
Install required dependencies separately: Appium requires several dependencies, such as Node.js and the Android SDK. Installing these dependencies separately can make the Appium installation process smoother.
Use Appium doctor: Appium doctor is a command-line tool that can help diagnose and resolve common installation issues. Running Appium doctor before installing Appium can help identify any missing dependencies or configuration issues. https://github.com/appium/appium-doctor
Use a package manager: Using a package manager like Homebrew (for macOS) can simplify the installation process by automatically resolving dependencies. https://brew.sh/
Thank you for reading this blog post. I hope you found the information useful and informative. If you enjoyed this post, be sure to check out our next blog post, which will focus on locating elements on Appium, POM and running & debugging Appium tests on Android.
In today's digital age, mobile applications have become an integral part of our daily lives. From ordering food to managing finances, there seems to be an app for every need. Behind the scenes, these apps are powered by a technology that has revolutionize...
Spatial is a metaverse platform that allows anyone to create immersive 3D spaces, which can be instantly shared to the Web, iOS, Android, and VR, and explored by others. The Spatial Creator Toolkit, powered by Unity, allows you to add even more interactiv...