Skip to main content

Appium Testing with Emulators and Simulators

With Sauce Labs, you can run automated Appium tests for your native and hybrid mobile apps against many virtual OS and platform combinations with Android Emulators and iOS Simulators.

What You'll Need

note

Sauce Labs does not support Android Emulators with Play Store integration. For more information contact Sauce Labs Support or use the Sauce Labs Portal.

Upload Your App to Emulators and Simulators

To begin, upload your app to a publicly available source. Accepted file types are *.zip iOS package files for Simulators and *.apk or *.aab Android package files for Emulators. There are two ways you can upload your app for automated testing:

Set Your Test Credentials

After you've uploaded your app, open a new test script. Add your Sauce Labs credentials (username and accessKey).

warning

Credentials should not be stored in as text in your code where they might be stored in version control system. For every machine that executes the code, set your Sauce Labs credentials with environment variables.

Set Test Configurations

There are numerous Test Configuration Options that can be used to generate the session you want and determine the behavior of the tests.

Here are some tips for configuring your Appium tests:

Set the Location of Your Mobile App

Set the value of app to the location for where it can be accessed. This can be a full URL, or it can use Sauce Labs App Storage

note

Sauce Labs only allows you to set either browserName or app. If you have a value set for browserName Sauce will treat it as a mobile-web test instead of a native app test, so make sure this value is empty or removed.

Example of using Sauce Labs Storage:

Sauce Labs Storage
loading...

Set the appiumVersion

We recommend specifying one of the newer Appium versions, which will provide a more extended API and fixes to known bugs. If this value is not set, an older default value may be used instead.

Check the Appium Version for Your Test

  • Log in to Sauce Labs.
  • Find and select the test that you ran using Appium to view the Test Details page.
  • Click the Metadata tab.
  • Look for the Logs row and select Appium Log. The first line should indicate the Appium version. For example:
    2014-05-05T17:45:07.541Z - info: Welcome to Appium v1.9.0.

iOS Code Examples

Below are examples of an iPhone 8 project using iOS version 12.2:

DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("appiumVersion", "1.13.0");
caps.setCapability("deviceName","iPhone 8 Simulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion","12.2");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "");
caps.setCapability("app", "https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.1.0.zip");

Android Code Examples

Below are examples of an Samsung Galaxy S9 Plus project using Android version 8.1:

DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("appiumVersion", "1.9.1");
caps.setCapability("deviceName","Samsung Galaxy S9 Plus FHD GoogleAPI Emulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", "");
caps.setCapability("platformVersion","8.1");
caps.setCapability("platformName","Android");
caps.setCapability("app", "https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/Android.SauceLabs.Mobile.Sample.app.2.2.0.apk");

Native Apps vs. Hybrid Apps

iPhone Native App
DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("appiumVersion", "1.9.0");
caps.setCapability("deviceName","iPhone 8");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion","14.3");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "");
caps.setCapability("app","storage:filename=mapp.zip");
iPad Native App
DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("appiumVersion", "1.9.0");
caps.setCapability("deviceName","iPad Retina");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion","14.3");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "");
caps.setCapability("app","storage:filename=myapp.zip");
iPhone Hybrid App,
DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("appiumVersion", "1.9.0");
caps.setCapability("deviceName","iPhone Retina (4-inch 64-bit)");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion","7.1");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "");
caps.setCapability("app","storage:filename=myapp.zip");

Example Appium Test Scripts

These Appium scripts for iOS and Android mobile app tests on Emulators and Simulators can help streamline your testing process. Below are links to the Sauce Labs Training on GitHub repository, where you'll find demo scripts for a variety of use cases to get you started with automated Appium testing:

Additional Test Configuration Options