Mobile Automated Tests with CircleCI and Genymotion SaaS

CircleCI & Genymotion SaaS integration illustration.

Note

The following article is a reproduction of Run your mobile automated tests on Genymotion Cloud Android Virtual Devices with CircleCI authored and authorized by Ellinor Kwok.

Efficiently testing mobile apps at every stage of the application lifecycle is challenging, even more with Android fragmented market. Many companies are adopting tools to help them create, automate and orchestrate tests on mobile devices. Among them are continuous integration and deployment (CI/CD) tools. Having a CI tool isn’t enough, we also need devices to run tests on. By partnering with CircleCI, we help providing the full continuous integration workflow.

Genymotion SaaS (Cloud) provides Android virtual devices on the Cloud with various configurations and Android versions. CircleCI is a cloud continuous integration server to help teams get faster builds, shorter feedback lifecycles and simplified pipeline maintenance.

The integration of Genymotion SaaS is now available on CircleCI as an Orb, so QA engineers can now easily integrate Genymotion SaaS in their test cases on CircleCI and reuse jobs, commands and executors to run their test on chosen devices.

In this article, we are going to cover Espresso written tests but you can also use any other testing framework.

To run tests in parallel with CircleCI i.e running your tests on several devices at the same time, you also need to have a CircleCI plan that supports more than one job at a time.

1. Create your test workflow with config.yml file

Before setting up your Android project on CircleCI, let’s create the workflow to build the application, start Genymotion SaaS devices, run the tests and stop the devices.
For this, everything is done through a config.yml file in .circleci/ directory in your project root directory.

Genymotion SaaS Cloud account credentials need to be set as environment variables:

  • GMCLOUD_SAAS_EMAIL : it is the email of your Cloud account; if you don’t have an account, please create it first on https://cloud.geny.io.
  • GMCLOUD_SAAS_PASSWORD : it is the password for your Cloud account.

We will cover two examples: Start/Stop Genymotion SaaS devices with a single predefined job, or with orb commands in your own job.

Start & Stop Genymotion SaaS devices

Several parameters are used :

recipe_uuid : Recipe UUID is the identifier used when starting an instance, it can be retrieved using gmsaas recipes list command line. The comprehensive list of all currently available recipes UUIDs are available here.

adb_serial_port : it is the port through which the instance will be connected to ADB, for example: localhost:adb_serial_port.

If you do not specify any ADB serial ports, it will be generated randomly.

Use the job defined with the orb

With this single job, authentication on Genymotion SaaS, start & stop devices steps are included in the genymotion-saas/run_testsstep. Only the recipe_uuid is required, adb_serial_port is optional. It needs to be directly used in the workflow.

CircleCI dashboard: running tests after a commit.
Running tests after a commit
Circle CI dashboard after running genymotion-saas-orb job successfully.
All steps are done with genymotion-saas-orb job

Use orb commands in your own job

To start a device (adb_serial_port is optional)

To stop a device after running the tests, replace genymotion-saas/start-instance with genymotion-saas/stop-instance.

So a job that runs tests on an Android 9 devices will look like:

Run the tests

The tests are run between start & stop instance steps. To run espresso tests, we use the connectedDebugAndroidTest gradle command:

CircleCI dashboard after running a successful test.
Results after a successful test

Scale your tests by running your tests in parallel

Each genymotion-saas/start-instance step starts one Android virtual device. To start several devices you need to define as many jobs as many devices you wish to start.

where android9, android10 are jobs with genymotion-saas/start-instance steps that start respectively an Android 9 & Android 10 devices. To start these devices in parallel, you need to have subscribed to the CircleCI plan that enables more than one job to run in parallel.

CircleCI dashboard when running tests in parallel.
Running tests in parallel

2. Get running on CircleCI

You are now all setup to run your tests on Genymotion SaaS virtual devices. Please refer to the official documentation on how to setup your project to run on CircleCI.

Conclusion

At the end of this tutorial, you should be able to create a Continuous Integration workflow for your application to run your tests at scale.

Genymotion SaaS (Cloud) orb is open-source, so feel free to create an issue or contribute.

The Android application code sample and the config.yml file used in this tutorial is available on Github

Enjoy running your automated tests on Genymotion SaaS from CircleCI!

Thanks to the CircleCI team (special thanks to Kyle Tryon) for all their help!

Table of Contents

Select Product Portal

SaaS Platform

Access to our SaaS solution and use virtual machines in the cloud on any web browsers.

Or

Or

Desktop Platform

Access to manage your Genymotion Desktop licenses, your invoices and account information.

Select a Cloud provider Marketplace

How to get a quote for multiple Business Licenses?

  1. You need a Genymotion Desktop account. If you haven’t one yet, you can create it here.
  2. After creation and activation, or if you already have an account, follow this link.
  3. Add the number of desired licenses to your shopping cart and click “Continue to Billing”
  4. Add a shipping address, or select one if you already created one.
  5.  In the next page, click “Get a quote”:
    Payment details
  6. A quote will be automatically generated in PDF format.

Genymotion Device Image for Cloud providers
- Private Offer -

Genymotion Device On-premise
- Contact Us -

Genymotion SaaS
- Increase Maximum Simultaneous devices -

Genymotion SaaS Enterprise Plan
- Get a Quote -

Genymotion SaaS Premium Plan
- Get a Quote -

Personal Use - Free

Genymotion Desktop for personal use is not suitable for trial or POC: you will not get any assistance and some features will be disabled. If you have already selected “personal use” and wish to get a trial license, please contact our Sales at [email protected].

Technical support is not available with Genymotion Desktop free edition for personal use. For more details, please refer to Genymotion conditions of use (Personal Use).

The following features are not available in personal use mode:

Follow these steps to get Genymotion Desktop and activate personal use mode:

  1. Go to the Download page and get the latest version for your system.
  2. Follow the instructions from Genymotion Desktop quickstart guide to install Genymotion Desktop.
  3. Launch Genymotion and click CREATE to create an account. You should receive an activation email within an hour. If not, make sure to check your spam.
  4. After activating your account, return to Genymotion and log in with your credentials.
  5. Select personal use when prompted.
  6. Read Genymotion Desktop quickstart guide carefully to setup Genymotion for your needs.

Indie Plan Application Form

This plan is strictly reserved to individual workers (freelancers, self-employed).

Educational Plan Application Form

The Educational plan is restricted to:

  • schools, teachers or students who wish to use Genymotion Desktop for tuition
  • students who wish to use Genymotion Desktop for a school project

It is subject to valid proof (student card, teacher card, etc.)