Search in sources :

Example 31 with JavaFXLibraryNonFatalException

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

the class ConvenienceKeywords method getTabPaneTabs.

@RobotKeyword("Returns a dictionary containing key:value pairs for each tab name and tab content(Node).\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" + "| ${tabs}= | Get Tab pane Tabs | \\#tab-pane-id | \n" + "| Dictionary Should Contain Key | ${tabs} | tab name | \n")
@ArgumentNames({ "locator" })
public Map<String, Object> getTabPaneTabs(Object locator) {
    robotLog("INFO", "Getting a dictionary for all tabs in TabPane: " + locator);
    try {
        TabPane tabPane = (TabPane) objectToNode(locator);
        Map<String, Object> tabs = new HashMap<>();
        int i = tabPane.getTabs().size() - 1;
        for (Node node : tabPane.getChildrenUnmodifiable()) {
            if (node.getStyleClass().contains("tab-content-area")) {
                tabs.put(getTabHeaderText(tabPane, i), mapObject(node));
                i--;
            }
        }
        return tabs;
    } 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 32 with JavaFXLibraryNonFatalException

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

the class ConvenienceKeywords method getNodeChildrenByClassName.

// TODO: Should this be deleted? Find All From Node has the same functionality
@RobotKeyword("Returns *all* descendant nodes of given node matching the given Java class name. \n\n" + "``locator`` is either a _query_ or _Object_ for node whose children will be queried, see " + "`3. Locating or specifying UI elements`. \n\n" + "``className`` is the Java class name to look for.\n" + "\nExample:\n" + "| ${panes}= | Get Node Children By Class Name | ${some node} | BorderPane | \n" + "Returns an empty list if none is found. \n")
@ArgumentNames({ "node", "className" })
public Set<Object> getNodeChildrenByClassName(Object locator, String className) {
    Node node = objectToNode(locator);
    robotLog("INFO", "Getting node: \"" + node.toString() + "\" children by class name: \"" + className + "\"");
    try {
        Set<Object> keys = new HashSet<Object>();
        Set childNodes = node.lookupAll("*");
        Iterator iter = childNodes.iterator();
        while (iter.hasNext()) {
            Node childNode = (Node) iter.next();
            if (childNode.getClass().getSimpleName().equals(className)) {
                robotLog("TRACE", "Classname: \"" + className + "\" found: \"" + childNode.toString() + "\"");
                keys.add(mapObject(childNode));
            }
        }
        return keys;
    } catch (Exception e) {
        if (e instanceof JavaFXLibraryNonFatalException)
            throw e;
        throw new JavaFXLibraryNonFatalException("Unable to get node children for node: \"" + node.toString() + "\" with class name: " + className, e);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 33 with JavaFXLibraryNonFatalException

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

the class ConvenienceKeywords method listNodeMethods.

@RobotKeyword("Lists methods available for given node.\n" + "``node`` is the Object:Node which methods to list, see `3.2 Using objects`. \n\n" + "When working with custom components you may use this keyword to discover methods you can call " + "with `Call Method` keyword.\n\n" + "Example:\n" + "| List Component Methods | ${my node} |\n")
@ArgumentNames({ "node" })
public String[] listNodeMethods(Node node) {
    robotLog("INFO", "Listing all available methods for node: \"" + node.toString() + "\"");
    try {
        Class klass = node.getClass();
        ArrayList<String> list = new ArrayList<String>();
        System.out.println("*INFO*");
        while (klass != null) {
            String name = String.format("\n*%s*\n", klass.getName());
            System.out.println(name);
            list.add(name);
            for (Method m : klass.getDeclaredMethods()) {
                String entry = getMethodDescription(m);
                System.out.println(entry);
                list.add(entry);
            }
            klass = klass.getSuperclass();
        }
        return list.toArray(new String[list.size()]);
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Listing node methods failed.", 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 34 with JavaFXLibraryNonFatalException

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

the class ConvenienceKeywords method getTableRowCells.

@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 Map<String, Object> getTableRowCells(Object locator, int row) {
    robotLog("INFO", "Getting cell nodes from table row: " + row);
    try {
        TableView table = (TableView) objectToNode(locator);
        Map<String, Object> cells = new HashMap<>();
        for (int i = 0; i < table.getColumns().size(); i++) {
            cells.put(getTableColumnName(table, i), mapObject(getTableRowCell(table, row, i)));
        }
        return cells;
    } 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 35 with JavaFXLibraryNonFatalException

use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException 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)

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