The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

Below are some examples of how to configure Appium tests for Real Devices.  For real device testing you'll need to grab the project API key and app ID. Please visit the Appium Capabilities for Real Device Testing page for required/optional capabilities and more advanced test configuration options. Also visit the sample test frameworks repository in GitHub for more detailed language-specific examples.

Using Regular Expressions for deviceName

The examples below use regular expressions for setting the deviceName, because a matching device must be present in your account in order for the test to run.

For example:

  • "iPhone.*""iPhone .*" will allocate any iPhone. "
  • .*nexus.*" will allocate any device with the word "nexus" in its display name.
  • "iPhone [67]" or "iPhone [6-7]" will allocate either "iPhone 7" or "iPhone 6" device.
  • "iPhone [67]S" or "iPhone [6-7]S" will allocate either "iPhone 7S" or "iPhone 6S" device. "iPhone 7.*" will allocate "iPhone 7" or "iPhone 7S", or any device that starts with the display name "iPhone 7"

Regular expressions are case insensitive, for example, "iphone .*S" and "IPHONe .*s" are the same.

Using Real Devices on Sauce Labs (app.saucelabs.com)

Below are examples of an iPhone project using iOS version 12.2.

DesiredCapabilities caps = DesiredCapabilities();
	caps.setCapability("username", "SAUCE_USERNAME");
	caps.setCapability("accessKey", "SAUCE_ACCESS_KEY");
	caps.setCapability("deviceName","iPhone .*");
	caps.setCapability("deviceOrientation", "portrait");
	caps.setCapability("platformVersion","12.2");
	caps.setCapability("platformName", "iOS");
	caps.setCapability("browserName", "");
	caps.setCapability("app", "sauce-storage:<upload_filename>");
caps = {}
caps['username'] = "SAUCE_USERNAME"
caps['accessKey'] = "SAUCE_ACCESS_KEY"
caps['browserName'] = ""
caps['deviceName'] = "iPhone .*"
caps['deviceOrientation'] = "portrait"
caps['platformVersion'] = "12.2"
caps['platformName'] = "iOS"
caps['app'] = "sauce-storage:<upload_filename>"
caps = {};
caps['username'] = 'SAUCE_USERNAME';
caps['accessKey'] = 'SAUCE_ACCESS_KEY';
caps['browserName'] = '';
caps['deviceName'] = 'iPhone .*';
caps['deviceOrientation'] = 'portrait';
caps['platformVersion'] = '12.2';
caps['platformName'] = 'iOS';
caps['app'] = 'sauce-storage:<upload_filename>';
caps = Selenium::WebDriver::Remote::Capabilities()
caps['username'] = 'SAUCE_USERNAME'
caps['accessKey'] = 'SAUCE_ACCESS_KEY'
caps['deviceName'] = 'iPhone .*'
caps['deviceOrientation'] = 'portrait'
caps['platformVersion'] = '12.2'
caps['platformName'] = 'iOS'
caps['browserName'] = ''
caps['app'] = 'sauce-storage:<upload_filename>'
DesiredCapabilities caps = new DesiredCapabilities();
	caps.SetCapability("username", "SAUCE_USERNAME");
	caps.SetCapability("accessKey", "SAUCE_ACCESS_KEY");
	caps.SetCapability("deviceName", "iPhone .*");
	caps.SetCapability("deviceOrientation", "portrait");
	caps.SetCapability("platformVersion", "12.2");
	caps.SetCapability("platformName", "iOS");
	caps.SetCapability("browserName", "");
	caps.SetCapability("app", "sauce-storage:<upload_filename>");

Below are examples of an Samsung Galaxy project using Android version 8.1.

DesiredCapabilities caps = DesiredCapabilities();
	caps.setCapability("username", "SAUCE_USERNAME");
	caps.setCapability("accessKey", "SAUCE_ACCESS_KEY");
	caps.setCapability("deviceName","Samsung.*Galaxy.*");
	caps.setCapability("deviceOrientation", "portrait");
	caps.setCapability("browserName", "");
	caps.setCapability("platformVersion","8.1");
	caps.setCapability("platformName","Android");
	caps.setCapability("app", "sauce-storage:<upload_filename>");
