Search in sources :

Example 6 with RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.

the class ApplicationLauncher method launchJavafxApplication.

@RobotKeyword("Launches JavaFX application with the given arguments.\n\n" + "``appName`` is the name of the application to launch. \n\n" + "``appArgs`` is a list of arguments to be passed for the application. \n\n" + "Example:\n" + "| Launch JavaFX Application | _javafxlibrary.testapps.MenuApp_ |\n")
@ArgumentNames({ "appName", "*args" })
public void launchJavafxApplication(String appName, String... appArgs) {
    try {
        HelperFunctions.robotLog("INFO", "Starting application:" + appName);
        createNewSession(appName, appArgs);
        HelperFunctions.robotLog("INFO", "Application: " + appName + " started.");
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Unable to launch application: " + appName, e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryFatalException(javafxlibrary.exceptions.JavaFXLibraryFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 7 with RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.

the class ApplicationLauncher method closeJavafxApplication.

@RobotKeyword("Closes JavaFX application.\n\n" + "Example:\n" + "| Close JavaFX Application | \n")
public void closeJavafxApplication() {
    try {
        HelperFunctions.robotLog("INFO", "Closing application...");
        deleteSession();
        HelperFunctions.robotLog("INFO", "Application closed.");
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Unable to close Java FX application.", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryFatalException(javafxlibrary.exceptions.JavaFXLibraryFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword)

Example 8 with RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.

the class ConvenienceKeywords method getNodeImageUrl.

@RobotKeyword("Returns image name and path of the node. \n\n" + "``locator`` is either a _query_ or _Object_ for a node whose getHeight method will be called, see " + "`3. Locating or specifying UI elements`. \n\n" + "Returns full image path by subsequently calling impl_getUrl -method. \n\n" + "Note, impl_getUrl -method is deprecated! Support for this method will be removed from Java in the future.")
@ArgumentNames({ "node" })
public String getNodeImageUrl(Object locator) {
    Node node = objectToNode(locator);
    robotLog("INFO", "Getting image url from node: \"" + node.toString() + "\"");
    try {
        Method[] methods = node.getClass().getMethods();
        for (Method m : methods) {
            if (m.getName().equals("getImage") && m.getParameterCount() == 0) {
                robotLog("TRACE", "Method getImage() found. Invoking it on node: \"" + node.toString() + "\"");
                try {
                    Object result = m.invoke(node, null);
                    Image image = (Image) result;
                    robotLog("TRACE", "Calling deprecated method impl_getUrl() for image: \"" + image.toString() + "\"");
                    return image.impl_getUrl();
                } catch (Exception e) {
                    throw new JavaFXLibraryNonFatalException("Problem calling method: .getImage(): " + e.getMessage(), e);
                }
            }
        }
        throw new JavaFXLibraryNonFatalException("Get node image url failed for node: \"" + node.toString() + "\". Element has no method impl_getUrl()");
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException)
            throw e;
        throw new JavaFXLibraryNonFatalException("Unable to get node image url for node: \"" + node.toString() + "\"", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) Method(java.lang.reflect.Method) Image(javafx.scene.image.Image) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 9 with RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.

the class ConvenienceKeywords method switchWindow.

/*
     * TODO: Switching between test applications using CMD + TAB doesn't work on Mac
     * cmd + tab moves between top level applications and multiple JavaFX applications launched by the testing framework
     * are bundled under a single tab named Java.
     */
@RobotKeyword("Presses ALT/CMD + TAB for the given amount of times. \n\n" + "``switchAmount`` is an Integer value and specifies how many switches will be made in total")
@ArgumentNames({ "switchAmount" })
public void switchWindow(int switchAmount) {
    robotLog("INFO", "Switching window for: \"" + Integer.toString(switchAmount) + "\" times.");
    try {
        if (isMac()) {
            robot.press(KeyCode.META);
        } else {
            robot.press(KeyCode.ALT);
        }
        for (int i = 0; i < switchAmount; i++) {
            robot.push(KeyCode.TAB);
        }
        robot.release(KeyCode.META);
        robot.release(KeyCode.ALT);
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Unable to switch window.", 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 RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.

the class ConvenienceKeywords method getTableColumnCells.

@RobotKeyword("Returns a list of *visible* cells(Nodes) of the given table column.\n\n" + "``locator`` is either a _query_ or _Object:Node_ for identifying the TableView element, see " + "`3. Locating or specifying UI elements`. \n\n" + "``column`` Integer value for the column")
@ArgumentNames({ "table", "column" })
public List<Object> getTableColumnCells(Object locator, int column) {
    try {
        TableView table = (TableView) objectToNode(locator);
        List<Object> columnCells = new ArrayList<>();
        VirtualFlow<?> vf = (VirtualFlow<?>) ((TableViewSkin<?>) table.getSkin()).getChildren().get(1);
        for (int i = vf.getFirstVisibleCell().getIndex(); i < vf.getLastVisibleCell().getIndex() + 1; i++) {
            robotLog("INFO", "index number: " + Integer.toString(i));
            columnCells.add(mapObject(vf.getCell(i).getChildrenUnmodifiable().get(column)));
        }
        return mapObjects(columnCells);
    } catch (ClassCastException cce) {
        throw new JavaFXLibraryNonFatalException("Unable to handle argument as TableView!");
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) TableViewSkin(com.sun.javafx.scene.control.skin.TableViewSkin) VirtualFlow(com.sun.javafx.scene.control.skin.VirtualFlow) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Aggregations

RobotKeyword (org.robotframework.javalib.annotation.RobotKeyword)34 JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)33 ArgumentNames (org.robotframework.javalib.annotation.ArgumentNames)30 Node (javafx.scene.Node)10 JavaFXLibraryFatalException (javafxlibrary.exceptions.JavaFXLibraryFatalException)5 Method (java.lang.reflect.Method)4 Window (javafx.stage.Window)4 PseudoClass (javafx.css.PseudoClass)3 BoundingBox (javafx.geometry.BoundingBox)3 Scene (javafx.scene.Scene)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 ObservableList (javafx.collections.ObservableList)2 Bounds (javafx.geometry.Bounds)2 Rectangle2D (javafx.geometry.Rectangle2D)2 InstanceOfMatcher (javafxlibrary.matchers.InstanceOfMatcher)2 ListViewSkin (com.sun.javafx.scene.control.skin.ListViewSkin)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1