我有一个项目已经运行很长时间了。最近(几周)系统测试失败。
经过大量的调查,我们得出结论,量角器不能识别和关闭警报。
原来的代码
exports.removeFaq = function( index ){
console.log('deleting item at',index);
exports.getContent(index).$( '[ng-click="removeFAQ($index)"]').click();
browser.sleep(2000);
browser.switchTo().alert().accept();
return browser.sleep(2000);
};
现在抛出错误:
WebDriverError: unknown error: cannot determine loading status
from unexpected alert open
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)
和(使用元素资源管理器):
> browser.switchTo().alert().accept();
UnexpectedAlertOpenError: unexpected alert open: {Alert text : are you sure you want to remove this helper content?}
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)
我们已经试过了- waiting
代替睡眠。-长时间睡眠-忽略angular.
似乎没有任何区别。
如何解决这个问题?
同样的问题持续了几天。看起来我们用的是chromedriver 2.21。我更新到最新版本(2.23),似乎已经解决了这个问题。
命令webdriver-manager update --chrome
不适合我,所以我必须下载压缩并将其解压缩到我的selenium目录。在量角器。
注意,有一个新的量角器主版本与更新版本。所以更新量角器也可以解决这个问题。
用于量角器版本3.x
您也可以将node_modules/protractor/config.json
文件修改为正确的版本,然后运行webdriver-manager update
用于量角器版本4.x
您应该修改文件./node_modules/protractor/node_modules/webdriver-manager/config.json
。
我们怎么能肯定地说2000ms
的睡眠足够好呢?正是由于这个原因,不建议在测试中睡觉。相反,您可以使用适当的等待和轮询来获得警报。这样您就会知道,在某个商定的超时之后,警报从未出现,测试失败
//wait maximum up to lets 5s before giving up
browser.wait(protractor.ExpectedConditions.alertIsPresent(), 5000);
browser.switchTo().alert().accept();