Last active
December 11, 2015 18:38
-
-
Save senny/4642853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hook to save the html page of every failed scenario into the temp | |
# file directory taht it can be checked after cucumber has finished running. | |
require 'fileutils' | |
require 'capybara/util/save_and_open_page' | |
FAILED_SCENARIO_PAGES_PATH = File.join Rails.root, 'tmp', 'failed_scenarios' | |
FAILED_SCENARIO_IMAGES_PATH = File.join Rails.root, 'tmp', 'failed_scenarios_images' | |
FileUtils.rm_rf FAILED_SCENARIO_PAGES_PATH | |
FileUtils.rm_rf FAILED_SCENARIO_IMAGES_PATH | |
After do |scenario| | |
if scenario.failed? | |
begin | |
FileUtils.makedirs(FAILED_SCENARIO_PAGES_PATH) unless File.exists?(FAILED_SCENARIO_PAGES_PATH) | |
FileUtils.makedirs(FAILED_SCENARIO_IMAGES_PATH) unless File.exists?(FAILED_SCENARIO_IMAGES_PATH) | |
name = scenario.name | |
name = "#{scenario.scenario_outline.name}_00_#{name}" if scenario.respond_to? :scenario_outline | |
filename = "#{name.parameterize}.html" | |
File.open File.join(FAILED_SCENARIO_PAGES_PATH, filename), 'w+' do |f| | |
f.write Capybara.send(:rewrite_css_and_image_references, page.body) | |
end | |
if page.driver.respond_to?(:render) | |
filename = "#{name.parameterize}.png" | |
page.driver.render(File.join(FAILED_SCENARIO_IMAGES_PATH, filename)) | |
end | |
rescue Rack::Test::Error | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment