Skip to content

Commit 85d0ab5

Browse files
committed
8353138: Screen capture for test TaskbarPositionTest.java, failure case
Backport-of: 05ff557dee6adc679d85bfe8fb49f69053a6aaba
1 parent 45b84ae commit 85d0ab5

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

test/jdk/javax/swing/Popup/TaskbarPositionTest.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,11 @@
3737
import java.awt.event.KeyEvent;
3838
import java.awt.event.MouseAdapter;
3939
import java.awt.event.MouseEvent;
40+
import java.awt.image.BufferedImage;
41+
import java.io.File;
42+
import java.io.IOException;
4043

44+
import javax.imageio.ImageIO;
4145
import javax.swing.AbstractAction;
4246
import javax.swing.JComboBox;
4347
import javax.swing.JFrame;
@@ -337,11 +341,11 @@ public static void main(String[] args) throws Throwable {
337341
}
338342
}
339343

340-
try {
341-
// Use Robot to automate the test
342-
Robot robot = new Robot();
343-
robot.setAutoDelay(50);
344+
// Use Robot to automate the test
345+
Robot robot = new Robot();
346+
robot.setAutoDelay(50);
344347

348+
try {
345349
SwingUtilities.invokeAndWait(TaskbarPositionTest::new);
346350

347351
robot.waitForIdle();
@@ -442,6 +446,9 @@ public static void main(String[] args) throws Throwable {
442446
hidePopup(robot);
443447

444448
robot.waitForIdle();
449+
} catch (Throwable t) {
450+
saveScreenCapture(robot, screens);
451+
throw t;
445452
} finally {
446453
SwingUtilities.invokeAndWait(() -> {
447454
if (frame != null) {
@@ -450,4 +457,17 @@ public static void main(String[] args) throws Throwable {
450457
});
451458
}
452459
}
460+
461+
private static void saveScreenCapture(Robot robot, GraphicsDevice[] screens) {
462+
for (int i = 0; i < screens.length; i++) {
463+
Rectangle bounds = screens[i].getDefaultConfiguration()
464+
.getBounds();
465+
BufferedImage image = robot.createScreenCapture(bounds);
466+
try {
467+
ImageIO.write(image, "png", new File("Screenshot.png"));
468+
} catch (IOException e) {
469+
e.printStackTrace();
470+
}
471+
}
472+
}
453473
}

0 commit comments

Comments
 (0)