On Tue, 1 Apr 2025 22:42:25 GMT, Kevin Rushforth <[email protected]> wrote:
>> Turns out one can't intercept assertion exceptions with
>> `Thread.setDefaultUncaughtExceptionHandler()` (duh!), so this is likely to
>> be a known limitation.
>>
>> We might still provide general purpose methods in `ScreenCapture` (new
>> class) like
>>
>>
>> /**
>> * Captures a screenshot using JavaFX {@link Robot} in the PNG format.
>> * <p>
>> * This method can be called from any thread. If called from a thread
>> other than
>> * the JavaFX Application Thread, the current thread will be paused
>> until the screenshot is taken.
>> *
>> * @return the byte array containing the screenshot
>> * @throws IOException when an I/O error occurs
>> */
>> public static byte[] takeScreenshot() throws IOException {
>>
>>
>> and
>>
>>
>> /**
>> * Captures a screenshot using JavaFX {@link Robot} in the PNG format,
>> * in the form of a Base-64 encoded {@code String}.
>> * <p>
>> * This method can be called from any thread. If called from a thread
>> other than
>> * the JavaFX Application Thread, the current thread will be paused
>> until the screenshot is taken.
>> *
>> * @param prefix the string to append before the base-64 representation,
>> or null
>> * @param postfix the string to append after the base-64 representation,
>> or null
>> * @return the screenshot in Base-64 encoded PNG, or an error message
>> */
>> public static String takeScreenshotBase64(String prefix, String postfix)
>> {
>>
>>
>> What do you think?
>
>> We might still provide general purpose methods in ScreenCapture (new class)
>> like
>
> That might work. So the idea would be a utility class not tied to a JUnit5
> annotation? The usage would then be adding a call to that while debugging a
> test wherever it makes sense for your test, possible from an AfterEach method.
>
>> public static byte[] takeScreenshot() throws IOException {
>
> What would this do? I can see the usefulness of returning a WritableImage
> (basically calling `Robot::getScreenCapture` on the whole screen) or a
> base64-encoded PNG file, but what does it mean to return a raw byte array? I
> probably wouldn't recommend this one.
>
>> public static String takeScreenshotBase64(String prefix, String postfix)
>> {
>
> This seems useful, although what are "prefix" and "postfix" for?
@kevinrushforth do you know why there are two java windows in the screenshot
above?
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1746#issuecomment-2773133380