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

Jasmine 量角器:在新选项卡中检查pdf文档,jasmine,protractor,Jasmine,Protractor,我正在尝试自动化一个场景,在这个场景中,我单击一个按钮,它会在新选项卡中打开一个pdf文档。当测试失败时,将显示一个json对象,而不是pdf文档 我使用以下代码: element(by.id('MyButton')).click().then(function () { browser.getAllWindowHandles().then(function (handles) { newWindowHandle =

我正在尝试自动化一个场景,在这个场景中,我单击一个按钮,它会在新选项卡中打开一个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"
提前谢谢。
;-)

可能是因为呈现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);
    });
}):

非常感谢你,泰伯德!你打开了局面。