I'm trying to test print functionality of a button, like:
it('print document', function(){
element(by.id('print-button')).click();
expect(window.print());
});
I want to test browser print dialog box. How to do this?
I'm trying to test print functionality of a button, like:
it('print document', function(){
element(by.id('print-button')).click();
expect(window.print());
});
I want to test browser print dialog box. How to do this?
Browser's print dialog is out of scope of selenium, it is not under selenium's control. There is no way to solve your problem reliably with protractor
/selenium
only.
Besides, you don't need to test the browser and it's ability to open print dialogs. What you can do (not tested), is to test whether window.print
is called on print-button
click by redefining window.print()
(reference):
browser.setScriptTimeout(10);
var printButton = element(by.id('print-button'));
var result = browser.executeAsyncScript(function (elm, callback) {
function listener() {
callback(true);
}
window.print = listener;
elm.click();
}, printButton.getWebElement());
expect(result).toBe(true);
See also: