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
- A Sauce Labs account (Log in or sign up for a free trial license).
- Your Sauce Labs Username and Access Key.
- The native or hybrid mobile app you want to test. If you don't have one on hand and would like to test this functionality, consider using our Sauce Labs demo mobile app.
- Ensure that your system fulfills the project support and requirements prior to uploading your apps or leveraging device Emulators and Simulators. Review the Automated Mobile App Testing Admin Guide for further details.
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:
- Upload a local file using the App Storage REST API
- Provide a URL to install from a Remote Location
Set Your Test Credentials
After you've uploaded your app, open a new test script. Add your Sauce Labs credentials (username
and accessKey
).
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
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:
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 14.0:
- Java
- Python
- Node.js
- Ruby
- C#
DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("appiumVersion", "1.13.0");
caps.setCapability("deviceName","iPhone 8 Simulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion","14.0");
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");
caps['browserName'] = ""
caps['appiumVersion'] = "1.13.0"
caps['deviceName'] = "iPhone 8 Simulator"
caps['deviceOrientation'] = "portrait"
caps['platformVersion'] = "12.2"
caps['platformName'] = "iOS"
caps['app'] = "https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.1.0.zip"
caps['browserName'] = ''
caps['appiumVersion'] = '1.13.0'
caps['deviceName'] = 'iPhone 8 Simulator'
caps['deviceOrientation'] = 'portrait'
caps['platformVersion'] = '12.2'
caps['platformName'] = 'iOS'
caps['app'] =
'https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.1.0.zip'
caps = Selenium::WebDriver::Remote::Capabilities.iphone()
caps['appiumVersion'] = '1.13.0'
caps['deviceName'] = 'iPhone 8 Simulator'
caps['deviceOrientation'] = 'portrait'
caps['platformVersion'] = '12.2'
caps['platformName'] = 'iOS'
caps['browserName'] = ''
caps['app'] = 'https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.1.0.zip'
DesiredCapabilities caps = new DesiredCapabilities();
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:
- Java
- Python
- Node.js
- Ruby
- C#
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");
caps = {}
caps['appiumVersion'] = "1.9.1"
caps['deviceName'] = "Samsung Galaxy S9 Plus FHD GoogleAPI Emulator"
caps['deviceOrientation'] = "portrait"
caps['platformVersion'] = "8.1"
caps['platformName'] = "Android"
caps['app'] = "https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/Android.SauceLabs.Mobile.Sample.app.2.2.0.apk"
caps = {}
caps['appiumVersion'] = '1.9.1'
caps['deviceName'] = 'Samsung Galaxy S9 Plus FHD GoogleAPI Emulator'
caps['deviceOrientation'] = 'portrait'
caps['browserName'] = ''
caps['platformVersion'] = '8.1'
caps['platformName'] = 'Android'
caps['app'] =
'https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/Android.SauceLabs.Mobile.Sample.app.2.2.0.apk'
caps = Selenium::WebDriver::Remote::Capabilities.android()
caps['appiumVersion'] = '1.9.1'
caps['deviceName'] = 'Samsung Galaxy S9 Plus FHD GoogleAPI Emulator'
caps['deviceOrientation'] = 'portrait'
caps['browserName'] = ''
caps['platformVersion'] = '8.1'
caps['platformName'] = 'Android'
caps['app'] = 'https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/Android.SauceLabs.Mobile.Sample.app.2.2.0.apk'
DesiredCapabilities caps = new DesiredCapabilities();
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
- iOS
- Android
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");
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");
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");
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("appiumVersion", "1.9.0");
caps.setCapability("deviceName","Samsung Galaxy S4 Emulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", "");
caps.setCapability("platformVersion","4.3");
caps.setCapability("platformName","Android");
caps.setCapability("app","storage:filename=myapp.zip");
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("appiumVersion", "1.9.0");
caps.setCapability("deviceName","Android Emulator");
caps.setCapability("deviceType","tablet");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", "");
caps.setCapability("platformVersion","4.1");
caps.setCapability("platformName","Android");
caps.setCapability("app","storage:filename=myapp.zip");
caps.setCapability("automationName","Selendroid");
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
- Implement timeouts to control text execution times
- Annotating Tests with the Sauce Labs REST API
- Annotating Tests with Selenium's JavaScript Executor
- Setting Test Status to Pass or Fail
- Using Build IDs and tags to differentiate and identify test runs
- Create your own test script examples using our Platform Configurator
- Browse our full suite of test configuration options and advanced configurations