How to Run Espresso Tests on CI with Real Mobile Devices
Sauce AI for Test Authoring: Move from design to performance in min.|xBack to ResourcesBlogPosted April 7, 2023
How to Run Espresso Tests on CI with Real Mobile Devices
Learn how to achieve confidence for our SDK with the help of Sauce Labs RDC and GitHub Actions.
Here is a crazy idea: let ’ s improve git push to create our CI run Espresso tests on a existent device, powered by (RDC). That ’ s flop. Every time we have a modification in our app code, a real Google Pixel phone will launch our trial entourage and show us the results, all without leave the consolation of our GitHub repo. This is how we test our mobile SDKs, and it is how you should try your app too!
Ingredients
Where is the phone?
Sauce Labs information centre host a huge number of existent mobile devices, accessible by developers to ensure their apps can confidently run across. You can harness Real Device Cloud device with of your choice.
As of 2021, Google Play shows there are at least 15,000 different Android device models citizenry use all around the world. We can ’ t merely buy all of those device and trial TestFairy SDK in each one of them. It is not a race we can e'er hope to win without the help of a robust service. If we want to be convinced that TestFairy SDK will run without bugs on any device, going cloud is our good shot. Below, you will find the exact codification for how we achieve assurance for our SDK with the aid of Sauce Labs RDC and GitHub Actions.
Steps
Let ’ s start with configuring our repo for saucectl. It is the tool we use under the thug to get admission to RDC. saucectl cli takes a look at our current directory (i.e., in CI) to determine what form of tests to run, on which device with the criteria we define.
Create a new folder named “ .sauce ” in the project root and put a configuration file named “ config.yml ” in it.

We will need to define the following items: essay framework, data eye region, app paths, real phone specification.
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
1apiVersion: v1alpha2kind: espresso3sauce:4region: us-west-15# Controls how many suites are executed at the same time (sauce test env only).6concurrency:27metadata:8name:Testing My Demo App Androidwith espresso9tags:10- e2e11-freeing team12- other tag13build:Release $ CI_COMMIT_SHORT_SHA14espresso:15app:./app/build/outputs/apk/debug/app-debug.apk16testApp:./app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk17suites:18- name:& quot; Main rooms & quot;19devices:20- name:& quot; Google Pixel 3a & quot;21platformVersion:1122-id:Google_Pixel_3a_real23# Controls what artifacts to fetch when the suite on Sauce Cloud has finished.24artifacts:25download:26when: always27match:28- junit.xml29directory:./artifacts/
Once you finish, you can execute saucectl run topically and see your test results on your Sauce Labs dashboard in real time.
This is already really cool but we want to do more. Let ’ s use GitHub Actions to run these tests, so that every time a developer makes an update to our repo, the tests are mechanically fulfil.
Our GitHub repo doesn ’ t cognise that we use Sauce Labs yet, so let ’ s add that.
Navigate to your project secrets:https: //github.com/MY_ORGANIZATION/MY_APP/settings/secrets/actions
Add a repository secret name SAUCE_USERNAME and enroll your saucelabs.com username in it.
Similarly, add another deposit secret named SAUCE_ACCESS_KEY and paste your in it.
Now that our repo cognise about our Sauce credentials, we can connect to RDC inside all of our GitHub workflows. For a canonical “ test on push ” scenario, we define the following workflow file (.github/workflows/test-with-saucectl.yml).
1name:Testwith saucectl2on:[push]3env:4SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}5SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}6jobs:7main:8timeout-minutes:209runs-on: ubuntu-latest10steps:11- name:Checkout12uses: actions/checkout @ v213- name:SetupJava14uses: actions/setup-java@v115with:16java-version:1117- name:SetupAndroidSDK18uses: android-actions/setup-android @ v219- name:Compile20run:|21./gradlew app:assembleDebug22./gradlew app:assembleDebugAndroidTest23shell: bash24- name:Test espresso with saucectl25uses: saucelabs/saucectl-run-action@v126with:27testing-environment:& quot; & quot;28concurrency:1029
Finally, we commit our modification and energy.
Once our changes are merged to the primary ramification for the first time, GitHub will be capable to start schedule action whenever a new contribution arrives.
Try it now!
If you ’ d like to see this in action right now, just fork our on GitHub and update your repo secrets.
This spot was originally published on October 27, 2021 and has been update in April 2023.
Sr. Software Engineer
Share this post
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free