2017-08-29 49 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在相同的窗口中打開。 –

相關問題