【发布时间】:2018-03-20 20:40:56
【问题描述】:
我正在使用量角器进行端到端测试。在某个测试中,我需要测试打印按钮是否正在创建 pdf。因此,当 Test 单击按钮时,它会打开如下所示的打印窗口对话框。
现在这个测试无法完成。因为这个打印窗口。我的问题是如何在量角器中关闭此打印对话框?正因为如此,其余的测试变得悬而未决。请帮忙。提前致谢。
编辑
我试过这样的..
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])
});
});
});
});
但是它没有为打印对话框打开一个新标签。在同一个标签中打开打印对话框。
【问题讨论】:
-
如果这个pdf在另一个窗口打开,你只需要切换那个窗口并以
browser.switchTo().window(browser.getAllWindowHandles()[1]).close();...关闭 -
您可以查看已编辑的帖子。Saurabh请帮忙。
-
请给一个完整的答案..我没有得到..Saurabh
-
Have a look here知道如何切换窗口
-
是一个窗口还是多个??
标签: javascript jquery angular protractor