如何修复“意外警报打开:{警告文本:}”错误

问题描述 投票:1回答:1

我在Angy中使用AngularJS进行了一个项目,我目前正在将测试转换为Phantomjs的Headless chrome,并且我一直收到错误消息:

Selenium::WebDriver::Error::UnhandledAlertError:
            unexpected alert open: {Alert text : }

这发生在多个测试文件中..我试过添加

命令前的“accept_alert {}”:

#from

find('.sp-advanced-configuration').click

#to
accept_alert{ find('.sp-advanced-configuration').click  } 

但收到

Failure/Error: accept_alert{ ... }

          Capybara::ModalNotFound:
            Unable to find modal dialog

以及

Selenium::WebDriver::Error::UnhandledAlertError:
            unexpected alert open: {Alert text : }

不知道还有什么可以尝试

/*********** *********/

在进一步研究之后,在进行下一次测试之前,只要测试中有未保存的更改,就会出现问题。

有没有办法让你可以接受每个测试,而无需添加

 after do 
    execute_script('window.onbeforeunload = undefined')
  end

在每个测试文件中?

ruby selenium-webdriver
1个回答
0
投票

你看到这个的原因是Poltergesit / PhantomJS曾经自动接受意想不到的系统模态。硒驱动程序不会这样做,因为您的测试应该主动接受或拒绝它。 find('.sp-advanced-configuration').click是打开警报框的动作吗?从你得到的错误我猜不会。块accept_alert接收需要是实际触发系统模态打开的块。这意味着您的代码可能需要

accept_alert { # action that triggers the alert }
find('.sp-advanced-configuration').click
© www.soinside.com 2019 - 2024. All rights reserved.