Skip to content

Instantly share code, notes, and snippets.

@danivovich
Created June 14, 2012 17:51
Show Gist options
  • Save danivovich/2931746 to your computer and use it in GitHub Desktop.
Save danivovich/2931746 to your computer and use it in GitHub Desktop.
Capybara Webkit save and open page but with render
Then /^render the page$/ do
if Capybara.current_driver == Capybara.javascript_driver
file_name = "capybara-webkit-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.png"
name = File.join(*[Capybara.save_and_open_page_path, file_name].compact)
page.driver.render name
begin
require "launchy" # could raise LoadError
raise LoadError unless Launchy::Version::MAJOR >= 2
Launchy.open(name)
rescue LoadError
puts "Sorry, you need to install launchy >=2.0.0 (`gem install launchy`) and " <<
"make sure it's available to open images taken with `render the page`."
end
else
puts "MUST BE A JAVASCRIPT TEST TO RENDER THE PAGE"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment