Skip to content

Instantly share code, notes, and snippets.

@wojtekmach
Created March 15, 2013 03:57
Show Gist options
  • Save wojtekmach/5167380 to your computer and use it in GitHub Desktop.
Save wojtekmach/5167380 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/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
@gmile
Copy link

gmile commented Mar 15, 2013

Nice!

How about?

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

@wojtekmach
Copy link
Author

nice idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment