2024-04-23
> Note: This article is a reproduction of a medium article: Learn how to integrate Genymotion Cloud Android Virtual Devices into your workflows and use the testing framework of your choice on Bitrise. by Thomas Carpentier.
Mobile DevOps encourages the use of multiple mobile devices in the Cloud to tackle the challenge of performing quick and efficient tests in a highly Android dominant fragmented mobile market.
Genymotion SaaS (Cloud) enables QA engineers to spawn many Android virtual devices in the Cloud in parallel and test at scale. Bitrise is a Continuous Integration & Delivery platform dedicated to mobile apps.Bitrise uses a powerful UI to create workflows easily.
Bitrise workflows can build, test, and deploy an app.
Genymotion SaaS is now available on Bitrise.
QA engineers can choose Genymotion SaaS Android virtual devices to run tests on them using any testing framework.
The page lists Espresso and Appium as examples of supported testing frameworks.
The page states that there is no need to learn how to use the Genymotion SaaS command-line tool to automate the start/stop of the devices.
The start/stop automation can be handled in the UI.
This article covers Appium written tests.
Connect your Android project to Bitrise
Adding an application to Bitrise is simple.
The page directs readers to the official documentation for details.
After connecting an Android application to bitrise.io, a workflow is created with several default Android steps.
The following screenshot shows the default workflow.
Build an Android application
To run Appium tests, build an Android application.
Add the “Android build” step to the workflow.
When the “Android build” step executes, the APK path is pushed to an environment variable ($BITRISE_APK_PATH).
The workflow uses $BITRISE_APK_PATH later when running the tests.
Install and start an Appium server
Use the “Script” step to install and start an Appium server.
The page states that the “Script” step is a Bash script.
The “Script” step starts an Appium server with the needed capabilities.
The “Script” step arguments are described here.
Add Genymotion SaaS start instances step
This step starts one or several devices on the Genymotion SaaS platform.
This step has several required parameters.
- Genymotion SaaS account ).
- Genymotion SaaS password (required): the password for the Genymotion SaaS account.
- Recipe UUID (required): the identifier used when starting an instance.
- Recipe UUID can be retrieved using the gmsaas recipes list command line.
- The comprehensive list of all currently available recipes UUIDs is available here.
- ADB serial port (optional): the port through which the instance will be connected to ADB, for example:
localhost:adb_serial_port.
Run tests
This tutorial uses an Android application with Appium tests written in Python.
The source code is public and available on Github.
Even if a different language is used, the logic is the same.
The workflow adds another “Script” step.
The “Script” step installs all dependencies.
The “Script” step starts the command executing tests.
The workflow uses the environment variable $BITRISE_APK_PATH which was exported in the Android build step.
The following script is used to install and start the Appium server.
| | #!/usr/bin/env bash | | --- | --- | | | # fail if any commands fails | | | set -e | | | # debug log | | | set -x | | | | | | #export JAVA_HOME | | | export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 | | | export PATH=$PATH:$JAVA_HOME/bin | | | | | | npm install -g appium --unsafe-perm=true --allow-root | | | | | | appium &>/dev/null & |
view raw Start Appium serverThe following script is used to run tests.
| | #! /usr/bin/env bash | | --- | --- | | | # fail if any commands fails | | | set -e | | | | | | # debug log | | | set -x | | | | | | | echo " # Install dependencies " | | | pip3 install -r appium/requirements.txt | | | | | | # Execute tests through pytest | | | echo " # Execute tests " | | | pytest -n 2 appium/test_send_message.py --apk $BITRISE_APK_PATH |
view raw run-tests.shAdd Genymotion SaaS stop instances step
This step stops all Genymotion SaaS instances started in the “start” step.
This step always runs to make sure that no instances are left running in case a previous step fails the build.
No need to change the input variable “Instance UUID”.
The page states that “Instance UUID” is automatically exported in the “start” step.
Conclusion
At the end of this tutorial, a complete Continuous Integration workflow for an application should be possible.
The workflow includes unit and UI testing.
The page suggests improving the workflow by adding other steps in order to deliver the application.
More information is available here.
If any questions exist, the page says to submit a request from the Genymotion SaaS platform.
For more information, the page directs readers to documentation.
Genymotion SaaS steps are open-source.
The page says to feel free to create an issue or contribute.
https://github.com/Genymobile/bitrise-step-genymotion-cloud-saas-start https://github.com/Genymobile/bitrise-step-genymotion-cloud-saas-stopThe Android application code sample used in this tutorial is available on Github.
Enjoy a Bitrise CI/CD workflow with Genymotion SaaS.