microsoft / playwright-java

Java version of the Playwright testing and automation library
https://playwright.dev/java/
Apache License 2.0
1.13k stars 205 forks source link

[BUG] TimeoutError thrown when attempting to take screenshot within onDialog handler #1325

Closed mrokitka closed 1 year ago

mrokitka commented 1 year ago

System info

Source code

Test file (self-contained) Page Javascript:

confirm("Are you sure that you want to delete the file?");

Java:

final Boolean[] dialogProcessed = new Boolean[1];
dialogProcessed[0] = false;
page.onDialog(dialog -> {
  //this prints as expected
  System.out.println("Dialog dismissed");
  //hangs here
  page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("foo.png"));
  dialogProcessed[0] = true;
  dialog.dismiss();
});
pageModel.clickDeleteButton();
//moving the sshot call to this line does not result in timeout, but it does not visually contain the dialog either
page.waitForCondition(() -> dialogProcessed[0] == true);

Steps

Expected

Screenshot taken showing the javascript confirmation dialog

Actual

Error stacktrace:

com.microsoft.playwright.TimeoutError: Error {
  message='Timeout 30000ms exceeded.
=========================== logs ===========================
taking page screenshot
============================================================
  name='TimeoutError
  stack='TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
taking page screenshot
============================================================
    at ProgressController.run (C:\Users\mike.r\AppData\Local\Temp\playwright-java-12589068589396836453\package\lib\server\progress.js:88:26)
    at Page.screenshot (C:\Users\mike.r\AppData\Local\Temp\playwright-java-12589068589396836453\package\lib\server\page.js:436:23)
    at PageDispatcher.screenshot (C:\Users\mike.r\AppData\Local\Temp\playwright-java-12589068589396836453\package\lib\server\dispatchers\pageDispatcher.js:200:32)
    at DispatcherConnection.dispatch (C:\Users\mike.r\AppData\Local\Temp\playwright-java-12589068589396836453\package\lib\server\dispatchers\dispatcher.js:312:46)
}

    at com.microsoft.playwright.impl.WaitableResult.get(WaitableResult.java:52)
    at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:111)
    at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:126)
    at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:102)
    at com.microsoft.playwright.impl.PageImpl.screenshotImpl(PageImpl.java:1094)
    at com.microsoft.playwright.impl.PageImpl.lambda$screenshot$65(PageImpl.java:1038)
    at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47)
    at com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:87)
    at com.microsoft.playwright.impl.PageImpl.screenshot(PageImpl.java:1038)
yury-s commented 1 year ago

Playwright screenshot of native browser UI elements except for the web content, so you wouldn't see the dialog on the screenshot. Also screenshots are while a modal dialog is open are not supported. You can take screenshot only after the dialog has been handled.

mrokitka commented 1 year ago

Can this be documented somewhere? I wasn't aware this was not supported.

53n4d commented 1 year ago

This should be supported because of DAST tools. I have the same problem with taking screenshot of xss alert for validation point.