문제

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.

도움이 되었습니까?

해결책 2

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.

다른 팁

An example straight from Sauce Labs found here.

require 'rubygems'
require "test/unit"
require 'selenium-webdriver'

class ExampleTest < Test::Unit::TestCase
    def setup
        caps = Selenium::WebDriver::Remote::Capabilities.firefox
        caps.version = "5"
        caps.platform = :XP
        caps[:name] = "Testing Selenium 2 with Ruby on Sauce"

        @driver = Selenium::WebDriver.for(
          :remote,
          :url => "http://username-string:access-key-string@ondemand.saucelabs.com:80/wd/hub",
          :desired_capabilities => caps)
    end

    def test_sauce
        @driver.navigate.to "http://saucelabs.com/test/guinea-pig"
        assert @driver.title.include?("I am a page title - Sauce Labs")
    end

    def teardown
        @driver.quit
    end
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top