Date: 2024-04-23
Note
This article is a reproduction of a Medium article.
The article title is “Learn how to integrate Genymotion Cloud Android Virtual Devices into your workflows and use the testing framework of your choice on Bitrise.”
The author is Thomas Carpentier.
Connect your Android project to Bitrise
- Adding an application to Bitrise is simple.
- Please refer to the official documentation for details.
- After connecting an Android application to bitrise.io, a workflow is created with several default Android steps.
- The default workflow is shown in the following screenshot. (Note: images are not reproduced here.)
Build an Android application
- The Android build step builds the Android application.
- To run Appium tests, the workflow must include the Android build step.
- When the Android build step is executed, the APK path is pushed to an environment variable named $BITRISE_APK_PATH.
- The APK path will be used later when tests are run.
Install and start an Appium server
- A Script step is used to install and start an Appium server.
- The Script step is a Bash script.
- The Bash script starts an Appium server with the needed capabilities.
- The arguments for the Appium server 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 email (required): It is the email of your Genymotion SaaS account. If you do not have an account, please create it first on https://cloud.geny.io.
- Genymotion SaaS password (required): It is the password for your Genymotion SaaS account.
- Recipe UUID (required): Recipe UUID is the identifier used when starting an instance. It can be retrieved using gmsaas recipes list on the command line. The comprehensive list of all currently available recipes UUIDs is available here.
- ADB serial port (optional): It is the port through which the instance will be connected to ADB, for example: localhost:adb_serial_port.
Run tests
- In this tutorial, the Android application is tested with Appium tests written in Python.
- Source code is public and available on Github.
- Even if a different language is used, the logic remains the same.
#!/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 server
hosted with
by
GitHub
- Here, another Script step is added which:
- Installs all dependencies
- Starts the command executing tests
- Uses the environment variable $BITRISE_APK_PATH, exported in the Android build step
#!/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.sh
hosted with
by
GitHub
Add Genymotion SaaS stop instances step
- This step stops all Genymotion SaaS instances started in the “start” step.
- This step always runs to ensure that no instances remain running if a previous step fails the build.
- No need to change the input variable “Instance UUID”; it is automatically exported in the “start” step.
Conclusion
- At the end of this tutorial, you should be able to create a complete Continuous Integration workflow for your application, including unit and UI testing.
- You can improve the workflow by adding other steps in order to deliver the application, but this is another story. You can find more information here.
- Genymotion SaaS steps are open-source. You can create an issue or contribute at:
- https://github.com/Genymobile/bitrise-step-genymotion-cloud-saas-start
- https://github.com/Genymobile/bitrise-step-genymotion-cloud-saas-stop
- The Android application code sample used in this tutorial is available on Github.
- Last but not least, enjoy your Bitrise CI/CD workflow with Genymotion SaaS!