Question

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?

Was it helpful?

Solution 3

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");')

OTHER TIPS

:js => true tells Capybara to use the JavaScript driver for your spec; it's needed to run pages that have to execute JavaScript as part of their functionality. In your case, it would be needed for the JS confirmation dialog.

BUT...there's a couple of other things to note:

  1. Your link is titled "Account" above and your looking for "Account Settings". Is that a typo?
  2. I don't think you'll be able to interact with a vanilla browser confirmation dialog (i.e. alert box with confirm buttons). I know you can't when using the Poltergeist driver

Verify the visit path, before clicking to 'Delete My Account'.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top