protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Handling Print Dialog Using Protractor

Open arvindr21 opened this issue 12 years ago • 5 comments

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.

arvindr21 avatar Jun 17 '14 06:06 arvindr21

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 avatar Jun 17 '14 17:06 juliemr

@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.

arvindr21 avatar Jun 17 '14 17:06 arvindr21

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.

priyabrat1801 avatar Jun 17 '14 18:06 priyabrat1801

Did anyone solve this problem?

Thanks, Max

traxtor182 avatar Jul 17 '14 12:07 traxtor182

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.

juliemr avatar Sep 23 '14 18:09 juliemr