Skip to end of metadata
Go to start of metadata

The Sauce plugin for Jenkins provides an easy way for you to populate the desired capabilities for operating system and browser combinations for your tests as environment variables, rather than needing to hardcode them into your tests. This is a best practice for automated testing, since it means you can use your tests with multiple operating system/browser combinations without having to rewrite your test.

Prerequisites

Overriding the Environment Variables for Authentication

If you want to override the default global authentication credentials that you set as environment variables when you configured the plugin, select Override default authentication in the Build Environment section of the project configuration page. After you select this option, enter the authentication credentials you want to use for the project.

Setting Desired Capabilities for Your Project

  1. In Jenkins, go to your project.
  2. In the left-hand navigation, select Configure.
  3. In the Sauce Labs Options section, select the browser automation tool you want to use, for example WebDriver.
    When you select a browser automation tool, it will open up a menu of operating system and browser combinations that you can test against with that tool.
  4. Select the the operating systems and browsers you want to test against.
    Select Use latest version of selected browsers to default to the latest version of the browsers you select. 
  • If you select a single operating system/browser combination, then the environment variables SELENIUM_PLATFORM, SELENIUM_VERSION, and SELENIUM_BROWSER will be populated with your selections. If you select a mobile operating system/browser, the variables SELENIUM_DEVICE and SELENIUM_DEVICE_TYPE will be populated. 
  • If you select multiple OS/browser combinations, the SAUCE_ONDEMAND_BROWSERS environment variable will be populated with a JSON-formatted string containing the attributes of the selected browsers, as shown in this example:

    SAUCE_ONDEMAND_BROWSERS Environment Variable
    [
        {
        	"platform":"LINUX",
        	"os":"Linux",
        	"browser":"firefox",
        	"url":"sauce-ondemand:?os=Linux&browser=firefox&browser-version=16",
        	"browserVersion":"16"
        },
        {
        	"platform":"VISTA",
        	"os":"Windows 2008",
        	"browser":"iexploreproxy",
        	"url":"sauce-ondemand:?os=Windows 2008&browser=iexploreproxy&browser-version=9",
        	"browserVersion":"9"
        }
    ]

Setting Up Your Tests to Use the Environment Variables

In your test script, you reference the environment variables as part of your desired capabilities. Though the exact syntax will vary depending on your scripting language, this example illustrates the way you would reference the environment variables SELENIUM_BROWSER, SELENIUM_VERSION, AND SELENIUM_PLATFORM in your test script. 

desiredCapabilities.setBrowserName(System.getenv("SELENIUM_BROWSER"));
desiredCapabilities.setVersion(System.getenv("SELENIUM_VERSION"));
desiredCapabilities.setCapability(CapabilityType.PLATFORM, System.getenv("SELENIUM_PLATFORM"));

This example is for a single operating system/browser combination. If you have multiple selections, you can load the JSON string for the SAUCE_ONDEMAND_BROWSERS environment variable by using the JSON library for your scripting language, and then loop through the string to send the various combinations to your test framework. 

You can find a full list of the available environment variables in the topic Environment Variables Used by the Jenkins Plugin.