Skip to content

Instantly share code, notes, and snippets.

@thefotios
Created October 11, 2011 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefotios/1279719 to your computer and use it in GitHub Desktop.
Save thefotios/1279719 to your computer and use it in GitHub Desktop.
Setup and teardown for Test::Unit and Selenium
def setup
@url="http://localhost"
@verification_errors = []
@tags = []
@custom_data = {
"commit" => 'abcd1234',
"release" => 'rhc-site-0.79.4'
}
caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps.version = "5"
caps.platform = :XP
caps[:name] = "Unnamed test" # Name is populated later
caps[:tags] = @tags.flatten.uniq
caps['custom-data'] = @custom_data
caps[:build] = ENV['BUILD_NUMBER'] || 'unofficial'
@driver=Selenium::WebDriver.for(
:remote,
:url => "http://#{$username}:#{$key}@ondemand.saucelabs.com:80/wd/hub",
:desired_capabilities => caps
)
@job_id = @driver.instance_variable_get(:@bridge).session_id,
@http = Net::HTTP.new("saucelabs.com")
@req = Net::HTTP::Put.new("/rest/v1/#{$username}/jobs/#{@job_id}")
@req.basic_auth $username, $key
end
def update_test(body)
@req.body = body.to_json
response = @http.request(@req)
# Raises HTTP error if the response is not 2xx (HTTPSuccess).
response.value
end
def teardown
update_test({
:passed => @verification_errors.empty?,
:tags => @tags.flatten.uniq
})
@driver.quit
assert_equal [], @verification_errors
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment