How do I confirm a javascript popup with Capybara?

前端 未结 8 961
梦谈多话
梦谈多话 2020-12-08 01:55

I\'ve tried several examples found online, but with no luck. I am looking to confirm the confirm message of a delete link. The last attempt was the code below, but that re

相关标签:
8条回答
  • 2020-12-08 02:19

    First of all switch to using Selenium as the driver by putting an @javascript tag in front of your scenario.

    The following code in your cucumber step will then confirm the dialogue:

    page.driver.browser.switch_to.alert.accept
    # or
    page.driver.browser.switch_to.alert.dismiss
    # or
    page.driver.browser.switch_to.alert.text
    

    As @NobbZ said, this question has been asked and answered before here: How to test a confirm dialog with Cucumber?.

    More selenium documentation available here too: http://code.google.com/p/selenium/wiki/RubyBindings#JavaScript_dialogs

    0 讨论(0)
  • 2020-12-08 02:21

    for capybara-webkit:

    page.driver.browser.accept_js_confirms
    page.driver.browser.reject_js_confirms
    

    which is still working, but the documentation says also:

    page.driver.accept_js_confirms!
    page.driver.accept_js_confirms!
    

    See https://github.com/thoughtbot/capybara-webkit , search "accept_js_confirms"

    0 讨论(0)
提交回复
热议问题