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.
Efficiently testing mobile apps at every stage of the application lifecycle is challenging. Android fragmented market increases the challenge. Many companies adopt tools to help create, automate, and orchestrate tests on mobile devices. Continuous integration and deployment (CI/CD) tools are among the tools. Having a CI tool isn’t enough. Device access is also needed to run tests. By partnering with CircleCI, Genymotion helps provide 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. CircleCI helps teams get faster builds. CircleCI helps teams get shorter feedback lifecycles. CircleCI helps teams simplify pipeline maintenance.
The integration of Genymotion SaaS is available on CircleCI as an Orb. QA engineers can integrate Genymotion SaaS in their test cases on CircleCI. QA engineers can reuse jobs, commands, and executors to run tests on chosen devices.
This article covers Espresso written tests. Other testing frameworks can also be used.
Running tests in parallel with CircleCI requires 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, create the workflow to build the application. Start Genymotion SaaS devices. Run tests. Stop the devices.
Everything is done through a config.yml file in .circleci/ directory in the 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.
Two examples are covered. Start/Stop Genymotion SaaS devices with a single predefined job is one example. Orb commands in your own job is the second example.
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 no ADB serial ports are specified, 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" |
view raw Circleci-genymotion-saas-jobWith this single job, authentication on Genymotion SaaS is included in the genymotion-saas/run_tests step. Start & stop devices steps are included in the genymotion-saas/run_tests step. Only recipe_uuid is required. adb_serial_port is optional. adb_serial_port needs to be directly used in the workflow.
Running tests after a commit
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).
| | 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" |
view raw Circleci-genymotion-saas-jobTo 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 |
view raw CircleCi-Start-Android9-instanceRun 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 |
view raw CircleCi-run-android-expresso-testsResults 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.
| | 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: "70eaaf75-bd9a-406d-9f01-682a5d400c6e" | | | - run:./gradlew connectedDebugAndroidTest | | | - genymotion-saas/stop-instance | | | | | | workflows: | | | version: 2 | | | build_and_test: | | | jobs: | | | - android9 | | | - android10 |
view raw Circleci_several_android_buildswhere 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.
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.
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. The orb repository is available at open-source. You can create an issue. You can 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!