Created
April 13, 2017 10:34
-
-
Save Jamedjo/b2622958d3eafbf868fe9090f253b776 to your computer and use it in GitHub Desktop.
Capybara after_page_change hook
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
module CapybaraHooks | |
def after_page_change | |
end | |
Capybara::Session::DSL_METHODS.each do |method| | |
define_method method do |*args, &block| | |
old_page = page.current_url | |
super(*args, &block) | |
new_page = page.current_url | |
puts "Command #{method}" | |
if old_page != new_page | |
puts "Changed from #{old_page} to #{new_page}" | |
after_page_change | |
else | |
puts "Still on page: #{new_page}" | |
end | |
end | |
end | |
end | |
RSpec.configure do |config| | |
config.include CapybaraHooks, type: :feature | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment