Skip to content

Instantly share code, notes, and snippets.

@adammw
Forked from wojtekmach/capybara-recording.rb
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adammw/9200791 to your computer and use it in GitHub Desktop.
Save adammw/9200791 to your computer and use it in GitHub Desktop.
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'
require 'capybara/poltergeist'
require 'capybara-recording'
Capybara.current_driver = :poltergeist
include Capybara::DSL
include Capybara::Recording
record '/tmp/filename.gif' do
visit 'http://www.google.com/'
fill_in 'q', with: 'NYC'
click_button 'Google Search'
click_link "New York City - Wikipedia, the free encyclopedia"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment