-
-
Save ddonahue99/6116406 to your computer and use it in GitHub Desktop.
jquery.tokeninput.js cucumber helper, updated with capybara 2.1 and theme support
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 TokenInputHelpers | |
THEME = '' # set to 'facebook' or 'mac' if using themes | |
def token_input(locator, options) | |
raise "Must pass a hash containing 'with'" unless options.is_a?(Hash) && options.has_key?(:with) | |
theme = THEME.present? ? "-#{THEME}" : "" | |
field = _find_fillable_field(locator) # find the field that will ultimately be sent to the server, the one the user intends to fill in | |
# Delete the existing token, if present | |
begin | |
# This xpath is finds a <ul class='token-input-list'/> followed by a <input id="ID"/> | |
within(:xpath, "//ul[@class='token-input-list#{theme}' and following-sibling::input[@id='#{field[:id]}']]") do | |
find(:css, ".token-input-delete-token").click | |
end | |
rescue Capybara::ElementNotFound | |
# no-op | |
end | |
ti_field = _find_fillable_field("token-input-#{field[:id]}") # now find the token-input | |
ti_field.set(options[:with]) # 'type' in the value | |
within(:css, ".token-input-dropdown#{theme}") do | |
find(:xpath, "//li[contains(text(),'#{options[:with]}')]").click | |
end | |
end | |
protected | |
def _find_fillable_field(locator) | |
find(:xpath, "//input[@id='#{locator}']", visible: false) | |
end | |
end | |
World(TokenInputHelpers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this one better https://gist.github.com/victorhazbun87/46d86d9de77540bbbceb