Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cucumber and Capybara-Webkit automatic screenshots on failure
def screen_shot_and_save_page
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
Capybara.save_page body, "#{path}.html"
page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
end
begin
After do |scenario|
screen_shot_and_save_page if scenario.failed?
end
rescue Exception => e
puts "Snapshots not available for this environment.\n
Have you got gem 'capybara-webkit' in your Gemfile and have you enabled the javascript driver?"
end
Then /take a snapshot(| and show me the page)/ do |show_me|
page.driver.render Rails.root.join("tmp/capybara/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.png")
Then %{show me the page} if show_me.present?
end
@mattheworiordan

This comment has been minimized.

Copy link
Owner Author

@mattheworiordan mattheworiordan commented Nov 16, 2011

Please note that this has been superseded by the Capybara-screenshot gem at https://github.com/mattheworiordan/capybara-screenshot

@shahmishal

This comment has been minimized.

Copy link

@shahmishal shahmishal commented Jan 7, 2013

How do i change the path of automatic screen shot on failure? currently it saves it in "/" but want to move it to working directory. or How do i turn off automatic screen shot? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.