Testing if a dialog is pop-up with Playwright for Java

8 hours ago 1
ARTICLE AD BOX

I have a question about dialog in Playwright Java. By far what I have known, you can handle dialog through onDialog(), offDialog(), onceDialog(). But they are not suitable for testing if a dialog is not displayed when you trigger a button or similar.

For example, the code that I have tried:

page.onceDialog(dialog -> { assertTrue(true); dialog.accept(); }); page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Open Dialog")).click();

doesn't handle if the dialog has never displayed.

Would be nice if there is an easy waitForDialog() method for fully testing as if the dialog is either displayed or not.
Reference:

Dialogs | Playwright Java

Events | Playwright Java

Read Entire Article