Search code examples
rubyseleniumwebdriversaucelabs

Ruby Selenium Webdriver - configuring Sauce Labs Pass/Fail


Sauce Labs has a specific :passed option that can be used to report the pass/fail status of a test - (https://saucelabs.com/docs/additional-config).

I just can't seem to wrap my head around how to accomplish this in Ruby.

I've tried creating a global variable ($status) in my class that is used as a placeholder for the value of :passed for the Sauce Labs test. Then during teardown updating the placeholder to the appropriate value.

In this example the test will always return as Fail

in my class

$status = false

in my setup

caps[:passed] = $status

in my teardown

def success
  $status = true
end

def error
  $status = false
end

I'm assuming that caps[:passed] = $status is set during setup and can't be changed.

I have no idea how to update the :passed status after the job is complete.


Solution

  • I was able to accomplish this by using the sauce_whisk gem (https://github.com/saucelabs/sauce_whisk)

    "SauceWhisk provides an "ActiveRecord" style client for the Sauce Labs RESTful API. If you're not using the Sauce Gem and you want a nice way to interact with our API, give this a try."

    During driver setup retrieve the SauceLabs Job ID - something like @job_id = @driver.instance_variable_get("@bridge").instance_variable_get("@session_id")

    Then during teardown I can use SauceWhisk::Jobs.pass_job @job_id or SauceWhisk::Jobs.fail_job @job_id to set the status of the job.