I'm using Rails 3.2.8 with
- gem 'jquery-rails', '2.1.2'
- gem 'rails3-jquery-autocomplete', '1.0.9'
- gem 'rspec-rails', '2.11.4'
- gem 'capybara', '1.1.3'
- gem 'capybara-webkit', '0.12.1'
I've recently converted a select drop-down to an autocomplete (using rails3-jquery-autocomplete) and am trying to update my request specs to fill in the autocomplete.
My approach has been to create a helper as shown in this gist:
def fill_autocomplete(field, options = {})
fill_in field, :with => options[:with]
selector = "ul.ui-autocomplete a:contains('#{options[:select]}')"
page.should have_selector selector
page.execute_script "$(\"#{selector}\").mouseenter().click()"
end
If I test that with Webkit, the test fails with this message:
expected css "ul.ui-autocomplete a:contains('Firstname Lastname')" to return something.
If I test with Selenium, as I watch the test proceed in Firefox, I do not see the drop-down pick list appearing. Adding a sleep 3
to wait for the drop-down doesn't help.
I see here that there is a related but somewhat old issue with capybara-webkit, something about when a field is filled in, it is immediately blurred, which would of course prevent the autocomplete pick list from appearing. But that doesn't seem to jibe with others who have gotten this to work.
Is it currently possible to test a form that includes a rails3-jquery-autocomplete field with RSpec and Capybara? How? If not, is there a way to manually fill in the corresponding, hidden id
field so I can still test that the form creates the correct data?