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

Setting the Build Capability

Just set the build desired capability to the value of the SAUCE_BUILD_NAME environment variable. For example, in Java:

DesiredCapabilities capabilities = new DesiredCapabilities();
// ...
capabilities.setCapability("build", System.getenv("SAUCE_BUILD_NAME");
This will ensure that the Sauce build name is stored when the job is first run, and then you will be able to access your test reports in your Sauce Labs dash account by looking for the build number and then clicking through to the report, and the Sauce jobs that were executed as part of the build will be listed on the Jenkins Build Details page. 

Using the Sauce Jenkins Plugin

 If you re using the Sauce OnDemand Jenkins plugin, the value of the SAUCE_BUILD_NAME environment variable will be populated with the ${JOB_NAME}__${BUILD_NUMBER} for you.


Marking Tests as Pass/Fail

The Sauce plugin for Jenkins will also mark the Sauce jobs as passed or failed, but you need to configure Jenkins to parse the test results. 

  1. In Jenkins, on the project configuration page, go the Post-Build Actions section.
  2. Select Run Sauce Labs Test Publisher

Outputting the Jenkins Session ID to stdout

As part of the post-build activities, the Sauce plugin will parse the test result files in an attempt to associate test results with Sauce jobs. It does this by identifying lines in the stdout or stderr that have this format:
SauceOnDemandSessionID=<session id> job-name=<some job name>

The session id can be obtained from the RemoteWebDriver instance and the job-name can be any string, but is generally the name of the test class being executed.

To make sure that your test results and Sauce jobs are associated properly, you need to output the session id to stdout. For example, this is the code you would use to output the session id to the Java stdout. 

private void printSessionId() {

    String message = String.format("SauceOnDemandSessionID=%1$s job-name=%2$s",
    (((RemoteWebDriver) driver).getSessionId()).toString(), "some job name");