Search code examples
ruby-on-railsrubyrspeccapybaracapybara-webkit

javascript Confirmation Dialog in capybara webkit driver


So I want to test a user deleting their account using capybara and rspec:

scenario "User wants to delete their account" do
  click_link "Account"
  click_link "Delete My Account"
  expect(page).to have_text("You're account was deleted.")
end

Only problem is a js confirmation dialog appears when a user clicks 'delete my account'. To confirm this dialog I did the following:

  1. Install capybara-webkit
  2. add Capybara.javascript_driver = :webkit to my spec_helper.rb
  3. add :js => true to scenario "User wants to delete their account" do.

Now nothing seems to work with the addition of :js => true. I am getting the error Capybara::ElementNotFound: Unable to find link "Account" and before it was working fine, does js: true interfere with these capybara methods? Is my config wrong?


Solution

  • Importantly, the link in question was inside a dropdown that was not visible without a mouse hover event. To solve the issue I opened the dropdown with javascript before I clicked the link.

    page.execute_script('$(".dropdown-toggle").dropdown("toggle");')