playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Listen for print dialog

Open aaliakseyenka opened this issue 3 years ago • 16 comments

Hi, I would like to test printing of the page, particularly that print dialog is opened on user action. Although seems existing api in typescript doesn't allow that. page.on('dialog') seems doesn't work with print() call. Am I missing anything?

aaliakseyenka avatar May 12 '21 19:05 aaliakseyenka

No you are not missing anything. Sorry we don't current support listening for the print dialog.

JoelEinbinder avatar May 12 '21 20:05 JoelEinbinder

thanks for prompt answer. Wondering are there any plans to add this in near future?

aaliakseyenka avatar May 13 '21 08:05 aaliakseyenka

It's marked as collecting feedback. When there are enough upvotes and interest, it gets considered for implementation.

mxschmitt avatar May 13 '21 09:05 mxschmitt

also interested in this.

qwpnqjucz avatar May 17 '21 13:05 qwpnqjucz

Hi All

For all whose use case like me, then you could check on https://github.com/microsoft/playwright-python/issues/739 .

For my use case is after click on print button, then the Browser Print preview shows up, then I would like to save Print preview as PDF file.

BTW, it works when headless=False, and it doesn't work when headless=True.

Thank you, Leo

leochung042 avatar Jun 08 '21 03:06 leochung042

Hi, I'm trying to use keyboard actions await this.page.keyboard.press('Enter');

, the similar to Robot Java class does to press Escape or Enter buttons. Unfortunately, it doesn't work. Looks like maybe with Playwright we can interact only on a page level.

Yurii397 avatar Oct 18 '21 16:10 Yurii397

Some corporate web applications have printing feature at its core, like bookkeeping software, where you need to print invoices, reports etc. It would be very useful if we could test that we can invoke printing function by clicking the designated button.

nbnds avatar Nov 05 '21 12:11 nbnds

Why was this issue closed?

We are prioritizing the features based on the upvotes, recency and activity in the issue thread. It looks like this issue only has a handful of upvotes, has not been touched recently and/or we lack sufficient feedback to act on it. We are closing issues like this one to keep our bug database maintainable. Please feel free to open a new issue and link this one to it if you think this is a mistake.

pavelfeldman avatar Oct 20 '22 03:10 pavelfeldman

Any workaround for this, this is a show stopper for me. Also I do not want to execute the script in headless mode. #16100 is also closed.

Is there any plan to provide the support in future?

Digraj22 avatar Jan 03 '23 08:01 Digraj22

I'm having this issue too... furthermore it seems like once a print dialog is opened, I'm unable to interact with anything... e.g. I can't even close the browser and restart it to continue...

It seems like there is significant demand (multiple open issues and 45+ upvotes on this issue @pavelfeldman, so I would urge you to re-open it.

chrismcv avatar Jul 14 '23 15:07 chrismcv

Here is how I handle it: Since all we need to do is ensure that the print was actually called when the print button is clicked we do:

(in Java but easy to translate to other languages):

page.onLoad(pa -> pa.evaluate("window.print = function() { console.log('Print was triggered'); };"));

then you can use waitForConsoleMessage to verify that Print was triggered was called.

uchagani avatar Jul 14 '23 16:07 uchagani

I'm surprised that this simple yet frequently used feature is not supported in Playwright. It's a total blocker for me since we have a print functionality in our gift card page that's used often by our customers and the print function has failed in the past and we need to put a test for it.
@pavelfeldman how many upvotes are needed for this feature to be considered worthy to be implemented?

pradeipp avatar Sep 05 '23 08:09 pradeipp

+1 to re-opening this issue.

snehankekre avatar Jan 05 '24 15:01 snehankekre

+1 to re-opening this issue.

AlexRhadoo avatar Jan 18 '24 08:01 AlexRhadoo

Hi, I have the same case: I need to verify the prints button and data in the print preview window before printing. It is an important future for testing!

ikonovalov070285 avatar Jan 22 '24 14:01 ikonovalov070285

+1 to re-open the issue.

tverdokhlebd avatar Feb 13 '24 13:02 tverdokhlebd

Hello, this is a important feature for a project I'm working on. I hope this feature gains some traction soon!

easyas123l11 avatar Apr 06 '24 04:04 easyas123l11

Hi,

I want to share with you the closest workaround that I found. Used a selector which points to the print event triggering button and add an additional event listener to the click event. The event listener writes a message to the console, and I checked it with an expect. If you reload the page, it will close the print dialog.

const printButton = page.frameLocator('iframe').getByRole('button', { name: 'Print' });
await printButton.evaluate(node => node.addEventListener('click', function printEventLogger(){ console.log('Print button clicked!'); }));
const msgPromise = page.waitForEvent('console');
await printButton.click();
const msg = await msgPromise;
expect(msg.text()).toBe('Print button clicked!');
await page.reload();

marnandr avatar Apr 15 '24 14:04 marnandr

We added it to our docs here, please create a new issue if it doesn’t work for you or you have feedback for it. Thanks!

mxschmitt avatar Jun 25 '24 06:06 mxschmitt