我试图自动化一个场景,我点击一个按钮,它打开一个pdf文档在新的选项卡。当测试失败时,将显示一个json对象而不是pdf文档。
我使用以下代码:
element(by.id('MyButton')).click().then(function () {
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle).then(function () {
var EC = protractor.ExpectedConditions;
// Waits for the element is not present on the dom.
browser.wait(EC.stalenessOf($('#formattedJson')), 5000);
});
});
});我可以打开新的选项卡,但当我不知道如何检查内容(pdf或json对象)。请给我一些建议。
例如,我有一个错误:
Failed: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"提前谢谢。;-)
发布于 2018-05-09 18:35:56
可能是因为呈现你的pdf的窗口不是一个有角度的页面。通过使用browser.waitForAngularEnabled(false),你可以告诉量角器不要等待角度。您应该在调用切换窗口之前就这样做。请记住,当您关闭窗口并切换回您的主应用程序窗口时,请重新打开它。请查看此文档以获得更多信息。
browser.getAllWindowHandles().then(function (handles) {
newWindowHandle = handles[1]; // this is your new window
browser.waitForAngularEnabled(false); //add this and it should work
browser.switchTo().window(newWindowHandle).then(function () {
var EC = protractor.ExpectedConditions;
// Waits for the element is not present on the dom.
browser.wait(EC.stalenessOf($('#formattedJson')), 5000);
});
}):https://stackoverflow.com/questions/50250338
复制相似问题