Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'RMagick'
require 'capybara'
require 'launchy'
module Capybara::Recording
def start_recording
system "rm -f tmp/*"
end
def save_recording
anim = Magick::ImageList.new(*Dir.glob('tmp/*png'))
anim.delay = 200
anim.write("tmp/animated.gif")
File.open("tmp/animated.html", "w") do |f|
f.puts "<img src='animated.gif'>"
end
end
def open_recording
Launchy.open("file:///#{Dir.pwd}/tmp/animated.html")
end
def _save_screenshot
save_screenshot "tmp/capybara-#{Time.now.to_f}.png"
end
(Capybara::Session::DSL_METHODS - [:save_screenshot]).each do |method|
define_method method do |*args|
super(*args)
_save_screenshot
end
end
end
require 'capybara/poltergeist'
Capybara.current_driver = :poltergeist
include Capybara::DSL
include Capybara::Recording
start_recording
visit 'http://www.google.com/'
fill_in 'q', with: 'NYC'
click_button 'Google Search'
click_link "New York City - Wikipedia, the free encyclopedia"
save_recording
open_recording
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment