我正在用量角器进行端到端测试。在某个测试中,我需要像打印按钮一样测试是否创建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();
});
我想如果我有成功的按ESC键,然后将解决issue.But没有成功。
NEXT EDIT-- 我已经尝试新的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
EDIT 3
我有未在Java中的角的js这个问题。
EDIT 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])
});
});
});
});
但它不会在同一选项卡中打开一个新的标签打印Dialog..open打印对话框。
如果PDF在其它窗口中打开,你只需要在该窗口和接近开关为'browser.switchTo()窗口(browser.getAllWindowHandles()[1])的close(); ... ' –
您可以查看已编辑的帖子。[Saurabh](https://stackoverflow.com/users/3193455/saurabh-gaur)请帮忙。 –
请给出一个完整的答案..我没有越来越.. [Saurabh](https://stackoverflow.com/users/3193455/saurabh-gaur) –