Handling Print Dialog Using Protractor
Is there an API wrapper available to handle Print Dialog using Protractor?
Steps
Configure a button to open the print dialog using $window.print(). Once this dialog is opened with a click event, looking for a method to close the print dialog.
Selenium Solution https://code.google.com/p/selenium/issues/detail?id=1815
Thanks.
Protractor is limited by the features available in selenium/webdriver, so there is no better way to close the print dialog. You might be able to do the same as the solution you linked (sending the escape key, which would look like
browser.actions().
sendKeys(protractor.Key.ESCAPE).
perform();
I haven't tried this yet though.
@juliemr Thanks for the solution, but I was wondering, since the print command triggers a modal dialog (or rather a pop up window), is it possible for us to focus/control it?
This is what I have done with the solution you have provided
it('should show the print dialog and the close it', function() {
element(by.css('#print')).click().then(function() {
browser.actions().
sendKeys(protractor.Key.ESCAPE).
perform();
});
});
The browser opens the print dialog and waits for something to happen
And the console logs
//snipp
Failures:
1) my app should show the print dialog and the close it
Message:
timeout: timed out after 30000 msec waiting for spec to complete
Stacktrace:
undefined
Finished in 33.97 seconds
2 tests, 2 assertions, 1 failure
Am I missing something?
PS: Tested on Chrome only.
Thanks.
This did not work for me either. Seems like since the print dialog is generated from browser, we are not able to focus on the overlay to take any actions. All my tries have been futile so far.
Did anyone solve this problem?
Thanks, Max
Confirmed that WebDriver doesn't have the native capability to deal with this. See http://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium
Unfortunately, we're constrained by what WebDriver can do here.