use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method selectContextMenuItem.
@RobotKeyword("Clicks the given item from menu\n\n" + "``item`` is the name for the Context Menu item to be clicked. This keyword clicks the first menu item that matches the given " + "item name. Search of an item is started from the last target window.\n\n" + "Example:\n" + "| Click On | \\#menu-button-id | \n" + "| Select Context Menu Item | menu item name |")
@ArgumentNames({ "item" })
public void selectContextMenuItem(String item) {
List<Window> windows = robot.listTargetWindows();
ListIterator li = windows.listIterator(windows.size());
while (li.hasPrevious()) {
for (Node node : robot.rootNode((Window) li.previous()).lookupAll(".menu-item")) {
if (getMenuItemText(node).equals(item)) {
robot.clickOn(node, Motion.HORIZONTAL_FIRST);
return;
}
}
}
throw new JavaFXLibraryNonFatalException("unable to find menu item: " + item);
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method getSelectedTabPaneTab.
@RobotKeyword("Returns the selected TabPane Tab as a dictionary entry in form of 'name : Node' pair.\n\n" + "``locator`` is either a _query_ or _Object:Node_ for identifying the TabPane element, see " + "`3. Locating or specifying UI elements`. \n\n" + "\nExample:\n" + "| ${tab}= | Get Tab Pane Selected Tab | \\#pane-id | \n" + "| Dictionary Should contain Key | ${tab} | tab name | \n")
@ArgumentNames({ "locator" })
public Map<String, Object> getSelectedTabPaneTab(Object locator) {
robotLog("INFO", "Getting the selected tab from TabPane: " + locator);
Map<String, Object> tab = new HashMap<>();
try {
TabPane tabPane = (TabPane) objectToNode(locator);
tab.put(getSelectedTabName(tabPane), mapObject(getSelectedTab(tabPane)));
return tab;
} catch (ClassCastException cce) {
throw new JavaFXLibraryNonFatalException("Given locator: \"" + locator + "\" could not be handled as TabPane!", cce);
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class Verifiers method imagesShouldNotMatch.
@RobotKeyword("Fails if images are too similar\n\n" + "``image1`` is an _Object:Image_ for the first comparable image.\n\n" + "``image2`` is an _Object:Image_ for the second comparable image.\n\n" + "``percentage`` the percentage of pixels that should not match, defaults to 100.\n\n" + "This keyword can be coupled with e.g. `Capture Image` -keyword.")
@ArgumentNames({ "image1", "image2", "percentage=100" })
public void imagesShouldNotMatch(Image image1, Image image2, double percentage) {
robotLog("INFO", "Checking if " + percentage + "% of " + image1 + " differs with " + image2);
if (image1.getHeight() != image2.getHeight() || image1.getWidth() != image2.getWidth())
throw new JavaFXLibraryNonFatalException("Images must be same size to compare: Image1 is " + (int) image1.getWidth() + "x" + (int) image1.getHeight() + " and Image2 is " + (int) image2.getWidth() + "x" + (int) image2.getHeight());
PixelMatcherResult result = robotContext.getCaptureSupport().matchImages(image1, image2, new PixelMatcherRgb());
int nonSharedPixels = (int) (result.getNonMatchFactor() * 100);
robotLog("INFO", "Matching pixels: " + nonSharedPixels + "%");
if (nonSharedPixels < percentage)
throw new JavaFXLibraryNonFatalException("Images are too similar - Expected at least " + (int) percentage + "% " + "difference, got " + nonSharedPixels + "%");
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class Verifiers method imagesShouldMatch.
@RobotKeyword("Fails if images are not similar enough\n\n" + "``image1`` is an _Object:Image_ for the first comparable image.\n\n" + "``image2`` is an _Object:Image_ for the second comparable image.\n\n" + "``percentage`` the percentage of pixels that should match, defaults to 100.\n\n" + "This keyword can be coupled with e.g. `Capture Image` -keyword.")
@ArgumentNames({ "image1", "image2", "percentage=100" })
public void imagesShouldMatch(Image image1, Image image2, double percentage) {
robotLog("INFO", "Checking if " + percentage + "% of " + image1 + " matches with " + image2);
if (image1.getHeight() != image2.getHeight() || image1.getWidth() != image2.getWidth())
throw new JavaFXLibraryNonFatalException("Images must be same size to compare: Image1 is " + (int) image1.getWidth() + "x" + (int) image1.getHeight() + " and Image2 is " + (int) image2.getWidth() + "x" + (int) image2.getHeight());
PixelMatcherResult result = robotContext.getCaptureSupport().matchImages(image1, image2, new PixelMatcherRgb());
int sharedPixels = (int) (result.getMatchFactor() * 100);
robotLog("INFO", "Matching pixels: " + sharedPixels + "%");
if (sharedPixels < percentage)
throw new JavaFXLibraryNonFatalException("Images do not match - Expected at least " + (int) percentage + "% " + "similarity, got " + sharedPixels + "%");
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class Verifiers method waitUntilProgressBarIsFinished.
@RobotKeyword("Waits until given ProgressBar is finished or timeout expires. \n\n" + "``locator`` is either a _query_ or _Object:Node_ for identifying the ToggleButton element, see " + " `3. Locating or specifying UI elements`. \n\n" + "``timeout`` is an integer value for timeout in seconds, defaults to 20 seconds.")
@ArgumentNames({ "locator", "timeout=20" })
public static void waitUntilProgressBarIsFinished(Object locator, int timeout) {
try {
ProgressBar pb = (ProgressBar) objectToNode(locator);
waitForProgressBarToFinish(pb, timeout);
} catch (ClassCastException cce) {
throw new JavaFXLibraryNonFatalException("Unable to handle given locator as ProgressBar!");
}
}
Aggregations