The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing


External Resources

More Info

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


The demo scripts in this repository allow you to run simple automated tests in order to validate your Java Selenium environment and your account credentials.


The code in these scripts is provided on an "AS-IS" basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. These scripts are provided for educational and demonstration purposes only, and should not be used in production. Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by the Technical Services team at Sauce Labs.


 Click here to expand the content

Not found

Could not read the file

Sauce Labs Test Setup

Click here to see how to setup your Sauce Labs credentials in Gitpod

Project Setup

Import the Project

  1. Create a directory on your machine.
  2. Clone this repository into said directory.
    $ git clone
  3. Import the project into your IntelliJ (or IDE of your choice) as a Maven Project.
  4. Click through the prompts, and confirm when it asks to Import from Sources
  5. Choose the demo-java directory as the root directory of the project.

Set Your Sauce Labs Credentials

  1. Copy your Sauce Labs username and accessKey in the User Settings section of the Sauce Labs Dashboard.

  2. Open a Terminal window (command prompt for Windows) and set your Sauce Labs Environment variables:

    Mac OSX:
    $ export SAUCE_USERNAME="username"
    $ export SAUCE_ACCESS_KEY="accessKey"
    > set SAUCE_USERNAME="username"
    > set SAUCE_ACCESS_KEY="accessKey"

    To set an environment variables permanently in Windows, you must append it to the PATH variable.

    Go to Control Panel > System > Windows version > Advanced System Settings > Environment Variables > System Variables > Edit > New

    Then set the "Name" and "Value" for each variable

  3. Test the environment variables

    Mac OSX:
    $ echo $SAUCE_USERNAME
    $ echo $SAUCE_ACCESS_KEY

    ***WARNING FOR UNIX USERS!***: If you have problems setting your environment variables, run the following commands in your terminal:

    $ launchctl setenv SAUCE_USERNAME $SAUCE_USERNAME
    $ launchctl setenv SAUCE_ACCESS_KEY $SAUCE_ACCESS_KEY
    > echo %SAUCE_USERNAME%
    > echo %SAUCE_ACCESS_KEY%

Run a Maven Test

  1. Run the following command to update any package dependencies:

    $ mvn dependency:resolve
  2. Then run the following command to compile your test code:

    $ mvn test-compile
  3. Finally, run the following test to see if you've properly configured the test environment:

    $ mvn test -Dtest=Module2TestNGTest -pl on-boarding-modules/testng

    If you wish to run a specific test/sub-module in this emusim_testng use the following command:

    # for running a specific test:
    mvn test -Dtest=testname
    # for running a specific sub-module
    mvn test -pl subproject/

Choosing the Correct Data Center

IP Ranges and Data Center Endpoints
Sauce Labs has data centers in both the US and EU. You can access Sauce Labs services from either location by providing the appropriate URL endpoints, and whitelisting their associated IP ranges. 

 Click here to view US Data Center Endpoints

Virtual Device Cloud

Real Devices:

Sauce Connect Proxy (do not need to specify, Sauce Connect Proxy will use this by default)



IP Ranges: (this is equivalent to the range – (this is equivalent to the range -

 Click here to view EU Data Center endpoints

For more information, including framework configuration for the European data center, check out Sauce Labs European Data Center Configuration Information.

Virtual Device Cloud

Real Devices:

Sauce Connect Proxy (specify with -x argument)



IP Range: (this is equivalent to the range -

Running Local Tests

Developing websites/apps within your local network is secure and efficient. The drawback to this method is that local assets are not publicly-accessible on the Internet, so the browsers/devices in the Sauce Labs cloud can't load and test your app. The solution is to use Sauce ConnectSauce Connect is a proxy server that creates a secure tunnel connection between the Sauce Labs virtual machine that runs your test and your local  network. You can also use Sauce Connect to test applications and websites that are located within your corporate firewall. Sauce Connect is not required to run tests on Sauce Labs, only in situations where the application or website you want to test is not publicly accessible. 

Running Tests in Parallel

Now that you’re running tests on Sauce, you may wonder how you can run your tests faster. One way to increase speed is by running tests in parallel across multiple virtual machines.

You can run your tests in parallel at two levels, and you can run your tests in parallel across multiple browsers. For example, if you have 10 tests and want to run on five browsers, this would be parallelism of five. You can also run tests across browsers and each test in parallel. Using our previous example this would be more like 50 parallel tests. Doing this requires that your tests are written in a way that they do not collide with one another, as described in our Best Practice topics avoiding external test dependencies and avoiding dependencies between tests.

Check out Using Frameworks to Run Tests in Parallel for more information, and examples of framework setups for Java, Python, and other programming languages.