Mobile Automated Tests with CircleCI and Genymotion SaaS

2024-04-23

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.

Audience This article is intended for QA engineers and developers who use CircleCI and Genymotion SaaS.

Introduction

Start & Stop Genymotion SaaS devices

Several parameters are used:

version: 2.1
orbs:
  genymotion-saas: genymotion/genymotion-saas@1.0.0
workflows:
  basic_workflow:
    jobs:
      - genymotion-saas/run_tests:
          name: "Run Android 9.0"
          recipe_uuid: 'd8b10016-c02a-41f9-8a91-ce9b44197d21'
          steps:
            - run: echo "run your test here"
      - genymotion-saas/run_tests:
          name: "Run Android 10.0"
          recipe_uuid: '4c015ada-e64e-4f5d-a320-06cbf6e95648'
          adb_serial_port: 12345
          steps:
            - run: echo "run your test here"

version: 2.1
orbs:
  genymotion-saas: genymotion/genymotion-saas@1.0.0
workflows:
  basic_workflow:
    jobs:
      - genymotion-saas/run_tests:
          name: "Run Android 9.0"
          recipe_uuid: 'd8b10016-c02a-41f9-8a91-ce9b44197d21'
          steps:
            - run: echo "run your test here"
      - genymotion-saas/run_tests:
          name: "Run Android 10.0"
          recipe_uuid: '4c015ada-e64e-4f5d-a320-06cbf6e95648'
          adb_serial_port: 12345
          steps:
            - run: echo "run your test here"

version: 2.1
orbs:
  genymotion-saas: genymotion/genymotion-saas@1.0.0
workflows:
  build_and_test:
    jobs:
      - android9
      - android10

Start & Stop Genymotion SaaS devices (in Orb usage) To start a device (adb_serial_port is optional) use the orb step genymotion-saas/start-instance. 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:

jobs:
  android9:
    executor: genymotion-saas/default
    steps:
      - checkout
      - genymotion-saas/setup
      - genymotion-saas/start-instance:
          recipe_uuid: "e20da1a3-313c-434a-9d43-7268b12fee08"
      - genymotion-saas/stop-instance

jobs:
  android9:
    executor: genymotion-saas/default
    steps:
      - checkout
      - genymotion-saas/setup
      - genymotion-saas/start-instance:
          recipe_uuid: "e20da1a3-313c-434a-9d43-7268b12fee08"
      - run: ./gradlew connectedDebugAndroidTest
      - genymotion-saas/stop-instance

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

jobs:
  android9:
    executor: genymotion-saas/default
    steps:
      - checkout
      - genymotion-saas/setup
      - genymotion-saas/start-instance:
          recipe_uuid: "e20da1a3-313c-434a-9d43-7268b12fee08"
      - run: ./gradlew connectedDebugAndroidTest
      - genymotion-saas/stop-instance

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 there are devices you wish to start.

version: 2.1
orbs:
  genymotion-saas: genymotion/genymotion-saas@1.0.0
jobs:
  android9:
    executor: genymotion-saas/default
    steps:
      - checkout
      - genymotion-saas/setup
      - genymotion-saas/start-instance:
          recipe_uuid: "e20da1a3-313c-434a-9d43-7268b12fee08"
      - run: ./gradlew connectedDebugAndroidTest
      - genymotion-saas/stop-instance
  android10:
    executor: genymotion-saas/default
    steps:
      - checkout
      - genymotion-saas/setup
      - genymotion-saas/start-instance:
          recipe_uuid: "70eaf75-bd9a-406d-9f01-682a5d400c6e"
      - run: ./gradlew connectedDebugAndroidTest
      - genymotion-saas/stop-instance
workflows:
  build_and_test:
    jobs:
      - android9
      - android10

Running tests in parallel To run tests in parallel, define multiple androidN jobs as shown above. Each job starts its own Android device. To run devices in parallel, you must subscribe to a CircleCI plan that enables more than one job to run concurrently.

2. Get running on CircleCI You are now all set up to run your tests on Genymotion SaaS virtual devices. Please refer to the official documentation on how to set up 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!

``` [End of Markdown content, navigation elements omitted per instructions.]