繁体   English   中英

如何在量角器测试中关闭打印窗口对话框

[英]How to close print windows dialog in Protractor Test

我正在与量角器进行端到端测试。 在某种测试中,我需要测试打印按钮是否创建pdf。 因此,当“测试”单击按钮时,它将打开打印窗口对话框,如下所示。

在此处输入图片说明

现在,此测试无法完成。 由于此打印窗口。 我的问题是如何在量角器中关闭此打印对话框? 因此,其余测试将待定。 请帮忙。 提前致谢。

编辑

我已经尝试过了

var printButton=element(by.css('[class="print"]'));
        /* This print button should be present first*/
        expect(printButton.isPresent()).toBe(true);

        browser.actions().mouseMove(printButton).perform();
        printButton.click().then(function () {
             // fill in the form here
             browser.sleep(2000);
            // For Pressing Escape key
            browser.actions().sendKeys(protractor.Key.ESC).perform();

        });

我以为如果我成功按了退出键,那么它将解决问题。但是没有成功。

下一步编辑-我尝试了如下的新Windows更改

printButton.click().then(function () {
             // fill in the form here

            browser.sleep(4000);
            browser.getAllWindowHandles().then(function(handles){
                browser.switchTo().window(handles[1]).then(function(){
                    //do your stuff on the pop up window

                    browser.driver.close();
                    browser.switchTo().window(handles[0]);
                });
            });

        });

但它在控制台中显示错误,实际上它不会打开任何窗口。 并像以前一样挂在打印对话框上。

 Failed: unknown error: failed to close window in 20 seconds

编辑3

我在Angular js而不是java中遇到了这个问题。

编辑4我的最后一次尝试

printButton.click().then(function () {
             // fill in the form here
            return browser.getAllWindowHandles().then(function (handles) {
                var newWindowHandle = handles[1]; // this is your new window
                return browser.switchTo().window(newWindowHandle).then(function () {
                    return browser.sleep(5000).then(function () {
                        return browser.actions().sendKeys(protractor.Key.ESCAPE).perform().then(function () {
                            return browser.switchTo().window(handles[0])
                        });
                    });
                });
            });

但是它不会为打印对话框打开新的选项卡。在同一选项卡中打开打印对话框。

您需要将转义发送到右侧窗口。 在发送窗口之前,还要等待窗口打开。 您可能还需要切换回handles [0]。

return browser.getAllWindowHandles().then(function (handles) {
    var newWindowHandle = handles[1]; // this is your new window
    return browser.switchTo().window(newWindowHandle).then(function () {
        return browser.sleep(5000).then(function () {
            return browser.actions().sendKeys(protractor.Key.ESCAPE).perform().then(function () {
                return browser.switchTo().window(handles[0])
            });
        });
    });
});

如下设置功能; 这将禁用从Chrome浏览器弹出的打印预览

功能:{'browserName':'chrome',chromeOptions:{args:['--disable-print-preview','start-maximized']}

},

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM