-
-
Save rinaldifonseca/3017661 to your computer and use it in GitHub Desktop.
Capybara helpers
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
def screenshot | |
require 'capybara/util/save_and_open_page' | |
now = Time.now | |
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}" | |
Capybara.save_page body, "#{p}.html" | |
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s | |
page.driver.render path | |
Launchy.open path | |
end | |
def verify_alert_message(msg, &block) | |
page.evaluate_script %Q| window.alert = function(msg) { | |
window.alert_message = msg; | |
return true; | |
}; | | |
yield | |
page.evaluate_script("window.alert_message").should eq(msg) | |
ensure | |
page.evaluate_script("window.alert_message = null)") | |
end | |
def js_confirm(accept=true) | |
page.evaluate_script "window.original_confirm = window.confirm" | |
page.evaluate_script "window.confirm = function(msg) { return #{!!accept}; }" | |
yield | |
ensure | |
page.evaluate_script "window.confirm = window.original_confirm" | |
end | |
def wait_until_ajax_done(wait_time=Capybara.default_wait_time) | |
wait_until wait_time do | |
page.evaluate_script('$.active') == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment