Last active
March 12, 2016 08:25
-
-
Save yurikoval/97af1eb6ec0dcfa94156 to your computer and use it in GitHub Desktop.
Take screenshot on capybara's every browser action.
This file contains 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
class Capybara::Session | |
%i(visit click_on fill_in).each do |method_name| | |
original_method_name = "old_#{method_name}".to_sym | |
alias_method original_method_name, method_name | |
define_method method_name do |*args| | |
return_value = send original_method_name, *args | |
save_screenshot(save_path) | |
increment_counter | |
return_value | |
end | |
private | |
def save_path | |
timestamp = Time.new.strftime("%Y%m%d%H%M%S") | |
name_parts = ['step', '%03d' % counter, timestamp, rand(10**10)] | |
"steps/#{@s_now ||= timestamp}/#{name_parts.join(?_)}.png" | |
end | |
def increment_counter | |
@counter = counter + 1 | |
end | |
def counter | |
@counter || 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment