Integrate Appium tests with GitHub Actions
Run your Appium tests on BrowserStack App Automate from a GitHub Actions workflow that uploads your app and reads credentials from secrets.
GitHub Actions runs workflows that you define in YAML files in the .github/workflows directory of your repository. You add a workflow that uploads your app to BrowserStack and runs your existing Appium test suite on App Automate. The workflow uses the BrowserStack GitHub Actions to set up environment variables and, if needed, a BrowserStack Local connection.
Prerequisites
Before you begin, ensure that you have the following:
- A GitHub repository that contains your Appium test suite, with GitHub Actions enabled.
- An Android (
.apkor.aab) or iOS (.ipa) app to test. - Your BrowserStack username and access key, available on the Account Settings page.
Integration steps
To integrate your Appium test suite with GitHub Actions, complete the following steps:
Add BrowserStack credentials as GitHub secrets
Store your BrowserStack credentials as encrypted secrets so that they stay out of your code and workflow files.
In your GitHub repository, go to Settings > Secrets and variables > Actions. Click New repository secret and add the following secrets:
-
BROWSERSTACK_USERNAME: Your BrowserStack username -
BROWSERSTACK_ACCESS_KEY: Your BrowserStack access key
For more information, see Using secrets in GitHub Actions.
Configure your tests to read environment variables
In the workflow, the setup-env BrowserStack Action and the app upload step set the following environment variables on the runner:
| Variable | Value |
|---|---|
BROWSERSTACK_USERNAME |
Your BrowserStack username from the BROWSERSTACK_USERNAME secret |
BROWSERSTACK_ACCESS_KEY |
Your BrowserStack access key from the BROWSERSTACK_ACCESS_KEY secret |
BROWSERSTACK_BUILD_NAME |
A build name built from the workflow run details, such as the branch, pull request, and run number |
BROWSERSTACK_PROJECT_NAME |
The name of your repository |
BROWSERSTACK_APP |
The app_url of the uploaded app, in the format bs://<hash>
|
Configure your tests to use these variables:
The BrowserStack SDK reads the environment variables set in the workflow and uses them instead of the matching values in browserstack.yml:
-
BROWSERSTACK_USERNAMEandBROWSERSTACK_ACCESS_KEYreplaceuserNameandaccessKey. -
BROWSERSTACK_BUILD_NAMEandBROWSERSTACK_PROJECT_NAMEreplacebuildNameandprojectName. -
BROWSERSTACK_APPreplacesapp, so the SDK tests the app uploaded in the current run.
Add the BrowserStack SDK to your project’s dependencies so that the install step of the workflow installs it. Then, in the Run Appium tests step of the workflow, replace the test command with the SDK command for your language:
| Language | Command in the Run Appium tests step |
|---|---|
| Java |
mvn test, with the BrowserStack Java SDK added to your pom.xml
|
| Node.js |
npx browserstack-node-sdk <your-test-command>, such as npx browserstack-node-sdk jest
|
| C# |
dotnet test, with the BrowserStack SDK NuGet package added to your test project |
| Python |
browserstack-sdk <your-test-command>, such as browserstack-sdk pytest
|
| Ruby |
bundle exec browserstack-sdk exec <your-test-command>, such as bundle exec browserstack-sdk exec cucumber
|
For PHP, use the non-SDK integration. To set up the SDK for your language and framework, see Integrate your test suite with BrowserStack and How BrowserStack SDK works.
Create the GitHub Actions workflow
Create a workflow file, such as .github/workflows/browserstack.yml, in your repository. Each of the following example workflows installs your project dependencies, sets up the BrowserStack environment variables, uploads your app to BrowserStack, and runs your tests. Select your language to view the example:
In the example workflow, replace <path-to-your-app> with the path to your app file on the runner. If your workflow builds the app, use the path to the build output.
The workflow runs on every push and pull_request event, so each commit maps to a build on App Automate. To run on other events, update the on key. For more information, see Events that trigger workflows.
How the workflow uploads your app
On every run, the upload step uses the REST API to upload your app with the custom ID SampleApp. It then saves the returned app_url as the BROWSERSTACK_APP environment variable for the later steps. A custom ID always refers to the latest app uploaded with that ID. The step uses jq to read the app_url from the response. GitHub-hosted runners include jq. If you use a self-hosted runner, install jq on it.
If your app doesn’t change between runs, upload it once and remove the upload step from the workflow. Then, set app in browserstack.yml to the returned app_url or custom ID. If you don’t use the BrowserStack SDK, add the app_url or custom ID as a BROWSERSTACK_APP variable in the env key of your workflow. To upload an app, see Upload apps from filesystem.
Customize the build and project names
The example uses the BUILD_INFO and REPO_NAME keywords. To set your own values, replace them:
You can combine the BUILD_INFO keyword with your own text, as in the example. For more information, see the setup-env Action repository.
Integrate test cases for apps that access privately hosted servers
If your app accesses servers hosted locally, in a staging environment, or behind a firewall, set up Local Testing so that BrowserStack can reach them through the GitHub Actions runner.
Enable Local Testing in your workflow using one of the following methods:
If you use the BrowserStack SDK, add the following options to your browserstack.yml file. The SDK starts and stops the Local connection on the runner, so you don’t need to add the setup-local Action to your workflow.
You can also set other Local options, such as proxy settings. With the setup-local Action, pass them in the local-args input. For more information, see Test in local environments with Appium.
View test results
After you push a commit or open a pull request, GitHub Actions runs the workflow and your tests run on BrowserStack App Automate.
In your GitHub repository, click Actions and select the workflow run to check whether the test suite passed or failed.
After the workflow completes, view the triggered build on the App Automate dashboard. The build uses the name set in BROWSERSTACK_BUILD_NAME.
Additional references
Use the following pages to set up and manage your Appium tests on BrowserStack:
- Integrate your existing Appium test suite with BrowserStack
- Get started with Appium testing in the language and framework of your choice
- Name and organize your Appium tests
- If the Local binary fails to start, look up the error code from the GitHub Actions workflow log in Local binary error codes.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!