id | title | sidebar_label |
---|---|---|
virtual-devices |
Appium Testing with Emulators and Simulators |
Virtual Devices |
import useBaseUrl from '@docusaurus/useBaseUrl'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
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.
- 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.
:::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. :::
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
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. :::
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 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:
https://github.com/saucelabs-training/demo-java/blob/docs-1.0/appium-examples/src/test/java/com/realdevice/image_injection/ImageInjectionIosTest.java#L63-L65
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.
- 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.
Below are examples of an iPhone 8 project using iOS version 12.2:
<Tabs defaultValue="Java" values={[ {label: 'Java', value: 'Java'}, {label: 'Python', value: 'Python'}, {label: 'Node.js', value: 'Node.js'}, {label: 'Ruby', value: 'Ruby'}, {label: 'C#', value: 'C#'}, ]}>
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");
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");
Below are examples of an Samsung Galaxy S9 Plus project using Android version 8.1:
<Tabs defaultValue="Java" values={[ {label: 'Java', value: 'Java'}, {label: 'Python', value: 'Python'}, {label: 'Node.js', value: 'Node.js'}, {label: 'Ruby', value: 'Ruby'}, {label: 'C#', value: '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");
<Tabs defaultValue="iOS" values={[ {label: 'iOS', value: 'iOS'}, {label: 'Android', value: 'Android'}, ]}>
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");
Android Native App, Android version 4.3.
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");
Android Hybrid App, Android version 4.1.
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");
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:
- 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