2017-08-29 65 views
-1

我正在用量角器进行端到端测试。在某个测试中,我需要像打印按钮一样测试是否创建PDF。所以当测试点击按钮时,它将打开如下所示的打印窗口对话框。如何关闭量角器测试中的打印窗口对话框

enter image description here

现在这个试验是无法完成。因为这个打印窗口。我的问题是如何关闭量角器中的这个打印对话框?正因为如此,其余的测试都成为待决。请帮忙。提前致谢。

编辑

我已经试过这样的..

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打印对话框。

+0

如果PDF在其它窗口中打开,你只需要在该窗口和接近开关为'browser.switchTo()窗口(browser.getAllWindowHandles()[1])的close(); ... ' –

+0

您可以查看已编辑的帖子。[Saurabh](https://stackoverflow.com/users/3193455/saurabh-gaur)请帮忙。 –

+0

请给出一个完整的答案..我没有越来越.. [Saurabh](https://stackoverflow.com/users/3193455/saurabh-gaur) –

回答

0

您需要将转义发送到右侧窗口。在发送之前,等待窗口打开。您可能还需要切换回处理[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]) 
      }); 
     }); 
    }); 
}); 
+0

感谢您的尝试。[Barteld](https://stackoverflow.com/users/7306638/barteld)我已经像上面那样尝试过了。它无法打开第二个窗口打印dialog.looks像browser.sleep不在这里工作 –

+0

你的功能打开一个新的选项卡,或只打印对话框?如果打印选项从新选项卡打开对话框,则只需切换窗口。否则,你只需要等待对话框打开。 – Barteld

+0

不,它没有打开新的tab。它只打开一个打印对话框[Barteld](https://stackoverflow.com/users/7306638/barteld)点击打印按钮后,打印对话框打开得很快,就像没有浏览器一样。睡眠工作,因此printDialog在相同的窗口中打开。 –