Configuring and Running Tests with Maestro in GitHub Actions
Maestro, a mobile UI automation framework, provides a simple way to automate mobile apps. Integrating Maestro with GitHub Actions ensures automated tests are run as part of your CI/CD workflow. In this article, we will walk through configuring a GitHub Actions workflow using the provided YAML file.
Setting Up the Workflow File
Below is the GitHub Actions workflow file. Save it as .github/workflows/maestro-version-check.yml
in your repository.
name: Maestro Version Check
on:
push:
branches:
- main
workflow_dispatch:
jobs:
maestro-version-check:
runs-on: ubuntu-latest
container:
image: alpine:latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install Dependencies
run: |
apk add --no-cache openjdk8 curl bash zip
echo "Dependencies installed successfully."
- name: Download and Install Maestro
run: |
echo "Downloading Maestro..."
curl -L https://get.maestro.mobile.dev -o install_maestro.sh
chmod +x install_maestro.sh
./install_maestro.sh || (echo "Failed to install Maestro" && exit 1)
- name: Add Maestro to PATH
run: |
export PATH="$PATH:$HOME/.maestro/bin"
echo "PATH updated to include Maestro: $PATH"
- name: Verify Maestro Installation and List Files
env:
MAESTRO_API_KEY: ${{ secrets.MAESTRO_API_KEY_SECRETS }}
run: |
export PATH="$PATH:$HOME/.maestro/bin"
maestro --version
ls
maestro cloud --apiKey ${{ secrets.MAESTRO_API_KEY_SECRETS }} .maestro/app-release.apk .maestro/android.yaml
Breaking Down the Workflow
Triggers
push
: Runs the workflow when changes are pushed to themain
branch.workflow_dispatch
: Allows manual triggering of the workflow.
Job Details
maestro-version-check
Job:
- Runs-on: Specifies the environment (
ubuntu-latest
) with an Alpine container for lightweight dependency management. - Steps:
- Checkout Repository: Uses the
actions/checkout
action to clone the repository. - Install Dependencies: Installs
openjdk8
,curl
,bash
, andzip
using the Alpine package manager. - Download and Install Maestro: Downloads Maestro using a shell script and installs it. If the installation fails, the workflow exits with an error.
- Add Maestro to PATH: Updates the
PATH
environment variable to include the Maestro binary location. - Verify Installation and Execute Tests:
- Checks the installed Maestro version.
- Lists files in the current directory.
- Runs Maestro tests in the cloud using the
cloud
command. The API key and file paths (.maestro/app-release.apk
and.maestro/android.yaml
) are specified.
Configuring Secrets
To securely provide your MAESTRO_API_KEY
, configure it in your repository’s settings:
- Go to your GitHub repository.
- Navigate to Settings > Secrets and variables > Actions.
- Click New repository secret.
- Add the secret:
- Name:
MAESTRO_API_KEY_SECRETS
- Value: Your Maestro API key.
File Structure
Ensure the following files are available in your repository:
.maestro/app-release.apk
: The APK file for your app..maestro/android.yaml
: The Maestro configuration file for your tests.
Running the Workflow
- Automatically: Push changes to the
main
branch. - Manually: Trigger it from the Actions tab on GitHub.
Verifying the Output
Check the workflow logs to verify:
- Maestro installation success.
- The correct version of Maestro is installed.
- The tests run successfully using the specified APK and YAML file.
Conclusion
This GitHub Actions setup ensures your Maestro tests are seamlessly integrated into your development workflow, offering automated test execution for mobile apps. By leveraging cloud capabilities, you can execute tests on remote devices, ensuring consistent and reliable results.
I have created a project on Github and added the code here.
Here is the test execution link on Github actions here.
Feel free to hit clap if you like the content. Happy Automation Testing :) Cheers. 👏