Planet Test Automation: First Steps Automating Mobile UI Testing
This article complements corresponding webinar from the Planet Test Automation series we are running at Inflectra. Once the recording of the webinar is available it will be referenced here. Test Plan section contains an overview of the demo presented in the webinar.
Mobile Testing Landscape
Mobile devices conquered the world. Most consumer applications have either dedicated mobile clients or specialized web versions. More than half of network traffic is mobile nowadays. So, there is no doubt we need to test applications on mobile platforms. At the moment we have two most popular platforms: Android and iOS. Since variety of devices is pretty high and new versions of mobile platforms are released every year, we may need to run our tests on different virtual and physical devices. It leads us up to the following landscape:
Most of mobile UI testing is still manual. And there are solid reasons for that. Mobile platforms have much better human faced interface than API for test automation tools. Many things are still not possible. One cannot grab a mobile device, perform a test manually and let an automated tool record the actions. It is problematic to use same test for both Android and iOS targets. Mobile tests are pretty slow. But things are getting better over time and it is already possible to get benefits from automated mobile testing.
Architecture of Mobile Testing
Let’s look at the architecture of mobile testing. Just like Selenium is a standard choice for automating browsers, in the mobile world the number one choice is Appium. Appium architecture and API is built on the same principles as Selenium and implements WebDriver interface. Appium connects to virtual and physical devices and listens to commands from network clients. It makes possible to use Appium in UI testing frameworks and test automation solutions. This is why many automated testing tools are integrated with Appium and use it under the hood. Typical mobile testing architecture looks like this.
Developers write code directly using Appium API and create their own testing frameworks. Testers use test automation tools that hide complexity of coding and offer object repository, recording, reporting, test management and other features out-of-the-box.
Application Under Test
As a demo application we are using Crate. It is a sample web and mobile application built with React and React Native and running on Node. You may clone the repository from GitHub and run the application in 10 minutes. It has web version and native clients for Android and iOS.
Test Automation Tool
For test recording and execution we are using Rapise — UI test automation tool for desktop, web and mobile applications.
Setting Up Desktop Environment
For iOS testing we need two machines (Mac OS + Windows). For Android testing everything can be configured on a single Windows host. First machine should run Appium, virtual devices and have physical devices connected via USB cable. Second machine should run Rapise and will be used for test recording and execution.
Machine #1 Specification
- Mac OS Catalina 10.15.1
- Node 12.13.0
- npm 6.12.0
- Appium 1.15.1
- Android Studio 3.5.2
- Xcode 11.1
Learn about environment setup here (for Android) and here (for iOS).
We need Android Studio to build Android Native client for Crate. We also need it to configure and run Android Emulators. Android Studio includes Android SDK Tools. Appium needs those tools to connect to Android targets.
Xcode allows us to build iOS Native client for Crate and allows Appium to deal with iOS virtual and physical devices.
Machine #2 Specification
- Windows 10
- Rapise 6.3
Tips and Tricks
While setting up testing environment you may face a number of known obstacles that are easy to resolve. In this section we collected some of them. You may skip this section for now and return later if you hit any of the obstacles.
Getting Android Device Id
To run a test on physical Android device you need to know the unique device id. Plug the device via USB cable, open terminal and run adb devices. The command will print ids of connected devices.
Getting iOS Device Id
To run a test on physical iOS device you need to know its unique device id. Plug the device via USB cable. Launch Xcode and from the main menu choose Window > Devices and Simulators. Copy Id from the Devices tab.
Getting Android Application Binary Path
If you are building the application yourself then in Android Studio choose menu Build > Build Bundles(s)/APK(s) > Build APK(s)
In the right bottom corner click locate link. Android Studio will open the folder with APK.
Drag the file to a terminal window to obtain the full path.
Getting iOS Application Binary Path
Xcode builds into
~/Library/Developer/Xcode/DerivedData
In this folder find your application and locate <your app folder>/Build/Products/<build configuration>/<application name>.app
Drag the file to a terminal window to obtain the full path.
Test is Not Working on Android Device
If you run the test and Appium complains it cannot connect to UIAutomator2 server then try the following steps:
1. Stop Appium server
2. Run adb devices and make sure you see the id of your device in the output
3. Run
adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test
4. Start Appium server
Running Crate Android Native Application on Physical Device
Crate is based on react-native framework. If you build the application with API 29 you may see it is not connecting to the react server when executed on a device. To fix it run the command in the terminal:
adb -s <your device id> reverse tcp:8081 tcp:8081
You will find more details here.
See More
For more tips and tricks please refer to
Test Plan
We are going to create three tests. One for each version of the application.
- Web
- Android Native
- iOS Native
Web Test
First, we record a simple login/logout test using desktop version of Chrome on the machine where Rapise is installed. Then we configure browser profiles for Android and iOS virtual devices as described here. And finally, we execute the test on virtual devices. Appium must be running on machine #1.
Android Native Test
We open Android Studio and use Android Virtual Device (AVD) Manager to launch a virtual device with Android 9 (Pie) operating system.
Then we use Rapise to connect to the emulator and record the test via Rapise Mobile Spy.
Here is the test.
We run it on Android Emulator and physical device attached via USB cable to machine #1.
iOS Native Test
We run iOS Simulator with iOS 11.4 and iPhone X. Using Rapise Mobile Spy we record the test.
Here is the test.
We run the test on iOS Simulator and physical phone attached via USB cable to machine #1.
References
1. Appium
http://appium.io/
2. Rapise
https://www.inflectra.com/Rapise/
3. Preparing for Android Testing
https://rapisedoc.inflectra.com/Manuals/Preparing_for_Android_Testing/
4. Preparing for iOS Testing
https://rapisedoc.inflectra.com/Manuals/Preparing_for_iOS_Testing/
5. How to run a cross-browser test on a mobile device?
https://www.inflectra.com/Support/KnowledgeBase/KB278.aspx
6. How to use specific version of Chromedriver with Appium?
https://www.inflectra.com/Support/KnowledgeBase/KB394.aspx
7. Recording of the Webinar
https://youtu.be/hR4KJ_Yfn2I
8. Recap of the Webinar
http://www.inflectra.com/Ideas/Entry/webinar-recap-automating-mobile-ui-testing-922.aspx
9. Webinar Series: Planet Test Automation — First Steps
https://www.inflectra.com/Ideas/Entry/webinar-series-planet-test-automation-first-steps-897.aspx