I got this cucumber sceanario:
When I fill in "End User" with "john"
Then wait
Then wait
When I click "John Doe"
Then show me the page
Step definitions:
Then /^wait$/ do
sleep 2
end
When /^(?:|I )click "([^"]*)"$/ do |selector|
find(":contains('#{selector}')").click
end
It passes but it doesn't select a user."End User" equals "john" in 'show me the page'.
I even can't get it to work in a javascript console. The following code does not select anything.
$(":contains('John Doe')").last().trigger('click')
# => [<a class="ui-corner-all" tabindex="-1"...
How can I script a autocomplete select? Be it in pure javascript or in cucumber.
Give this a go
When /^I type in "([^\"]*)" into autocomplete list "([^\"]*)" and I choose "([^\"]*)"$/ do |typed, input_name,should_select|
page.driver.browser.execute_script %Q{ $('input[data-autocomplete]').trigger("focus") }
fill_in("#{input_name}",:with => typed)
page.driver.browser.execute_script %Q{ $('input[data-autocomplete]').trigger("keydown") }
sleep 1
page.driver.browser.execute_script %Q{ $('.ui-menu-item a:contains("#{should_select}")').trigger("mouseenter").trigger("click"); }
end
Use like so
And I type in "Foo" into autocomplete list "input_id" and I choose "Foobar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With