Simulating Javascript Keydown in Capybara
How do you write an rspec test for a Google Places Autocomplete?
-
Use https://github.com/rdeguzman/jquery-ui/blob/ticker/tests/jquery.simulate.js
-
Trigger “keydown” event using simulate method.
fill_in 'address_search_textfield', :with => text sleep 2 script1 = '$("#address_search_textfield").trigger("focus");' page.driver.browser.execute_script(script1) sleep 1 script2 = '$("#address_search_textfield").simulate("keydown", { keyCode: $.ui.keyCode.DOWN });' page.driver.browser.execute_script(script2) sleep 1 script3 = '$("#address_search_textfield").simulate("keydown", { keyCode: $.ui.keyCode.ENTER });' page.driver.browser.execute_script(script3) sleep 1 page.should have_link(text) |