Sauce Labs makes it easy to automate your tests across a wide range of OS/browser combinations on desktop and mobile devices. This topic provides an overview of how to set up and execute an automated Selenium test: connecting and authenticating your test with Sauce Labs, specifying desired capabilities for your tests, and ensuring the Sauce Labs browser cloud can connect to your app.
See the following sections for more information:
The sample scripts assume you have access to:
A Selenium environment running on your local machine. You can find setup instructions in the demo directories of the Sauce Labs Training repository.
A Selenium script you can run locally (or remotely on a Selenium grid or another service), and that you want to modify to run with Sauce.
A web app for testing, located on the public internet where our virtual machines can find it. If your app is hosted on your local machine or behind a firewall, you'll need to use Sauce Connect Proxy.
Before you modify your existing test scripts or the examples, you should log in to your Sauce Labs account and navigate to Dashboard > Automated Tests. As you modify the scripts, you can verify your changes by running the script and monitoring its progress from the dashboard.
If you have an existing Selenium script that you want to update to run on Sauce Labs, the first thing you need to do is to set the
RemoteWebDriver to connect to the Sauce Labs browser cloud. For example, if your Selenium test is written in Java, you would set the connection to Sauce Labs like this:
driver = new RemoteWebDriver(new URL("http://ondemand.saucelabs.com:80/wd/hub"), capabilities);
The example scripts in the next section are already configured to connect to the Sauce Labs US data center.
You need to update your test script to include your username and access key for Sauce Labs, as shown in the examples below:
You can find your access key on your Account Profile page:
To ensure your credentials work without having to update an existing script, copy and paste your credentials into the code as indicated in the appropriate example script, and then run it from your local machine. This will launch a test to open a browser, connect to the Sauce Labs sample app, and then close the browser and quit the test.
We recommend using environment variables for your credentials instead of hard-coding them into your scripts. This makes it easier share tests, and avoids security issues that arise from exposing authentication credentials in your script. Once you've run your first test with hard-coded credentials, set up the environment variables on your local machine, and update your tests as demonstrated in the following examples:
Desired capabilities dictate the platform, operating system, and browser you want to test against. You can use our Platform Configurator to automatically generates code snippets for these capabilities.
Under API, select Selenium
To run a test against a mobile native browser, select Appium, select the mobile device you want to test with, and then select Web Testing.
Finally, you'll need to set the URL of the web app you want to test with
driver.get. The example tests scripts are all set to run against the Sauce Labs demo app, so you can paste the URL for your web app in place of the
saucedemo URL to ensure that the Sauce Labs browser cloud can connect to your app. Use Sauce Connect Proxy to establish a connection to an app hosted on your local machine or behind a firewall.
Now that you've been able to get a test running on Sauce, there are a few other modifications you can make to your tests. These example scripts show how to:
You can find more information under Best Practices for Running Tests and Setting Test Status to Pass or Fail.