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.

quote

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.

TestFairy-Espresso-Config

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.

1
apiVersion: v1alpha
2
kind: espresso
3
sauce:
4
region: us-west-1
5
# Controls how many suites are executed at the same time (sauce test env only).
6
concurrency:2
7
metadata:
8
name:Testing My Demo App Androidwith espresso
9
tags:
10
- e2e
11
-freeing team
12
- other tag
13
build:Release $ CI_COMMIT_SHORT_SHA
14
espresso:
15
app:./app/build/outputs/apk/debug/app-debug.apk
16
testApp:./app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
17
suites:
18
- name:& quot; Main rooms & quot;
19
devices:
20
- name:& quot; Google Pixel 3a & quot;
21
platformVersion:11
22
-id:Google_Pixel_3a_real
23
# Controls what artifacts to fetch when the suite on Sauce Cloud has finished.
24
artifacts:
25
download:
26
when: always
27
match:
28
- junit.xml
29
directory:./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.

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).

1
name:Testwith saucectl
2
on:[push]
3
env:
4
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}
5
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}
6
jobs:
7
main:
8
timeout-minutes:20
9
runs-on: ubuntu-latest
10
steps:
11
- name:Checkout
12
uses: actions/checkout @ v2
13
- name:SetupJava
14
uses: actions/setup-java@v1
15
with:
16
java-version:11
17
- name:SetupAndroidSDK
18
uses: android-actions/setup-android @ v2
19
- name:Compile
20
run:|
21
./gradlew app:assembleDebug
22
./gradlew app:assembleDebugAndroidTest
23
shell: bash
24
- name:Test espresso with saucectl
25
uses: saucelabs/saucectl-run-action@v1
26
with:
27
testing-environment:& quot; & quot;
28
concurrency:10
29

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.

Diego Perini

Sr. Software Engineer

Published:
Apr 7, 2023
Share this post
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all right reserve. SAUCE and SAUCE LABS are registered trademark owned by Sauce Labs Inc. in the United States, EU, and may be registered in early jurisdictions.
robot
quote

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 Free

Test 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