Skip to end of metadata
Go to start of metadata

Selenium is a protocol focused on automating the actions of a browser, and as such, it doesn't encompass the notions of a "test" that "passes" or "fails." Sauce Labs lets you notify us of test status using our REST API. All you need is the ID Sauce Labs gave the job, and the status your test ended with. Then, you can use the Update Job method on the REST API to set the job's status.

The Job ID is the simplest part of the process. The ID assigned to each job by Sauce Labs is the same as the Session ID for the corresponding Selenium session, which you can pull off the driver like so:

job_id = driver.session_id 

Using the REST API is best done with the sauce_whisk gem, which assumes you've set your Sauce username and access key as the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables.

This example shows how you would modify the example RSpec spec_helper.rb file to check the status of the test, and pass that to the REST API.

Modifying spec_helper.rb to Report Test Results to the Dashboard Using the sauce-whisk Gem
require "sauce_whisk"

RSpec.configure do |config|
  config.around(:example, :run_on_sauce => true) do |example|
    @driver = SauceDriver.new_driver
    @job_id = @driver.session_id
      SauceWhisk::Jobs.change_status job_id, !example.exception.nil?

That's it! Your tests will now be reporting their status to the Sauce Labs REST API.

  • No labels