Last active
January 27, 2017 10:14
-
-
Save lucashungaro/6596462 to your computer and use it in GitHub Desktop.
Triggering an autocomplete select box with Capybara and Turnip
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
# on spec/helpers | |
module FormHelper | |
def fill_in_autocomplete(selector, value) | |
page.execute_script %Q{$('#{selector}').focus().val('#{value}').keydown()} | |
end | |
def choose_autocomplete(text) | |
find('ul.ui-autocomplete').should have_content(text) | |
page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()") | |
end | |
end | |
# on spec_helper.rb, inside Rspec.configure block | |
config.include FormHelper, :type => :feature | |
#Calling these: | |
fill_in_autocomplete '#produto_search', @product.model_name | |
sleep 1 | |
choose_autocomplete(@product.model_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work for me, it doesn't trigger the AJAX call that collects the results unless I physically click on the input field. Cannot find a solution to this problem.