mirror of
https://github.com/appium/appium.git
synced 2026-05-04 09:20:30 -05:00
Added Sauce Labs API for passes and failures
This commit is contained in:
@@ -11,11 +11,41 @@
|
||||
|
||||
require 'rspec'
|
||||
require 'selenium-webdriver'
|
||||
require 'net/http'
|
||||
require 'uri'
|
||||
|
||||
APP_PATH = 'http://appium.s3.amazonaws.com/TestApp6.0.app.zip'
|
||||
SAUCE_USERNAME = ENV['SAUCE_USERNAME']
|
||||
SAUCE_ACCESS_KEY = ENV['SAUCE_ACCESS_KEY']
|
||||
|
||||
# This is the test itself
|
||||
describe "Computation" do
|
||||
before(:each) do
|
||||
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
# Get the success by checking for assertion exceptions,
|
||||
# and log them against the job, which is exposed by the session_id
|
||||
job_id = @driver.instance_variable_get(:@bridge).instance_variable_get(:@session_id)
|
||||
update_job_success(job_id, example.exception.nil?)
|
||||
@driver.quit
|
||||
end
|
||||
|
||||
it "should add two numbers" do
|
||||
values = [rand(10), rand(10)]
|
||||
expected_sum = values.reduce(&:+)
|
||||
elements = @driver.find_elements(:tag_name, 'textField')
|
||||
|
||||
elements.each_with_index do |element, index|
|
||||
element.send_keys values[index]
|
||||
end
|
||||
|
||||
@driver.find_elements(:tag_name, 'button')[0].click
|
||||
@driver.find_elements(:tag_name, 'staticText')[0].text.should eq expected_sum.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def capabilities
|
||||
{
|
||||
'browserName' => 'iOS 6.0',
|
||||
@@ -30,27 +60,24 @@ def server_url
|
||||
"http://#{SAUCE_USERNAME}:#{SAUCE_ACCESS_KEY}@ondemand.saucelabs.com:80/wd/hub"
|
||||
end
|
||||
|
||||
describe "Computation" do
|
||||
before(:each) do
|
||||
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
|
||||
end
|
||||
# Because WebDriver doesn't have the concept of test failure, use the Sauce
|
||||
# Labs REST API to record job success or failure
|
||||
def update_job_success(job_id, success)
|
||||
sauce_api.request update_request(job_id, success)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@driver.quit
|
||||
end
|
||||
# Creates the RESTful job update indicating passing or failure
|
||||
def update_request(job_id, success)
|
||||
request = Net::HTTP::Put.new("/rest/v1/#{SAUCE_USERNAME}/jobs/#{job_id}")
|
||||
request.basic_auth(SAUCE_USERNAME, SAUCE_ACCESS_KEY)
|
||||
request.content_type= "application/json"
|
||||
request.body = "{\"passed\":#{success}}"
|
||||
request
|
||||
end
|
||||
|
||||
it "should add two numbers" do
|
||||
values = [rand(10), rand(10)]
|
||||
expected_sum = values.reduce(&:+)
|
||||
elements = @driver.find_elements(:tag_name, 'textField')
|
||||
def sauce_api
|
||||
sauce_api = Net::HTTP.new("saucelabs.com", 443)
|
||||
sauce_api.use_ssl= true
|
||||
sauce_api
|
||||
end
|
||||
|
||||
elements.each_with_index do |element, index|
|
||||
element.send_keys values[index]
|
||||
end
|
||||
|
||||
button = @driver.find_elements(:tag_name, 'button')[0]
|
||||
button.click
|
||||
|
||||
@driver.find_elements(:tag_name, 'staticText')[0].text.should eq expected_sum.to_s
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user