Sauce Labs with TeamCity

TeamCity is a continuous integration tool suite by JetBrains. Use this documentation to manage your Sauce Labs tests within your TeamCity Java project.

Installing the Plugin#

  1. Download the Sauce OnDemand Plugin for TeamCity ZIP file.
  2. Copy the ZIP into your TeamCity ~/.BuildServer/plugins directory and extract the files.
  3. Restart TeamCity.

Configuring a Project#

Create the Project#

  1. From the TeamCity dashboard, choose Administration and click Create Project.
  2. For Name, enter SauceDemo (populates Project ID field with SauceDemo.
  3. Click Create.
  4. Select the VCS Roots tab, click Create VCS root, and enter the following field values:
    • Fetch URL: https://github.com/saucelabs-sample-test-frameworks/Java-Junit-Selenium (use the sample Java/JUnit test framework)
    • Default Branch: Master
  5. Click Save.

Create the Build Configuration#

  1. On the General tab, choose Create build configuration.
  2. In the Name field, enter Maven.
  3. Click VCS settings.
  4. In Attach existing VCS root, select https://github.com/saucelabs/java-sauce-example.git#master.
  5. Click Add build step.
    • For Runner type, choose Maven.
    • For Goals, enter test.
    • Save the build step.
  6. Click Add build feature and select Sauce Labs Build Feature.
  7. Enter your SAUCE_USERNAME and SAUCE_ACCESS_KEY.
  8. Select Enable Sauce Connect if you want to launch an instance of Sauce Connect prior to running your job that will close upon completion of the job (for use in private network environments in order to establish a secure connection to the Sauce platform).
  9. Select the operating system and browser combination you want to test against.
  10. Click Save.

Integrate the Tests#

  1. From the TeamCity dashboard, click Run.
  2. When the build completes, click Results and choose the Sauce Labs Results tab.
  3. Click the Job ID link to view the test report, which lists the steps performed the test and includes a video of the test.

Setting Environment Variables#

Using environment variables in your configuration file allows you to maintain the values of properties in a single source and then reference them throughout all your jobs, ensuring that, if a modification needs to be made, it only needs to be made in one place in order to take effect in all references.

note

If you're using Protractor to run your tests with TeamCity, ensure disableEnvironmentOverrides is set to false in your config.ts file (this is the default setting) to prevent environment variables from being overridden by that file.

Sauce OnDemand Environment Variables#

VariableDescription
SELENIUM_HOSTThe hostname of the Selenium server
SELENIUM_PORTThe port of the Selenium server
SELENIUM_PLATFORMThe operating system of the selected browser
SELENIUM_VERSIONThe version number of the selected browser
SELENIUM_BROWSERThe name of the selected browser
SELENIUM_DRIVERContains the operating system, version and browser name of the selected browser
SELENIUM_URLThe initial URL to load when the test begins
SAUCE_USERNAMEThe user name used to invoke Sauce OnDemand
SAUCE_ACCESS_KEYThe access key for the user used to invoke Sauce OnDemand
SELENIUM_STARTING_URLThe value of the Starting URL field
SAUCE_ONDEMAND_BROWSERSA JSON-formatted string representing browsers you selected for the job configuration

TeamCity Environment Variables#

VariableDescription
SAUCE_TC_BUILDNUMBERThe build name to use with Sauce Labs jobs
TUNNEL_IDENTIFIERThe unique tunnel identifier used by Sauce Connect, if enabled

Outputting the Bamboo Session ID to stdout#

As part of the post-build activities, the Sauce plugin parses the test result files to detect lines in the stdout or stderr containing the format:

SauceOnDemandSessionID=<session id> job-name=<job name>

To ensure that your test results and Sauce jobs are associated properly, output the SauceOnDemandSessionID (obtained from the RemoteWebDriver instance) to stdout using the following code.

private void printSessionId() {
String message = String.format("SauceOnDemandSessionID=%1$s job-name=%2$s",
(((RemoteWebDriver) driver).getSessionId()).toString(), "job name");
System.out.println(message);
}
Last updated on by James Tacker