A comprehensive development environment setup guide for running automated tests on an Android device. Appium's tech stack is vast, with a significant initial setup phase required to start using it. This guide demonstrates the process and includes an example mocha test project. While the guide is tailored for Windows, the principles apply to other platforms. It has been verified for compatibility with Linux.
(Note - the whole thing can be used to test an iOS app too because Appium is being used as the middleman. You'd just need to modify the page object to include iOS specific locators and tweak the driver options).
Install node.js and confirm its successful installation by opening a command prompt and typing:
node -v
Install the JDK and ensure the JAVA_HOME environment variable is set. If not, add it. On Windows, I've configured it as a system-wide variable. You can store the JDK anywhere you prefer:
Install Android Studio.
Android Studio is essential to:
a) Run and connect to an emulated Android device using the Android Debug Bridge (adb)
b) Install tools and SDKs, enabling Appium's server to connect to the Android device
Clone the app we'll test: https://github.com/Palringo/QA-Automation-Android:
git clone https://github.com/Palringo/QA-Automation-Android.git
Or download it directly from GitHub as a zip.
If familiar with Kotlin or eager to inspect the app structure, open the cloned repository in Android Studio. You can deploy the app to the emulated device using the "Run" button in Android Studio. Note that the actual tests will handle the installation of the pre and release APKs onto the device.
Optionally, open Android Studio and create a new empty project (accessing the device manager to run an emulated Android phone is the main goal). Install any Android emulator (e.g., MS Android Emulator) or connect a physical device via USB/Wi-Fi. As long as adb can communicate with the device, Appium can relay commands for automated tests.
Open the SDK Manager in Android Studio:
Note that the SDK Platform for version 34 of the Android API is installed:
Open the SDK Tools tab and ensure the items displayed are installed. Add the command line tools by selecting them and clicking "Apply":
Remember the Android SDK location; we'll need it for the subsequent environment variable setup:
Take a break, then ensure all environment variables allow using adb and other SDK commands:
Verify the environment variables setup:
echo %path:;=&echo.%
echo %ANDROID_HOME%
Now, the adb and other Android SDK commands can be used from the console:
Activate a device from the Device Manager in Android Studio, return to the command prompt, and enter:
adb devices -l
The emulated device should now appear:
There's progress now, where there once was non.
We're ready to install Appium and the required driver it needs to run automated tests.
Open a command window and type:
npm i --location=global appium
https://appium.io/docs/en/2.0/quickstart/install/
Now check Appium starts up by typing Appium
into a new console window. It runs on port 4723 by default.
Make sure any security software isn't blocking this port otherwise:
Now install the required driver to run automated tests on Android:
appium driver install uiautomator2
https://appium.io/docs/en/2.0/quickstart/uiauto2-driver/
Now when you run Appium you should see the driver is present:
Clone this repo and open in your preferred JS IDE and open the test file. Change the testingReleaseBuild
variable depending on which apk you wish to test:
let apk;
const testingReleaseBuild = true;
if (testingReleaseBuild) {
apk = path.resolve('./app/release/app-release.apk');
} else {
apk = path.resolve('./app/pre-release/app-release.apk');
}
You can also run the test from inside your IDE or via:
npm test
Doing it via npm test will generate a mocha test report inside the mochawesome-report
directory.
If testing the pre-release build, there should be a bug when the button is clicked a second time:
Bug Report:
BUG REPORT
Title: Label isn't updating correctly on second click.
Product/Component: Button Clicker
Version: pre-release APK
Environment: Android 12
Reported by: [email protected]
Date reported: 15/10/2023
Priority: Low
---
Description: Label isn't updating correctly on second click.
---
Steps to Reproduce:
1. Open app
2. Click button once
3. Click button again
---
Expected Behavior: Label shold be "2"
---
Actual Behavior: Label shows "Max"
---
Screenshots/Logs: N/A
---
Workarounds (if any): N/A
---
Additional Information: Found in automated regression test "Button Click Count Feature Acceptance Test":
https://github.com/ardz/wolfpack/blob/main/test/test.js
If testing the release build, all the steps should pass: