我正在创建一些黄昏测试,有时我在某些测试中遇到unexpected alert open: {Alert text : }
错误。在我的本地测试通过一些时间和一些时间抛出此错误。由于Alert text is also empty
我的网页中没有任何提醒,因此我不确定导致此问题的原因。在UI模式下运行测试时,我在页面中看不到任何警报。
以下是我当地的错误的完整信息
1) Tests\Browser\contacts\CreateContactTest::testCreate
Facebook\WebDriver\Exception\UnexpectedAlertOpenException: unexpected
alert open: {Alert text : }
(Session info: chrome=63.0.3239.132)
(Driver info: chromedriver=2.33.506106
(8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2),platform=Mac OS X 10.13.2 x86_64)
此外,我的CircleCI
测试中也会出现同样的错误,以下是关于CircleCI2的信息
1) Tests\Browser\auth\RegisterTest::testRegister
Facebook\WebDriver\Exception\UnexpectedAlertOpenException: unexpected
alert open: {Alert text : }
(Session info: headless chrome=63.0.3239.132)
(Driver info: chromedriver=2.35.528139
(47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-111-generic x86_64)
可能导致此类问题的原因,请记住,我没有在代码中打开任何警报,测试也会成功。 Can this be any chrome driver issue ?
答案 0 :(得分:1)
发生这种情况是因为我在页面上注册了一个onbeforeunload
处理程序,该处理程序提醒用户他们尚未保存的工作。
测试完成后,浏览器将“关闭”页面,导致此警报/对话框弹出。
我通过显式触发此事件并接受测试用例末尾的对话框来修复它:
$browser->visit('about:blank')->waitForDialog()->acceptDialog();