Test Alert Dialog Text Using Capybara Webkit 1.3.1
Asked Answered
A

1

2

I'm looking to test the text in an alert dialog using Capybara Webkit. I'm aware of the accept_js_confirms and reject_js_confirms methods, but I'm looking to evaluate the contents of the dialog prior to performing an action. In Selenium for example, the following works:

alert = page.driver.browser.switch_to.alert expect(alert.text).to eq t('report_periods.edit.delete_confirmation') alert.accept

I'm currently using expect(page.driver.confirm_messages).to include t('report_periods.edit.delete_confirmation') to test the text of the same dialog, however, after updating our capybara-webkit gem our tests output a deprecation warning: [DEPRECATION] Capybara::Webkit::Driver#confirm_messages is deprecated. Please use Capybara::Session#accept_confirm or Capybara::Session#dismiss_confirm instead. Using either of those methods from the warning will not test the contents of the dialog though.

Almanza answered 9/12, 2014 at 16:35 Comment(0)
S
5

accept_confirm and dismiss_confirm will only accept or dismiss the modal.

If you want to compare the text the you can take the return value of accept_confirm in a variable and then later you can compare it.

message = accept_prompt(with: 'Linus Torvalds') do
  click_link('Show Prompt About Linux')
end
expect(message).to eq('Who is the chief architect of Linux?')

Look at Modals here: https://github.com/jnicklas/capybara

Shae answered 9/12, 2014 at 16:55 Comment(1)
Thanks Ashutosh! I discovered this on my own as well using this answer: https://mcmap.net/q/244092/-deprecation-warning-from-capybaraAlmanza

© 2022 - 2024 — McMap. All rights reserved.