Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking on a confirmation alert using Capybara and rspec

In one of my views I have this link:

link_to 'Destroy', team, :method => :delete, :data => { :confirm => 'Are you sure?' }

In my rspec feature spec I want to simulate clicking on the "OK" button. I thought I could do this:

page.accept_alert 'Are you sure?' do
  click_button('OK')
end

but that results in:

Failure/Error: page.accept_alert 'Are you sure?' do
 Capybara::NotSupportedByDriverError:
   Capybara::Driver::Base#accept_modal

What is the correct way to do this with rspec and capybara?

like image 826
RobertJoseph Avatar asked Sep 17 '15 13:09

RobertJoseph


2 Answers

As the error states, the driver you are using in Capybara doesn't support the modal API. If you're using rack-test it's because it doesn't support JavaScript at all so modals don't happen anyway. If you're using poltergeist it's because they haven't released a version with support for the Capybara modal API yet - see https://github.com/teampoltergeist/poltergeist/pull/516

like image 195
Thomas Walpole Avatar answered Oct 15 '22 01:10

Thomas Walpole


I think it's confirm window not alert

page.accept_confirm do
  click_button('OK')
end
like image 2
Arsen Avatar answered Oct 15 '22 01:10

Arsen