量角器:在新标签中检查pdf文档 [英] Protractor : Check pdf document in a new tab

查看:79
本文介绍了量角器:在新标签中检查pdf文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动化一个场景,我单击一个按钮,然后在新选项卡中打开一个pdf文档.当测试失败时,将显示json对象而不是pdf文档.

I am trying to automate a scenario where I click on a button and its opens up a pdf document in new tab. When the test fails, a json object is displayed instead of the pdf document.

我使用以下代码:

            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对象)时. 一些建议将不胜感激.

I can open the new tab but when I dont know how to check the content (pdf or json object). Some advices would be appreciated.

例如我有错误:

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"

先谢谢了. ;-)

推荐答案

可能是因为呈现pdf的窗口不是角度页面.您可以使用browser.waitForAngularEnabled(false)告诉量角器不要等待角度.您应该在调用切换窗口之前立即执行此操作.只需记住在关闭窗口后将其重新打开,然后再切换回主应用程序窗口即可.请查看此文档以获得更多信息.

Probably because the window that is rendering your pdf isn't an angular page. You can tell protractor not to wait for angular by using browser.waitForAngularEnabled(false). You should do this right before your call to switch window. Just remember to turn it back on when you close the window and switch back to your main app window. Check out this documentation for more info.

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);
    });
}):

这篇关于量角器:在新标签中检查pdf文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