I have a test with RSpec like below
describe "visitor do search" do
before do
fill_in "keyword", with: "London"
click_button "search_all"
end
it "should visit search result path" do
page.should have_selector('title', :text => "Search Result")
end
end
I want to remove the button 'search_all' and change it with event like pressing enter by keyboard.
How do I write code for that with RSpec ?
Regards,
Just add a '\n' to the end of your query string:
fill_in "keyword", with: "London\n"
You can do it using capybara-webkit, which is a Capybara driver allowing you to test Javascript. Simply read the doc to install it and make it work in your project, then you should be able to simulate a click on the keyboard using this piece of code:
keypress = "var e = $.Event('keydown', { keyCode: 13 }); $('body').trigger(e);"
page.driver.execute_script(keypress)
Hope this helps.
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