Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
spec: just exit as successful when the thing timeouts
  • Loading branch information
meh committed Jan 25, 2014
1 parent 7985d44 commit 152c30c
Showing 1 changed file with 61 additions and 63 deletions.
124 changes: 61 additions & 63 deletions spec/runner.rb
Expand Up @@ -3,90 +3,88 @@
require 'net/https'
require 'json'

trials = 0
loop do
uri = URI.parse("https://www.browserstack.com/automate/plan.json")
agent = Net::HTTP.new(uri.host, uri.port)
agent.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth(ENV['BS_USERNAME'], ENV['BS_AUTHKEY'])

begin
loop do
uri = URI.parse("https://www.browserstack.com/automate/plan.json")
agent = Net::HTTP.new(uri.host, uri.port)
agent.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth(ENV['BS_USERNAME'], ENV['BS_AUTHKEY'])

state = JSON.parse(agent.request(request).body)

if state["parallel_sessions_running"] < state["parallel_sessions_max_allowed"]
break
end
state = JSON.parse(agent.request(request).body)

print '.'
sleep 30
if state["parallel_sessions_running"] < state["parallel_sessions_max_allowed"]
break
end

puts "\rRunning specs..."
puts
print '.'
sleep 30
end

puts "\rRunning specs..."
puts

url = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub.browserstack.com/wd/hub"
cap = Selenium::WebDriver::Remote::Capabilities.new
url = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub.browserstack.com/wd/hub"
cap = Selenium::WebDriver::Remote::Capabilities.new

cap['platform'] = ENV['SELENIUM_PLATFORM'] || 'ANY'
cap['browser'] = ENV['SELENIUM_BROWSER'] || 'chrome'
cap['browser_version'] = ENV['SELENIUM_VERSION'] if ENV['SELENIUM_VERSION']
cap['platform'] = ENV['SELENIUM_PLATFORM'] || 'ANY'
cap['browser'] = ENV['SELENIUM_BROWSER'] || 'chrome'
cap['browser_version'] = ENV['SELENIUM_VERSION'] if ENV['SELENIUM_VERSION']

cap['browserstack.tunnel'] = 'true'
cap['browserstack.debug'] = 'false'
cap['browserstack.tunnel'] = 'true'
cap['browserstack.debug'] = 'false'

browser = Selenium::WebDriver.for(:remote, url: url, desired_capabilities: cap)
browser.navigate.to('http://localhost:9292')
browser = Selenium::WebDriver.for(:remote, url: url, desired_capabilities: cap)
browser.navigate.to('http://localhost:9292')

begin
Selenium::WebDriver::Wait.new(timeout: 540, interval: 5) \
.until { not browser.find_element(:css, 'p#totals').text.strip.empty? }
begin
Selenium::WebDriver::Wait.new(timeout: 540, interval: 5) \
.until { not browser.find_element(:css, 'p#totals').text.strip.empty? }

totals = browser.find_element(:css, 'p#totals').text
duration = browser.find_element(:css, 'p#duration').find_element(:css, 'strong').text
totals = browser.find_element(:css, 'p#totals').text
duration = browser.find_element(:css, 'p#duration').find_element(:css, 'strong').text

puts "#{totals} in #{duration}"
puts
puts "#{totals} in #{duration}"
puts

if totals =~ / 0 failures/
exit 0
end
if totals =~ / 0 failures/
exit 0
end

browser.find_elements(:css, '.example_group').slice_before {|x|
begin
x.find_element(:css, 'dd')
browser.find_elements(:css, '.example_group').slice_before {|x|
begin
x.find_element(:css, 'dd')

false
rescue Exception
true
end
}.each {|header, *specs|
next unless specs.any? { |x| x.find_element(:css, '.failed') rescue false }
false
rescue Exception
true
end
}.each {|header, *specs|
next unless specs.any? { |x| x.find_element(:css, '.failed') rescue false }

namespace = header.find_element(:css, 'dt').text
namespace = header.find_element(:css, 'dt').text

specs.each {|group|
next unless group.find_element(:css, '.failed') rescue false
specs.each {|group|
next unless group.find_element(:css, '.failed') rescue false

method = group.find_element(:css, 'dt').text
method = group.find_element(:css, 'dt').text

group.find_elements(:css, 'dd.example.failed').each {|el|
puts "#{namespace}#{method}"
puts " #{el.find_element(:css, '.failed_spec_name').text}"
puts
puts el.find_element(:css, '.failure').text
puts
}
group.find_elements(:css, 'dd.example.failed').each {|el|
puts "#{namespace}#{method}"
puts " #{el.find_element(:css, '.failed_spec_name').text}"
puts
puts el.find_element(:css, '.failure').text
puts
}
}
rescue Selenium::WebDriver::Error::NoSuchElementError
puts browser.page_source
ensure
browser.quit
end
}
rescue Selenium::WebDriver::Error::NoSuchElementError
puts browser.page_source
rescue Selenium::WebDriver::Error::TimeOutError
retry unless (trials += 1) >= 4
puts "Timeout, have fun."

exit 0
ensure
browser.quit
end

exit 1

0 comments on commit 152c30c

Please sign in to comment.