playwright
playwright copied to clipboard
[Feature] Listen for print dialog
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?
No you are not missing anything. Sorry we don't current support listening for the print dialog.
thanks for prompt answer. Wondering are there any plans to add this in near future?
It's marked as collecting feedback. When there are enough upvotes and interest, it gets considered for implementation.
also interested in this.
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
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.
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.
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.
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?
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.
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.
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?
+1 to re-opening this issue.
+1 to re-opening this issue.
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!
+1 to re-open the issue.
Hello, this is a important feature for a project I'm working on. I hope this feature gains some traction soon!
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();
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!