Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
spec: some runner improvements
  • Loading branch information
meh committed Jan 25, 2014
1 parent 47f80aa commit 653c27a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
5 changes: 5 additions & 0 deletions Gemfile
@@ -1,11 +1,16 @@
source 'https://rubygems.org'
gemspec

# specs
gem 'rack'
gem 'sinatra'
gem 'sinatra-websocket'

# runner
gem 'selenium-webdriver', require: false
gem 'rest-client', require: false

# browser
gem 'opal', github: 'opal/opal'
gem 'opal-rspec', '0.3.0.beta3'
gem 'paggio', github: 'meh/paggio'
36 changes: 14 additions & 22 deletions spec/runner.rb
@@ -1,6 +1,6 @@
#! /usr/bin/env ruby
require 'selenium/webdriver'
require 'net/https'
require 'rest_client'
require 'json'

url = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub.browserstack.com/wd/hub"
Expand All @@ -17,13 +17,8 @@

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)
response = RestClient.get("https://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@www.browserstack.com/automate/plan.json")
state = JSON.parse(response.to_str)

if state["parallel_sessions_running"] < state["parallel_sessions_max_allowed"]
break
Expand All @@ -39,14 +34,6 @@
retry
end

def screenshot(browser)
browser.capture_entire_page_screenshot('screenshot.png')
request = Net::HTTP.new('imgur.com')
response = request.post('/api/upload.json', image: File.open('screenshot.png'))

JSON.parse(response.body)['rsp']['image']['original_image']
end

print "\rRunning specs..."

begin
Expand All @@ -60,20 +47,25 @@ def screenshot(browser)
duration = browser.find_element(:css, 'p#duration').find_element(:css, 'strong').text

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

if totals =~ / 0 failures/
exit 0
end

puts screenshot(browser)
rescue Selenium::WebDriver::Error::NoSuchElementError
puts "\rNo such element? You dun goof'd"
puts
puts browser.page_source
rescue Selenium::WebDriver::Error::TimeOutError
puts "\rTimeout, have fun: #{screenshot(browser)}"

exit 0
puts "\rTimeout, have fun."
ensure
browser.capture_entire_page_screenshot('screenshot.png')
response = RestClient.post('https://api.imgur.com/3/upload',
{ image: File.open('screenshot.png') },
{ 'Authorization' => 'Client-ID 1979876fe2a097e' })

puts
puts JSON.parse(response.to_str)['data']['link']

browser.quit
end

Expand Down

0 comments on commit 653c27a

Please sign in to comment.