问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/27384040/test-alert-dialog-text-using-capybara-webkit-1-3-1