caps = {}
caps['username'] = "SAUCE_USERNAME"
caps['accessKey'] = "SAUCE_ACCESS_KEY"
caps['deviceName'] = "Samsung.*Galaxy.*"
caps['deviceOrientation'] = "portrait"
caps['platformVersion'] = "8.1"
caps['platformName'] = "Android"
caps['app'] = "sauce-storage:<upload_filename>"
caps = {};
caps['username'] = 'SAUCE_USERNAME';
caps['accessKey'] = 'SAUCE_ACCESS_KEY';
caps['deviceName'] = 'Samsung.*Galaxy.*';
caps['deviceOrientation'] = 'portrait';
caps['browserName'] = '';
caps['platformVersion'] = '8.1';
caps['platformName'] = 'Android';
caps['app'] = 'sauce-storage:<upload_filename>';
caps = Selenium::WebDriver::Remote::Capabilities()
caps['username'] = 'SAUCE_USERNAME'
caps['accessKey'] = 'SAUCE_ACCESS_KEY'
caps['deviceName'] = 'Samsung.*Galaxy.*'
caps['deviceOrientation'] = 'portrait'
caps['browserName'] = ''
caps['platformVersion'] = '8.1'
caps['platformName'] = 'Android'
caps['app'] = 'sauce-storage:<upload_filename>'
DesiredCapabilities caps = new DesiredCapabilities();
	caps.SetCapability("username", "SAUCE_USERNAME");
	caps.SetCapability("accessKey", "SAUCE_ACCESS_KEY");
	caps.SetCapability("deviceName", "Samsung.*Galaxy.*");
	caps.SetCapability("deviceOrientation", "portrait");
	caps.SetCapability("browserName", "");
	caps.SetCapability("platformVersion", "8.1");
	caps.SetCapability("platformName", "Android");
	caps.SetCapability("app", "sauce-storage:<upload_filename>");

Using the Legacy Platform (app.testobject.com)

Below are examples of an iPhone project using iOS version 12.2

DesiredCapabilities caps = DesiredCapabilities();
	caps.setCapability("testobject_api_key", "project_api_key");
	caps.setCapability("testobject_app_id", "1");
	caps.setCapability("deviceName","iPhone .*");
	caps.setCapability("deviceOrientation", "portrait");
	caps.setCapability("platformVersion","12.2");
	caps.setCapability("platformName", "iOS");
	caps.setCapability("browserName", "");
caps['browserName'] = ""
caps['testobject_api_key'] = "project_api_key"
caps['testobject_app_id'] = "1"
caps['deviceName'] = "iPhone .*"
caps['deviceOrientation'] = "portrait"
caps['platformVersion'] = "12.2"
caps['platformName'] = "iOS"
caps['browserName'] = '';
caps['testobject_api_key'] = "project_api_key";
caps['testobject_app_id'] = "1";
caps['deviceName'] = 'iPhone .*';
caps['deviceOrientation'] = 'portrait';
caps['platformVersion'] = '12.2';
caps['platformName'] = 'iOS';
caps = Selenium::WebDriver::Remote::Capabilities()
caps['testobject_api_key'] = 'project_api_key'
caps['testobject_app_id'] = '1'
caps['deviceName'] = 'iPhone .*'
caps['deviceOrientation'] = 'portrait'
caps['platformVersion'] = '12.2'
caps['platformName'] = 'iOS'
caps['browserName'] = ''
DesiredCapabilities caps = new DesiredCapabilities();
	caps.SetCapability("deviceName", "iPhone .*");
	caps.SetCapability("testobject_api_key", "project_api_key");
	caps.SetCapability("testobject_app_id", "1");
	caps.SetCapability("deviceOrientation", "portrait");
	caps.SetCapability("platformVersion", "12.2");
	caps.SetCapability("platformName", "iOS");
	caps.SetCapability("browserName", "");

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

DesiredCapabilities caps = DesiredCapabilities();
	caps.setCapability("testobject_api_key", "project_api_key");
	caps.setCapability("testobject_app_id", "1");
	caps.setCapability("deviceName","Samsung.*Galaxy.*");
	caps.setCapability("deviceOrientation", "portrait");
	caps.setCapability("browserName", "");
	caps.setCapability("platformVersion","8.1");
	caps.setCapability("platformName","Android");
caps = {}
caps['testobject_api_key'] = "project_api_key"
caps['testobject_app_id'] = "1"
caps['deviceName'] = "Samsung.*Galaxy.*"
caps['deviceOrientation'] = "portrait"
caps['platformVersion'] = "8.1"
caps['platformName'] = "Android"
caps = {};
caps['testobject_api_key'] = 'project_api_key';
caps['testobject_app_id'] = '1';
caps['deviceName'] = 'Samsung.*Galaxy.*';
caps['deviceOrientation'] = 'portrait';
caps['browserName'] = '';
caps['platformVersion'] = '8.1';
caps['platformName'] = 'Android';
caps = Selenium::WebDriver::Remote::Capabilities()
caps['testobject_api_key'] = 'project_api_key'
caps['testobject_app_id'] = '1'
caps['deviceName'] = 'Samsung.*Galaxy.*'
caps['deviceOrientation'] = 'portrait'
caps['browserName'] = ''
caps['platformVersion'] = '8.1'
caps['platformName'] = 'Android'
DesiredCapabilities caps = new DesiredCapabilities();
	caps.SetCapability("testobject_api_key", "project_api_key");
	caps.SetCapability("testobject_app_id", "1");
	caps.SetCapability("deviceName", "Samsung.*Galaxy.*");
	caps.SetCapability("deviceOrientation", "portrait");
	caps.SetCapability("browserName", "");
	caps.SetCapability("platformVersion", "8.1");
	caps.SetCapability("platformName", "Android");

Further Information on Configuring Appium Tests for Real Devices