-
-
Save lucascaton/f452cdedfec766a13716 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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