Last active
March 20, 2017 13:03
-
-
Save jsugarman/3487e63d8013bf13b2e97e7252f2c9d5 to your computer and use it in GitHub Desktop.
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
module Capybara | |
module Node | |
module Actions | |
alias_method :old_check, :check | |
alias_method :old_uncheck, :uncheck | |
def check(locator, options = {}) | |
Capybara.current_session.evaluate_script js_element_check(locator, true) | |
end | |
def uncheck(locator, options = {}) | |
Capybara.current_session.evaluate_script js_element_check(locator, false) | |
end | |
private | |
def js_find_by_id locator | |
element = <<-SCRIPT.strip.gsub(/\s+/,' ') | |
element = (function () { | |
var element = document.getElementById(\"#{locator}\"); | |
return element; | |
})() | |
SCRIPT | |
end | |
def js_element_check locator, switch = true | |
checkbox = js_find_by_id(locator) | |
<<-SCRIPT | |
(function () { | |
#{checkbox}.checked = #{switch} | |
})() | |
SCRIPT | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Gov uk element for builder uses pseudo elements and javascript to style the checkboxes. as a result the input checkbox fields cannot be checked with the standard check/uncheck helpers (using capybara 2.5.0 with poltergeist 1.14.0 at least).
This patches the aforementioned helpers to use javascript on the resulting dom.