Running Android Espresso UI Tests in Parallel with Quantum on Perfecto Cloud

If you're an Android developer, you're probably familiar with Google's Espresso UI test automation framework. Espresso is more lightweight compared to UIAutomator and it’s newer. It supports 2.2 Froyo and up, and it’s also a fluent API with powerful hamcrest (https://github.com/hamcrest) integration that helps make code more readable and extensible.

Espresso is useful for Hybrid app testing, or webview heavy testing, but it does not have access to system integration tests, therefore, it is recommended on developer.android.com for the “Testing UI for a single App” test.

The Espresso testing framework is an instrumentation-based API and works with the AndroidJUnitRunner test runner. Using Espresso 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 while Appium has multiple layers.

Now, instead of running Espresso 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 Espresso 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, and 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 Espresso UI Tests on multiple devices in parallel by using an open-source Quantum project.

First step- Compile and Build Android APK Files For Espresso UI Tests.

- 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, and once created, the Espresso UI test script, then I build the APK files as shown below by using a command line:

  •    In terminal, type $>gradle assembleAndroidTest assembleDebug

  •   Which gradle compile and build 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.

Second step- Set Up and Use the Quantum Starter-Kit Project

- 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 things you need to do is make edits to the application.properties file under the resources folder, and 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)

  • Right-click on the steps folder -> New -> File, and then enter a filename and save it as EspressoStepsDefs.java
  • Then add the following code as shown below:
  • Make sure you are referencing to the proper APK files that you had created from the above instructions.

Now, we need to create a scenario file and place it under the scenario folder (src/main/resources/scenarios)

  • Right-click on the scenarios folder -> New -> File, and then enter a filename and save it as espresso.feature
  • Then add the following code as shown below:

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 be setting up to run three different Android devices and enabling 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, however, 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, and each of my test suite names are unique. (i.e., Android Simple Notes Espresso Test1)

The final step- Get Espresso UI Tests Running on Multiple Devices and In Parallel

- Right-click on testng_EspressoDemo.xml file -> and select “Run…” from menu item

To view which devices are running espresso UI tests

  • Click on Perfecto Dashboard pane and it will shows devices testing in progress.

SUMMARY

While using Android Studio to build and run the Espresso UI test script in a single device mode, if you would like to increase your testing coverage by running on different Android devices and OS versions in parallel to increase testing velocity, 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 UI Testing framework 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, check out my latest video:

Good luck!

Tags:

Share Your Thoughts!

Your email address will not be published. Required fields are marked *

Love to learn about creating top notch digital experiences?

Get the latest news, tips and articles delivered right to your inbox.