Search in sources :

Example 26 with RobotKeyword

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

the class ConvenienceKeywords method findClass.

@RobotKeyword("Returns the *first* node matching the query. \n\n" + "``query`` is the Class name String to use in lookup.\n" + "\nExample:\n" + "| ${my node}= | Find | javafx.scene.control.Button | # button class |")
@ArgumentNames({ "query" })
public Object findClass(final String query) {
    try {
        Class<?> clazz = Class.forName(query);
        InstanceOfMatcher matcher = new InstanceOfMatcher(clazz);
        return mapObject(robot.lookup(matcher).query());
    } catch (Exception e) {
        robotLog("TRACE", "Problem has occurred during node lookup: " + e);
        return "";
    }
}
Also used : InstanceOfMatcher(javafxlibrary.matchers.InstanceOfMatcher) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 27 with RobotKeyword

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

the class ConvenienceKeywords method selectTabPaneTab.

@RobotKeyword("Selects the given Tab from TabPane" + "``locator`` is either a _query_ or _Object:Node_ for identifying the TabPane element, see " + "`3. Locating or specifying UI elements`. \n\n" + "``tabName`` is the name of the tab to be selected\n" + "\nExamples:\n" + "| Select Tab Pane Tab | ${Tab Pane} | tab name | \n" + "| Select Tab Pane Tab | \\#tab-id | tab name | \n")
@ArgumentNames({ "locator", "tabName" })
public void selectTabPaneTab(Object locator, String tabName) {
    robotLog("INFO", "Selecting tab: \"" + tabName + "\" from TabPane: \"" + locator + "\"");
    try {
        Node headerArea = getTabPaneHeaderArea((TabPane) objectToNode(locator));
        for (Node node : headerArea.lookupAll(".tab .tab-label")) {
            if (node instanceof Labeled) {
                String tabLabel = ((Labeled) node).getText();
                if (tabLabel != null) {
                    if (tabLabel.equals(tabName)) {
                        robotLog("TRACE", "Clicking on node: " + node);
                        robot.clickOn(node);
                        return;
                    }
                }
            }
        }
        throw new JavaFXLibraryNonFatalException("Unable to find a tab with name: " + tabName);
    } catch (ClassCastException cce) {
        throw new JavaFXLibraryNonFatalException("Given locator: \"" + locator + "\" could not be handled as TabPane!", cce);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 28 with RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword 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 29 with RobotKeyword

use of org.robotframework.javalib.annotation.RobotKeyword 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 30 with RobotKeyword

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

the class ClickRobot method clickOnCoordinates.

@RobotKeyword("Moves mouse directly to the given coordinates and clicks the primary mouse button\n\n" + "``x`` and ``y`` defines the coordinates as integer values. \n\n" + "Optional argument ``motion`` defines how mouse pointer is moved to target. Defaults to _DIRECT_.")
@ArgumentNames({ "x", "y", "motion=DIRECT" })
public FxRobotInterface clickOnCoordinates(int x, int y, String motion) {
    robotLog("INFO", "Clicking on coordinates x=\"" + Integer.toString(x) + "\"" + ", y=\"" + Integer.toString(y) + "\"" + " and motion=\"" + motion + "\"");
    checkClickLocation(x, y);
    try {
        return robot.clickOn((double) x, (double) y, getMotion(motion), MouseButton.PRIMARY);
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException) {
            throw e;
        }
        throw new JavaFXLibraryNonFatalException("Unable to click on coordinates: " + Integer.toString(x) + " " + Integer.toString(y), e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) 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