Rayrun
โ† Back to Discord Forum

After clicking print button, assert that the dialog opened up with Print and Cancel button visible

fs_projectsposted in #help-playwright
Open in Discord

I have a button named "Print". I want to click on it and assert that the dialog opens up and "Print" and "Cancel" buttons are visible in the dialog. How can I assert it?

Thank you in advance!!

This thread is trying to answer question "How can I assert that a print dialog opens up with 'Print' and 'Cancel' buttons visible after clicking a 'Print' button?"

11 replies
.aleksandaraleksandrov
.aleksandaraleksandrov

await expect(page.locator('CSS Selectors')).toBeVisible();

@.aleksandaraleksandrov how do you validate that the print dialog has popped up?

.aleksandaraleksandrov
.aleksandaraleksandrov

The same way you are gonna validate that the buttons are visible. You find a CSS selector or a Xpath pointing to the element and expect it to be Visible.

Are you talking about the native print dialog/UI triggered when calling window.print()?

I'm not sure why anyone but the browser vendors would want to validate that a core browser scenarios that's been working for 30+ years didn't break suddenly without anyone noticing. ๐Ÿค”

If you are talking about something else, yes locators and friends should do.

@p01___ I am talking about window.print() triggered dialog. Actually there is button "PDF" in UI code that triggers it. Sometimes back there was bug in the code and this dialog was not opening up when clicking the button in UI. So now it's fixed I am being told to write a test for it to just validate if clicking on "PDF" button opens up the print dialog. That's it. This is only I have to validate. Can you tell me how can I do that? The print dialog is a whole new page in itself and just doing a page.getByText("Print") or page.getByText("Cancel") (where "Print" and "Cancel" are buttons inside the native print dialog) is not working at all.

Right so that makes no sense to test that really.

You can't use locators because that's a native dialog. We don't have access to it or what's going inside it.

Did you try anything using the dialog event from Playwright?

https://playwright.dev/docs/dialogs

What you can test though and makes some sense, is to check that window.print() was called, and/or that the response sending your PDF had the correct mime type.

hm..

thanks for clarifying

@p01___ how about I donwload that PDF using page.pdf() and if it's success that means the dialog did open

page.pdf() is a Playwright API to render the current page as a PDF. That's not the same as downloading a PDF from your servers.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.