- The Platform Configurator
- Getting Started with Selenium for Automated Website Testing
- Getting Started with Appium for Mobile Native Application Testing
- Selenium Bootcamp by Dave Haeffner
- Appium Bootcamp by Dave Haeffner and Matthew Edwards
With Sauce Labs you can run automated tests of your web apps against a wide variety of device/operating system/browser combinations. This topic will provide you with basic information and code examples to get your Python tests up and running with Sauce.
The code in this topic is presented as an example only, since your tests and testing environments may require specialized scripting. This information should be taken only as an illustration of how you could set up your tests with Sauce Labs, and is not directly supported by Sauce.
You will need to install the Selenium WebDriver client driver to your local Python environment
You can either download the driver from the link, or use
pipto install it.
You should also install the Sauce Python client, which provides features for reporting job information to the Sauce Labs dashboard.
Set Sauce URL and Access Credentials
If you wanted to run a Selenium test on Selenium locally, you would initiate a driver for the browser you want to test against like this.
To run a test on a remote service like Sauce Labs, all you need to change is your
driver definition, make sure that the
sauce_endpoint variable includes your Sauce
ACCESSKEY, and then pass it two parameters:
command_executor, which points to the Sauce cloud and uses your Sauce Labs authentication to log in, and
desired_capabilties, which specifies the browsers and operating systems to run the tests against.
To find your Sauce Labs access key:
- Sign in to https://saucelabs.com with the username you set up when you created your account.
You will use this same username in your test script.
- To find your access key:
- Click your name in the Account Profile menu in the upper-right corner.
- Click User Settings.
- Scroll down to Access Key and click Show.
- Enter the password you use to sign in to Sauce Labs to view the access key.
- Click the Copy icon.
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.
Virtual Device Cloud: https://ondemand.eu-central-1.saucelabs.com/wd/hub
Sauce Connect Proxy: https://eu-central-1.saucelabs.com/rest
REST API: https://eu-central-1.saucelabs.com/rest/v1
188.8.131.52/21 (this is equivalent to the range
184.108.40.206 – 220.127.116.11)
18.104.22.168/21 (this is equivalent to the range
22.214.171.124 - 126.96.36.199)
Set Desired Capabilities
Once you have your tests set up to run in the Sauce cloud, you need to define the platform, browser, and version you want the test to run against, which is where desired capabilities come into play.
You can manually enter the values you want for
version, or you can use the handy Platform Configurator to generate the
desired_caps values for any combination of platform, browser, and browser version.
This code sample is more complex, and relies on some libraries that you may need to install to make it work.
Running Local Tests
Running Tests in Parallel
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.
Match Thread Count to Concurrency Limit
You should match your thread count to your concurrency limit, which is shown in the My Account section of your user profile information on the Sauce Labs dashboard.
For more information, check out the example scripts in our GitHub repo.
Reporting on Test Results
Unfortunately, Sauce has no way to determine whether your test passed or failed automatically, since it is determined entirely by your business logic. You can, however, tell Sauce about the results of our tests automatically using the Sauce python client and adding these lines to your test.
You should also follow our recommended best practice of adding build numbers, tags, and other identifying information to your tests so you can easily find and manage them in your test results and archives pages.