Last active
August 5, 2020 12:24
-
-
Save tiagotex/94a053d6a8fa5274227d7ec1fe753005 to your computer and use it in GitHub Desktop.
Select item and get selected item from choises.js select with Capybara and Selenium
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 ChoicesHelpers | |
def select_from_choices(item_text, options) | |
field = find_field(options[:from], visible: false) | |
within(find("##{field[:id]}", visible: false).ancestor(".choices")) do | |
find(".choices__inner").click | |
find("input").send_keys(item_text, :return) | |
end | |
end | |
def selected_from_choices(from) | |
field = find_field(from, visible: false) | |
within(find("##{field[:id]}", visible: false).ancestor(".choices")) do | |
find(".choices__list--single").text | |
end | |
end | |
end | |
RSpec.configure do |config| | |
config.include ChoicesHelpers, type: :system | |
end | |
### Usage | |
# Instead of: | |
# select "option text", from: "field name" | |
# Do: | |
# select_from_choices "option text", from: "field name" | |
# Instead of: | |
# expect(page).to have_select "field name", selected: "option text" | |
# Do: | |
# expect(selected_from_choices("field name")).to eq "option text" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment