reporting-process

Setting the Build Capabilities

Just set the build desired capability to the value of the JOB_NAME and BUILD_NUMBER environment variable.  This will ensure that the Jenkins build number is stored when the job is first to run. Then you will be able to access your test reports in the Sauce Labs dashboard by looking for the build number and then clicking through to the report. The Sauce jobs that were executed as part of the build will be listed on the Jenkins Build Details page.

DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(“build”, System.getenv(“JOB_NAME”) + “__” + System.getenv(“BUILD_NUMBER”));

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.

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.

private void printSessionId() { String message = String.format(“SauceOnDemandSessionID=%1$s job-name=%2$s”, (((RemoteWebDriver) driver).getSessionId()).toString(), “some job name”); System.out.println(message); }

Marking Tests as Pass/Fail

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

  • In Jenkins, on the project configuration page, go the Post-Build Actions
  • Then Select Run Sauce Labs Test Publisher

Once done, test scripts setup look like below for Java:

public static final String USERNAME = “*****”; public static final String ACCESS_KEY = “*****************************************”; public static final String URL = “https://” + USERNAME + “:” + ACCESS_KEY + “@ondemand.saucelabs.com:443/wd/hub”; private void printSessionId() { String message = String.format(“SauceOnDemandSessionID=%1$s job-name=%2$s”, (((RemoteWebDriver) driver).getSessionId()).toString(), “some job name”); System.out.println(message); } @BeforeClass public void setUp() throws MalformedURLException{ DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setCapability(“build”, System.getenv(“JOB_NAME”) + “__” + System.getenv(“BUILD_NUMBER”)); desiredCapabilities.setBrowserName(System.getenv(“SELENIUM_BROWSER”)); desiredCapabilities.setVersion(System.getenv(“SELENIUM_VERSION”)); desiredCapabilities.setCapability(CapabilityType.PLATFORM, System.getenv(“SELENIUM_PLATFORM”)); driver = new RemoteWebDriver(new URL(URL), desiredCapabilities); printSessionId(); // driver = new FirefoxDriver(desiredCapabilities); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.MILLISECONDS); driver.navigate().to(baseURL); }

Execution and Reporting Integration

Now build Jenkins job and we should see below the screen in Sauce Labs.

SauceLabs and Jenkins Test Running

Jenkins Job will reflect in Sauce Labs with the build number.

SauceLabs and Jenkins Build Complete

After execution is done Sauce Labs report gets published on Jenkins Environment and we can download videos and check execution log which is generated under Sauce Labs.

You may also like: Getting Started With Integrating Jenkins and Sauce Labs

Leave a comment

Your email address will not be published. Required fields are marked *