View all web browser and mobile devices available in our cloud-based test lab.
It's important to get Android UI testing right. Here we cover Android UI automation and how to achieve it.
Espresso is Google's Android UI test automation framework. It's more lightweight compared to UIAutomator and it’s newer. It supports 2.2 Froyo and up, and it’s also a fluent API with a powerful hamcrest integration that helps make code more readable and extensible.
Espresso is useful for hybrid app testing or web-view heavy testing. But it does not have access to system integration tests. You should use it for "Testing UI for a Single App."
Espresso is an instrumentation-based API and works with the AndroidJUnitRunner test runner. Using it benefits the client because it bundles the tests on the client’s actual device. The advantage here is that it runs on the device, which runs faster, reduces network traffic, and has control over the classes and controller. (Appium has multiple layers.)
Now, instead of running tests on a single device at a time, you can run the test on multiple Android devices and in parallel with Quantum Framework on Perfecto Cloud devices.
Before I describe how easily you can set up to run tests on multiple devices and in parallel, let me explain about the Quantum Automation Framework (QAF).
QAF is an open-source test automation framework for web and mobile test authoring, execution and analysis. The framework enables ease of environment set-up to access the Perfecto Cloud Lab with user authentication and driver management. It allows you to create a test script in behavior-driven development (BDD) for easy-to-use English phrased steps. It will generate Perfecto DigitalZoom reporting of the test execution for quick analysis and drill down to the root cause of failure. The QAF Starter-Kit is available on GitHub.
The following describes a high-level step of how you can run the Android UI Tests on multiple devices in parallel by using Quantum, Perfecto's open-source BDD testing framework.
With Android Studio, you would need to create the Espresso UI Test Script and validate it. It can be run from the Android Studio IDE
Then build the two APK files, which will be “Tested Application File” and “Espresso Test File."
For my example, I have a project called SimpleNotesEspresso. After creating the Android UI test script, then I build the APK files as shown below by using a command line:
In terminal, type $>gradleassembleAndroidTestassembleDebug.
This compiles and builds the two APK files (app-mock-debug.apk and app-mock-debug-androidTest.apk )
Once the APK files are build, then the next step is to upload these files onto your Perfecto-hosted cloud lab repository.
Download and install QAF start project from GitLab
I am using IntelliJ Community Edition as my IDE for the Quantum Project. And I have installed Perfecto Continuous Quality Lab plugin for my IDE tool to access cloud devices.
Once installation is completed, the first thing you need to do is make edits to the application.properties file under the resources folder. And then make changes to the user credential information and hosted-cloud domain name, as shown:
Next, you will need to create a custom steps file, and place it under the steps folder (src/main/java/com.quantum/steps )
Now, we need to create a scenario file and place it under the scenario folder (src/main/resources/scenarios).
Finally, we need to create a TestNG configuration file to allow us to run the test script on multiple devices in parallel. Therefore, we need to create this file and place it under the config folder (src/main/resources/config).
Right-click on the config folder -> New -> File, and then enter a filename and save it as testng_espressoDemo.xml (or whatever name make sense).
Alternatively, you can just copy the testng_appium.xml file and then make edits to fit your devices’ needs.
In the example shown below, I will set it up to run three different Android devices and enable them to run in parallel. Notice, the device selection is set using a wildcard that indicates to select any available Android Galaxy S-type phone on the CQ Lab. But if you want to select a specific device then you would need to change the parameter capabilities from using a "model" to "deviceName" and set the device value to a specific Unique Device Identifier (UDID) number.
As shown on the image below, I will be using the wildcard for Galaxy ‘S’ phones. Each of my test suite names are unique. (i.e., Android Simple Notes Espresso Test1).
Right-click on testng_EspressoDemo.xml file -> and select “Run…” from menu item
To view which devices are running Android UI tests:
If you want increase your test coverage by running on different Android devices and OS versions in parallel to increase testing velocity, you'll need to add automation to Android UI testing. I would recommend using the Quantum starter-kit project. It has all the open-source components to help increase device test coverage and speed up testing velocity.
With that said, it means that you are using both Espresso framework for Android UI testing in combination with a TestNG testing framework build in a Quantum project for easily getting multiple devices running in parallel. To see how I implement end-to-end workflow of Espresso with Quantum, watch the video below.
Perfecto integrates with Espresso to automate Android UI testing.
With Perfecto, you'll get Android UI automation and:
See for yourself how Perfecto can help you. Get started with a free 14-day trial.
Try Perfecto For AndroiD UI TESTING