--- old/application/uitests/org.openjdk.jmc.test.jemmy/src/test/java/org/openjdk/jmc/test/jemmy/misc/wrappers/MCButton.java 2019-10-22 09:27:24.488193139 -0400 +++ new/application/uitests/org.openjdk.jmc.test.jemmy/src/test/java/org/openjdk/jmc/test/jemmy/misc/wrappers/MCButton.java 2019-10-22 09:27:24.331190895 -0400 @@ -36,6 +36,7 @@ import java.util.List; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -61,6 +62,45 @@ } /** + * Finds a button in the supplied shell by image and returns it. + * + * @param shell + * the shell where to search for the button + * @param image + * the image to look up the button with + * @return a {@link MCButton} (possibly null) + */ + @SuppressWarnings("unchecked") + public static MCButton getByImage(Wrap shell, Image image) { + List> allVisibleButtonWraps = getVisible( + shell.as(Parent.class, Button.class).lookup(Button.class)); + for (final Wrap buttonWrap : allVisibleButtonWraps) { + Fetcher fetcher = new Fetcher() { + @Override + public void run() { + setOutput(buttonWrap.getControl().getImage()); + } + }; + Display.getDefault().syncExec(fetcher); + if (image.equals(fetcher.getOutput())) { + return new MCButton(buttonWrap); + } + } + return null; + } + + /** + * Finds a button in the default Mission Control shell and returns it. + * + * @param image + * the image of the button + * @return a {@link MCButton} in the default shell matching the image. + */ + public static MCButton getByImage(Image image) { + return getByImage(getShell(), image); + } + + /** * Finds a button in the default Mission Control shell and returns it. * * @param label @@ -96,6 +136,19 @@ } /** + * Finds a button in a shell with the given text and returns it. + * + * @param label + * the label string of the button + * @param shellText + * the text to look up the shell that the button is contained in + * @return a {@link MCButton} in the shell matching the label + */ + public static MCButton getByLabel(String shellText, String label) { + return getByLabel(getShellByText(shellText), label); + } + + /** * Finds a button by button label and returns it * * @param shell