Search in sources :

Example 6 with JavaFXLibraryNonFatalException

use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.

the class HelperFunctions method getSelectedTabName.

public static String getSelectedTabName(TabPane tabPane) {
    robotLog("INFO", "Getting selected tab name");
    for (Node node : getTabPaneHeaderArea(tabPane).lookupAll(".tab")) {
        robotLog("INFO", "checking the name for: " + node);
        robotLog("INFO", "Styles: " + Arrays.asList(node.getPseudoClassStates()));
        if (node.getPseudoClassStates().stream().map(PseudoClass::getPseudoClassName).anyMatch("selected"::contains))
            return getTabName(node);
    }
    throw new JavaFXLibraryNonFatalException("Unable to get tab name");
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node)

Example 7 with JavaFXLibraryNonFatalException

use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.

the class HelperFunctions method waitUntilVisible.

public static Node waitUntilVisible(Object target, int timeout) {
    // if target is a query string, let's try to find the relevant node
    if (target instanceof String)
        target = waitUntilExists((String) target, timeout, "SECONDS");
    final Object finalTarget = target;
    robotLog("TRACE", "Waiting until target \"" + target.toString() + "\" becomes visible, timeout=" + Integer.toString(timeout));
    try {
        WaitForAsyncUtils.waitFor((long) timeout, TimeUnit.SECONDS, () -> Matchers.is(isVisible()).matches(finalTarget));
        return (Node) target;
    } catch (JavaFXLibraryNonFatalException nfe) {
        throw nfe;
    } catch (TimeoutException te) {
        throw new JavaFXLibraryNonFatalException("Given target \"" + target.toString() + "\" did not become visible within given timeout of " + Integer.toString(timeout) + " seconds.");
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Something went wrong while waiting target to be visible: " + e.getMessage());
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) TimeoutException(java.util.concurrent.TimeoutException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException)

Example 8 with JavaFXLibraryNonFatalException

use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.

the class ScreenCapturing method captureImage.

@RobotKeyword("Returns a screenshot of the given locator.\n\n" + "``locator`` is either a _query_ or _Object:Bounds, Node, Point2D, Rectangle, PointQuery, Scene, Window_ for identifying the element, see " + "`3. Locating or specifying UI elements`. \n\n" + "Argument ``logImage`` is a boolean value that specifies whether a captured image is also printed to test execution log. \n\n " + "\nExample:\n" + "| ${region}= | Create Rectangle | 11 | 22 | 33 | 44 | \n" + "| ${capture}= | Capture Image | ${region} | \n" + "| ${capture}= | Capture Image | ${node} | \n" + "| ${capture}= | Capture Image | ${window} | \n" + "| ${capture}= | Capture Image | \\#id | logImage=False |\n")
@ArgumentNames({ "locator", "logImage=True" })
public Object captureImage(Object locator, boolean logImage) {
    if (locator == null)
        throw new JavaFXLibraryNonFatalException("Unable to capture image, given locator was null!");
    robotLog("INFO", "Capturing screenshot from locator: \"" + locator.toString() + "\"");
    Image image = null;
    Bounds targetBounds = objectToBounds(locator);
    try {
        image = robot.capture(targetBounds).getImage();
        Path path = createNewImageFileNameWithPath();
        robotContext.getCaptureSupport().saveImage(image, path);
        if (logImage) {
            Double printSize = (targetBounds.getWidth() > 800) ? 800 : targetBounds.getWidth();
            System.out.println("*HTML* <img src=\"" + path + "\" width=\"" + printSize + "px\">");
        }
        return mapObject(image);
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException)
            throw e;
        throw new JavaFXLibraryNonFatalException("Unable to take capture : \"" + locator.toString() + "\"", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Path(java.nio.file.Path) Bounds(javafx.geometry.Bounds) Image(javafx.scene.image.Image) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 9 with JavaFXLibraryNonFatalException

use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.

the class ScrollRobot method scrollHorizontally.

/*
     *    Current version of TestFX uses java.awt.Robots mouseWheel-method for scrolling, which only supports
     *    vertical scrolling. This solution uses SHIFT + MWHEEL combination for horizontal scrolling. Note that this
     *    combination does not work out of the box on Linux desktops.
     */
@RobotKeyword("Scrolls horizontally by amount (in terms of ticks of a mouse wheel) in given direction.\n\n" + "``amount`` is the number of scroll ticks, defaults to 1. \n\n" + "``direction`` specifies whether to scroll RIGHT or LEFT. \n\n" + "\nExample:\n" + "| Move To | ${some node} | \n" + "| Scroll Horizontally | RIGHT | \n")
@ArgumentNames({ "direction", "amount=1" })
public void scrollHorizontally(String direction, int amount) {
    try {
        HelperFunctions.robotLog("INFO", "Scrolling \"" + direction + "\" by \"" + Integer.toString(amount) + "\" ticks.");
        robot.press(KeyCode.SHIFT);
        robot.scroll(amount, HelperFunctions.getHorizontalDirection(direction));
        robot.release(KeyCode.SHIFT);
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException)
            throw e;
        throw new JavaFXLibraryNonFatalException("Unable to scroll horizontally to direction: \"" + direction + "\"", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 10 with JavaFXLibraryNonFatalException

use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.

the class WindowLookup method getWindow.

@RobotKeyword("Returns window object.\n\n" + "``locator`` is either a _query_ or _Object:Node, Scene_ for identifying the Window. In addition to normal _query_, " + "locator can be a search string for _pattern=_, _title=_ or Integer number. See `3. Locating or specifying UI elements`. \n\n" + "\nExamples for different kind of locators: \n\n" + "Pattern (defaults to title):\n" + "| ${window}= | Get Window | My window title | \n" + "| ${window}= | Get Window | title=My window title | \n" + "| ${window}= | Get Window | pattern=W[i-w]{5} Title | \n\n" + "Index:\n" + "| ${window}= | Get Window | 0 | \n" + "| ${window}= | Get Window | ${2} | \n\n" + "Node:\n" + "| ${some_node}= | Find | \\#some_id | \n" + "| ${window}= | Get Window | ${some_node} | \n\n" + "Scene: \n" + "| ${some_scene}= | Get Nodes Scene | ${some_node} | \n" + "| ${window}= | Get Window | ${some_scene} | \n")
@ArgumentNames({ "locator" })
public Object getWindow(Object locator) {
    try {
        if (locator instanceof String) {
            if (((String) locator).startsWith("pattern=")) {
                locator = ((String) locator).replace("pattern=", "");
                HelperFunctions.robotLog("INFO", "Getting window with pattern \"" + locator + "\"");
                return HelperFunctions.mapObject(robot.window((String) locator));
            } else if (((String) locator).matches("[0-9]+")) {
                return getWindow(Integer.parseInt(locator.toString()));
            } else {
                if (((String) locator).startsWith("title=")) {
                    locator = ((String) locator).replace("title=", "");
                }
                HelperFunctions.robotLog("INFO", "Getting window with title \"" + locator + "\"");
                return HelperFunctions.mapObject(robot.window((String) locator));
            }
        }
        if (locator instanceof Node) {
            HelperFunctions.robotLog("INFO", "Getting window with node \"" + locator.toString() + "\"");
            return HelperFunctions.mapObject(robot.window((Node) locator));
        }
        if (locator instanceof Scene) {
            HelperFunctions.robotLog("INFO", "Getting window with scene \"" + locator.toString() + "\"");
            return HelperFunctions.mapObject(robot.window((Scene) locator));
        }
        if (locator instanceof Integer) {
            HelperFunctions.robotLog("INFO", "Getting window with index \"" + locator.toString() + "\"");
            return HelperFunctions.mapObject(robot.window((Integer) locator));
        }
        throw new JavaFXLibraryNonFatalException("Unable to handle argument \"" + locator.toString() + "\"");
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException)
            throw e;
        throw new JavaFXLibraryNonFatalException("Unable to find window: \"" + locator.toString() + "\"", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) Scene(javafx.scene.Scene) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

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