Search in sources :

Example 11 with RobotKeyword

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

the class ConvenienceKeywords method getPrimaryScreenBounds.

@RobotKeyword("Returns the bounds of primary screen. \n")
public Object getPrimaryScreenBounds() {
    try {
        robotLog("INFO", "Getting the primary screen bounds");
        Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
        return mapObject(new BoundingBox(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()));
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Unable to get primary screen bounds.", e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) BoundingBox(javafx.geometry.BoundingBox) Rectangle2D(javafx.geometry.Rectangle2D) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword)

Example 12 with RobotKeyword

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

the class ConvenienceKeywords method getTableRowValues.

@RobotKeyword("Returns the given table row cells in a dictionary in form of name:node pairs. \n\n" + "``locator`` is either a _query_ or _Object:Node_ for identifying the TableView element, see " + "`3. Locating or specifying UI elements`. \n\n" + "``row`` Integer value for the column" + "\nExample:\n" + "| ${row cells}= | Get Table Row Cells | \\#table-id | ${2} | \n" + "| Dictionary Should Contain Key | ${row cells} | column name | \n" + "| ${cell text}= | Get Node Text | &{row cells}[column name] | # assuming that cell is a node that has a text value |\n")
@ArgumentNames({ "table", "row" })
public List<Object> getTableRowValues(Object locator, int rowNumber) {
    robotLog("INFO", "Getting values from table row: " + rowNumber);
    try {
        TableView table = (TableView) objectToNode(locator);
        Object row = table.getItems().get(rowNumber);
        List<Object> values = new ArrayList<>();
        for (Object tableColumn : table.getColumns()) {
            values.add(((TableColumn) tableColumn).getCellObservableValue(row).getValue());
        }
        return values;
    } catch (ClassCastException cce) {
        throw new JavaFXLibraryNonFatalException("Unable to handle argument as TableView!");
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 13 with RobotKeyword

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

the class ConvenienceKeywords method getNodeText.

@RobotKeyword("Returns text value of the Node. \n\n" + "``locator`` is either a _query_ or _Object_ for a node whose getText method will be called, see " + "`3. Locating or specifying UI elements`. \n\n")
@ArgumentNames({ "locator" })
public String getNodeText(Object locator) {
    Object node = objectToNode(locator);
    // if(object instanceof String)
    // object = robot.lookup((String)object).query();
    robotLog("INFO", "Getting text value for node: \"" + node.toString() + "\"");
    Class c = node.getClass();
    try {
        Method[] methods = c.getMethods();
        for (Method m : methods) {
            // There are two versions of getText: getText() and getText(int, int)
            if (m.getName().equals("getText") && m.getParameterCount() == 0) {
                robotLog("TRACE", "Calling method getText() for node: \"" + node.toString() + "\"");
                try {
                    Object result = m.invoke(node);
                    return result.toString();
                } catch (Exception e) {
                    // Return empty string in case cannot get text from node
                    return "";
                // throw new JavaFXLibraryNonFatalException("Problem calling method getText() ", e);
                }
            }
        }
        throw new JavaFXLibraryNonFatalException("Get node text failed for node: \"" + node.toString() + "\". Node has no method getText().");
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException)
            throw e;
        throw new JavaFXLibraryNonFatalException("Get node text failed for node: " + node.toString(), e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PseudoClass(javafx.css.PseudoClass) Method(java.lang.reflect.Method) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 14 with RobotKeyword

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

the class ConvenienceKeywords method printChildNodes.

@RobotKeyword("Prints all child nodes starting from a given node.\n\n" + "Optional argument ``root`` is the starting point from where to start listing child nodes. It can be either a _query_ or _Object_, " + "see `3.1 Using queries` and `3.2 Using objects`. Defaults to root node of current window. \n\n" + "\nExample:\n" + "| ${my node}= | Find | \\#node-id | \n" + "| Print Child Nodes | ${my node} | \n")
@ArgumentNames({ "root=" })
public void printChildNodes(Object root) {
    try {
        robotLog("INFO", "Printing tree structure for node: \"" + root.toString() + "\"");
        printTreeStructure((Parent) objectToNode(root));
    } catch (ClassCastException e) {
        throw new JavaFXLibraryNonFatalException(root.getClass() + " is not a subclass of javafx.scene.Parent");
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 15 with RobotKeyword

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

the class ConvenienceKeywords method getContextMenuItems.

@RobotKeyword("Returns context menu items as a dictionary containing menu name:node pairs. \n\n" + "Optional parameter ``locator`` is an _Object:Window_ for specifying which contextMenu(window) items should be collected. " + "Default value is the last window returned by `Get Target Windows` -keyword. \n" + "\nExamples:\n" + "| Click On | \\#menu-button-id | \n" + "| ${menu items}= | Get Context Menu Items | \n" + "| Dictionary Should Contain Key | ${menu items} | menu item name" + "| Click On | &{menu items}[menu item name] | \n\n")
@ArgumentNames({ "locator=" })
public Map<String, Object> getContextMenuItems(Window window) {
    try {
        ContextMenu cm = (ContextMenu) window;
        Map<String, Object> menuItems = new HashMap<>();
        for (Node node : robot.rootNode(window).lookupAll(".menu-item")) {
            menuItems.put(getMenuItemText(node), mapObject(node));
        }
        return menuItems;
    } catch (ClassCastException cce) {
        throw new JavaFXLibraryNonFatalException("Unable to handle target as ContextMenu!");
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) 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