简体   繁体   English

黄瓜,确认显示页面开始刷新时显示的浏览器对话框

[英]Cucumber, confirm browser dialog which shows when page starts to refresh

When one scenario is done, the page refreshes (in the website there is a javascript modal implemented before refreshing the page which asks the user "Are you sure you want to leave the page?"). 完成一种情况后,页面将刷新(在网站中,在刷新页面之前已实现了JavaScript模式,该模式询问用户“您确定要离开页面吗?”)。 I need to confirm that modal. 我需要确认该模式。 But when I create the step for that, I always get this error: 但是,当我为此创建步骤时,总是会收到此错误:

Then User clicks "Leave this page" button in the popup at online reg form
      no alert open
        (Session info: chrome=35.0.1916.114)

and the code 和代码

And(/^User clicks "([^"]*)" button in the popup at online reg form$/) do |button|
  wait = Selenium::WebDriver::Wait.new
  alert = wait.until { page.driver.browser.switch_to.alert }
  alert.accept
end

Does anyone know how to handle this? 有人知道如何处理吗?

You need to override the confirm dialogue method in javascript to always return true 您需要覆盖javascript中的Confirm对白方法,以始终返回true

page.evaluate_script('window.confirm = function() { return true; }')

use this line before the line of code that triggers the dialogue to popup and it will always accept it no more steps needed :) 在触发对话框弹出的代码行之前使用此行,它将始终接受它,而无需其他步骤:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM