8284619: javax/swing/JTable/8236907/LastVisibleRow.java failed with "Test Case Failed!!, Last Row not Visible!!!"

Reviewed-by: psadhukhan, honkar
This commit is contained in:
Tejesh R 2022-06-16 03:47:30 +00:00 committed by Prasanta Sadhukhan
parent a1795901ee
commit 39526e28bc
2 changed files with 22 additions and 52 deletions

View File

@ -679,7 +679,6 @@ javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 8274106 macosx-aarch64
sanity/client/SwingSet/src/ToolTipDemoTest.java 8225012 windows-all,macosx-all
sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java 8265770 macosx-all
javax/swing/JTable/8236907/LastVisibleRow.java 8284619 macosx-all
############################################################################

View File

@ -59,9 +59,7 @@ public class LastVisibleRow {
Point clkPoint;
try {
testRobot = new Robot();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
}
@ -75,14 +73,17 @@ public class LastVisibleRow {
mouseEvents(clkPoint);
testRobot.waitForIdle();
clearSelect();
testRobot.delay(1000);
testRobot.waitForIdle();
BufferedImage bufferedImageAfter = testRobot.createScreenCapture(getCaptureRect());
testRobot.delay(1000);
if (!compare(bufferedImageBefore, bufferedImageAfter)) {
ImageIO.write(bufferedImageBefore, "png", new File("bufferedImageBefore.png"));
ImageIO.write(bufferedImageAfter, "png", new File("bufferedImageAfter.png"));
ImageIO.write(bufferedImageBefore, "png",
new File("bufferedImageBefore.png"));
ImageIO.write(bufferedImageAfter, "png",
new File("bufferedImageAfter.png"));
throw new RuntimeException("Test Case Failed!!, Last Row not Visible!!!");
}
} finally {
@ -90,23 +91,14 @@ public class LastVisibleRow {
}
}
/*
*
* Get clickable screen point for particular row and column of a table
* param row Row Number
* param column Column Number
* return Point
*/
// Get clickable screen point for particular row and column of a table
private static Point getCellClickPoint(final int row, final int column) {
Point result;
Rectangle rect = table.getCellRect(row, column, false);
Point point = new Point(rect.x + rect.width / 2,
Point clickPoint = new Point(rect.x + rect.width / 2,
rect.y + rect.height / 2);
SwingUtilities.convertPointToScreen(point, table);
result = point;
SwingUtilities.convertPointToScreen(clickPoint, table);
return result;
return clickPoint;
}
private static void createAndShowGUI() {
@ -119,7 +111,10 @@ public class LastVisibleRow {
centerPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JPanel tablePaneContainer = new JPanel(new BorderLayout());
JPanel tablePane = new JPanel(new BorderLayout());
table = new JTable(new Object[][]{{"row_1_col_1", "row_1_col_2", "row_1_col_3"}, {"row_2_col_1", "row_2_col_2", "row_2_col_3"}, {"row_3_col_1", "row_3_col_2", "row_3_col_3"}, {"row_4_col_1", "row_4_col_2", "row_4_col_3"}}, new String[]{"Col1", "Col2", "Col3"});
table = new JTable(new Object[][]{{"row_1_col_1", "row_1_col_2", "row_1_col_3"},
{"row_2_col_1", "row_2_col_2", "row_2_col_3"}, {"row_3_col_1", "row_3_col_2",
"row_3_col_3"}, {"row_4_col_1", "row_4_col_2", "row_4_col_3"}},
new String[]{"Col1", "Col2", "Col3"});
table.setPreferredSize(new Dimension(0, (table.getRowHeight() * 3)));
tablePane.add(table.getTableHeader(), BorderLayout.NORTH);
@ -130,15 +125,10 @@ public class LastVisibleRow {
frame.setSize(400, 120);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
/*
*
* mouseEvents for last row click
*/
private static void mouseEvents(Point clkPnt) {
// mouseEvents for last row click
private static void mouseEvents(Point clkPnt) {
testRobot.mouseMove(clkPnt.x, clkPnt.y);
testRobot.delay(50);
testRobot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
@ -146,13 +136,8 @@ public class LastVisibleRow {
testRobot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
testRobot.delay(50);
}
/*
*
* getMousePosition Actions for last row click
* returns Point
* throws Exception
*/
// getMousePosition Actions for last row click
private static Point getMousePosition() throws Exception {
final Point[] clickPoint = new Point[1];
SwingUtilities.invokeAndWait(new Runnable() {
@ -164,12 +149,7 @@ public class LastVisibleRow {
return clickPoint[0];
}
/*
*
* Clears the selected table row
* throws Exception
*/
// Clears the selected table row
private static void clearSelect() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
@ -180,12 +160,7 @@ public class LastVisibleRow {
});
}
/*
* getCaptureRect Method - To Compute the Rectangle for
* Screen Capturing the Last Row for comparison
* return Rectangle
*/
// getCaptureRect Method - To Compute the Rectangle Area of last row
private static Rectangle getCaptureRect() throws InterruptedException, InvocationTargetException {
final Rectangle[] captureRect = new Rectangle[1];
SwingUtilities.invokeAndWait(new Runnable() {
@ -195,19 +170,15 @@ public class LastVisibleRow {
Point point = new Point(cellRect.x, cellRect.y);
SwingUtilities.convertPointToScreen(point, table);
captureRect[0] = new Rectangle(point.x, point.y, table.getColumnCount() * cellRect.width, cellRect.height);
captureRect[0] = new Rectangle(point.x+5, point.y+2,
table.getColumnCount() * cellRect.width - 10,
cellRect.height-2);
}
});
return captureRect[0];
}
/*
* Compare method - to compare two images.
* param bufferedImage1 Buffered Image Before click
* param bufferedImage2 Buffered Image After click
* return Boolean
*/
// Compare method - to compare two images.
static Boolean compare(BufferedImage bufferedImage1, BufferedImage bufferedImage2) {
if (bufferedImage1.getWidth() == bufferedImage2.getWidth()
&& bufferedImage1.getHeight() == bufferedImage2.getHeight()) {