Search in sources :

Example 36 with JavaFXLibraryNonFatalException

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);
}
Also used : Window(javafx.stage.Window) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 37 with JavaFXLibraryNonFatalException

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);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 38 with JavaFXLibraryNonFatalException

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 + "%");
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PixelMatcherResult(org.testfx.service.support.PixelMatcherResult) PixelMatcherRgb(org.testfx.service.support.impl.PixelMatcherRgb)

Example 39 with JavaFXLibraryNonFatalException

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 + "%");
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PixelMatcherResult(org.testfx.service.support.PixelMatcherResult) PixelMatcherRgb(org.testfx.service.support.impl.PixelMatcherRgb)

Example 40 with JavaFXLibraryNonFatalException

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!");
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException)

Aggregations

JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)46 RobotKeyword (org.robotframework.javalib.annotation.RobotKeyword)32 ArgumentNames (org.robotframework.javalib.annotation.ArgumentNames)28 Node (javafx.scene.Node)15 Method (java.lang.reflect.Method)6 TimeoutException (java.util.concurrent.TimeoutException)6 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 PseudoClass (javafx.css.PseudoClass)5 Window (javafx.stage.Window)5 Scene (javafx.scene.Scene)4 JavaFXLibraryFatalException (javafxlibrary.exceptions.JavaFXLibraryFatalException)4 BoundingBox (javafx.geometry.BoundingBox)3 Image (javafx.scene.image.Image)3 TableViewSkin (com.sun.javafx.scene.control.skin.TableViewSkin)2 VirtualFlow (com.sun.javafx.scene.control.skin.VirtualFlow)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 JarFile (java.util.jar.JarFile)2 ObservableList (javafx.collections.ObservableList)2