Skip to main content

How to Run a Test on a Real Mobile Device

Your users run your app on real phones, not on emulators. Here is how to run a first test on a real Android phone and a real iPhone on Sauce Labs, with Appium, Mobilewright, Espresso and XCUITest.

Beginnerremote4 tools

How to Run a Test on a Real Mobile Device

Intro​

Your users run your app on real phones: many brands and models, different OS versions, screen sizes, and the manufacturers' own changes to Android. Emulators and simulators are great while you write the app, but they don't show how it behaves on the phones your users have. Buying and maintaining a shelf of phones to test on is slow and costly.

A Solution​

Run your tests on real devices in the cloud. Sauce Labs has a cloud of real Android phones and iPhones. Your test asks for a device (e.g., any Google Pixel, or any iPhone), Sauce Labs installs your app on it, and the test drives the app, as it would on a phone on your desk. Each test run records a video, screenshots and the device logs.

Every example here uses Sauce Labs' demo app ("My Demo App", for Android and iOS), a small shop app. The test opens the app and checks that the catalog shows the Sauce Labs Backpack. Sauce Labs downloads the app from its GitHub release, so you don't need to build or upload anything to try it.

There are two kinds of mobile test tools:

  • Appium and Mobilewright drive the app from outside, like a user would. One test can run on Android and iOS, and you can write it in many languages. The test runs on your machine and talks to the device over the network.
  • Espresso (Android) and XCUITest (iOS) are the test frameworks from Google and Apple. The tests are written in the language of the app (Kotlin and Swift), built into a test app, and run on the device itself. Sauce Labs' saucectl uploads the app and the tests and starts the run.

Example​

NOTE: You'll need an account to use Sauce Labs. You can sign up for a free trial account (no credit-card required).

Export your Sauce Labs username and access key as the environment variables SAUCE_USERNAME and SAUCE_ACCESS_KEY, instead of hard-coding them in your tests. If they are not set, the tests are skipped.

The examples use the us-west-1 data center. Each one asks for a device by a pattern of its name (e.g., Google.* or iPhone.*), so any free device that matches can run the test.

Expected Behavior​

  • Sauce Labs finds a free real device that matches the test (an Android phone, an iPhone, or both)
  • It installs the demo app (and, for Espresso and XCUITest, the tests)
  • The test opens the app and checks that the catalog shows the Sauce Labs Backpack
  • The session ends, and the results (with a video, screenshots and the device logs) are available on the test results dashboard

Summary​

With a test running on a real device, you can check your app on the phones your users have, without keeping any of them on your desk. The next tips build on this one: installing your own app, finding elements, waiting for them, and answering permission pop-ups.

Happy Testing!

Authors​

Last updated on by Diego Molina
Next tipAccessing Previous Tips ArchiveRead next