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
- Efficiently testing mobile apps at every stage of the application lifecycle is challenging.
- The Android market is fragmented.
- Many companies are adopting tools to help them create, automate and orchestrate tests on mobile devices.
- Continuous integration and deployment (CI/CD) tools are among these tools.
- Having a CI tool isn’t enough.
- We also need devices to run tests on.
- By partnering with CircleCI, Genymotion provides 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 Genymotion SaaS integration is now available on CircleCI as an Orb.
- QA engineers can easily integrate Genymotion SaaS in their test cases on CircleCI and reuse jobs, commands and executors to run tests on chosen devices.
- In this article, Espresso written tests are covered.
- 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.
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 is 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
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.]