November 20, 2013

Quick tip: Testing JavaScript confirmation dialogs

Did you know that testing JavaScript confirmation dialogs is pretty easy with capybara-webkit?

You can use page.driver.accept_js_confirms! and page.driver.dismiss_js_confirms! in your tests.

For example:

# spec/features/delete_post_spec.rb

feature 'Delete post', js:true do
  scenario 'does not delete post without accepting confirmation' do

    # create post, visit post page

    click_link 'Delete posts'

    expect(page).not_to have_content 'Post has been deleted.'

For more information check capybara-webkit github repository.

Hey there!

My name is Patrik Bóna and I am the only programmer at Memberful. This blog is kind of dead, but I just started my own Ruby on Rails screencast. Follow me on Twitter if you want to be notified about my newest videos.