Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
spec: take a screenshot in case of failure
  • Loading branch information
meh committed Jan 25, 2014
1 parent 574b32c commit 47f80aa
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions spec/runner.rb
Expand Up @@ -39,6 +39,14 @@
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 @@ -58,37 +66,11 @@
exit 0
end

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 }

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

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

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
}
}
}
puts screenshot(browser)
rescue Selenium::WebDriver::Error::NoSuchElementError
puts browser.page_source
rescue Selenium::WebDriver::Error::TimeOutError
puts "Timeout, have fun."
puts "\rTimeout, have fun: #{screenshot(browser)}"

exit 0
ensure
Expand Down

0 comments on commit 47f80aa

Please sign in to comment.