首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >量角器:在新选项卡中检查pdf文档

量角器:在新选项卡中检查pdf文档
EN

Stack Overflow用户
提问于 2018-05-09 09:49:39
回答 1查看 1.4K关注 0票数 0

我试图自动化一个场景,我点击一个按钮,它打开一个pdf文档在新的选项卡。当测试失败时,将显示一个json对象而不是pdf文档。

我使用以下代码:

代码语言:javascript
复制
            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对象)。请给我一些建议。

例如,我有一个错误:

代码语言:javascript
复制
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"

提前谢谢。;-)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-09 18:35:56

可能是因为呈现你的pdf的窗口不是一个有角度的页面。通过使用browser.waitForAngularEnabled(false),你可以告诉量角器不要等待角度。您应该在调用切换窗口之前就这样做。请记住,当您关闭窗口并切换回您的主应用程序窗口时,请重新打开它。请查看此文档以获得更多信息。

代码语言:javascript
复制
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);
    });
}):
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50250338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档