- 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
Sauce Labs is a cloud platform for executing automated and manual mobile and web tests. Sauce Labs supports running automated tests with Selenium WebDriver (for web applications) and Appium (for native and mobile web applications). This topic covers the basic information and example code you need to get your Java tests up and running on 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 need to have these components installed to set up testing on Sauce with Java.
- You must have JDK 1.6 or higher installed
- You need to have the selenium-java client for your operating system installed. You can download it from http://www.seleniumhq.org/download/, under the section Selenium Client & WebDriver Language Bindings.
- You should install the Java Helper Library, which will automatically update your Sauce Labs dashboard with information like whether tests have passed or failed, output the Sauce Session ID to
stdoutfor parsing by the Sauce Jenkins and Bamboo plugins, and which provides a
com.saucelabs.common.SauceOnDemandAuthenticationclass, which handles obtaining the Sauce OnDemand user name and access key from environment variables or the filesystem.
ondemand.saucelabs.com, specifying your Sauce Labs account credentials and desired browser configuration.
This code example illustrates setting up a simple Java test to find the title of a page hosted by Sauce Labs.
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.
Running Tests in Parallel and Across Multiple Browsers
Tests can be run in parallel at two levels: you can run your tests in parallel,and you can run your tests in parallel across multiple browsers. For example, if you have 10 tests and run them serially 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 50 parallel tests (10 tests, five browsers). This requires that your tests are written in a way that they do not collide with one another. For more on this see Selenium WebDriver - Running Your Tests in Parallel blog.
For more information, check out the example scripts in our GitHub repo.
Reporting on Test Results
If using other frameworks, then use the SauceRest Java Library to update the pass or fail status of the test.
You should also check out the topic Best Practice: Use Build IDs, Tags, and Names to Identify Your Tests for more suggestions on how to improve test reporting and using build numbers for your continuous integration platform.