Search in sources :

Example 21 with JavaFXLibraryNonFatalException

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

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

Example 23 with JavaFXLibraryNonFatalException

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

the class ConvenienceKeywords method getTableColumnValues.

@RobotKeyword("Returns list of values 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> getTableColumnValues(Object locator, int column) {
    try {
        TableView table = (TableView) objectToNode(locator);
        ObservableList items = table.getItems();
        List<Object> values = new ArrayList<>();
        TableColumn tableColumn = (TableColumn) table.getColumns().get(column);
        if (tableColumn.getText() != null)
            robotLog("INFO", "Getting values from column " + tableColumn.getText());
        else
            robotLog("INFO", "Getting values from column using index " + column);
        for (Object item : items) {
            Object value = tableColumn.getCellObservableValue(item).getValue();
            values.add(mapObject(value));
        }
        return values;
    } catch (IndexOutOfBoundsException e) {
        throw new JavaFXLibraryNonFatalException("Out of table bounds: " + e.getMessage());
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Couldn't get column values: " + e.getMessage());
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) ObservableList(javafx.collections.ObservableList) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 24 with JavaFXLibraryNonFatalException

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

the class ConvenienceKeywords method findAllWithPseudoClass.

@RobotKeyword("Returns *all* nodes matching query AND given pseudo-class state. \r\n" + "``query`` is a query locator, see `3.1 Using queries`.\n\n" + "``pseudo`` is a String value specifying pseudo class value.\n\n" + "``failIfNotFound`` specifies if keyword should fail if nothing is found. By default it's false and " + "keyword returns null in case lookup returns nothing.\n\n" + "\nExample:\n" + "| ${my node}= | Find All With Pseudo Class | .check-box-tree-cell .check-box | selected | \n")
@ArgumentNames({ "query", "pseudo", "failIfNotFound=" })
public List<Object> findAllWithPseudoClass(String query, String pseudo, boolean failIfNotFound) {
    robotLog("INFO", "Trying to find all nodes with query: \"" + query + "\" that has pseudoclass state as: \"" + pseudo + "\", failIfNotFound= \"" + Boolean.toString(failIfNotFound) + "\"");
    try {
        Set<Node> nodes = robot.lookup(query).queryAll();
        Set<Node> matches = nodes.stream().filter(n -> n.getPseudoClassStates().stream().map(PseudoClass::getPseudoClassName).anyMatch(pseudo::contains)).collect(Collectors.toSet());
        return mapObjects(matches);
    } catch (JavaFXLibraryNonFatalException e) {
        if (failIfNotFound)
            throw e;
        return Collections.emptyList();
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Find all with pseudo class operation failed for query: \"" + query + "\" and pseudo: \"" + pseudo + "\"", e);
    }
}
Also used : RobotKeywords(org.robotframework.javalib.annotation.RobotKeywords) java.util(java.util) ListViewSkin(com.sun.javafx.scene.control.skin.ListViewSkin) PseudoClass(javafx.css.PseudoClass) javafx.scene.control(javafx.scene.control) BoundingBox(javafx.geometry.BoundingBox) HelperFunctions(javafxlibrary.utils.HelperFunctions) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames) Parent(javafx.scene.Parent) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) InstanceOfMatcher(javafxlibrary.matchers.InstanceOfMatcher) TestFxAdapter(javafxlibrary.utils.TestFxAdapter) Method(java.lang.reflect.Method) KeyCode(javafx.scene.input.KeyCode) Rectangle2D(javafx.geometry.Rectangle2D) Node(javafx.scene.Node) Motion(org.testfx.robot.Motion) VirtualFlow(com.sun.javafx.scene.control.skin.VirtualFlow) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) Screen(javafx.stage.Screen) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Stage(javafx.stage.Stage) RobotKeywordOverload(org.robotframework.javalib.annotation.RobotKeywordOverload) TableViewSkin(com.sun.javafx.scene.control.skin.TableViewSkin) Window(javafx.stage.Window) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) 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 25 with JavaFXLibraryNonFatalException

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

the class TestFxAdapter method createNewSession.

public void createNewSession(String appName, String... appArgs) {
    /* Applications using FXML-files for setting controllers must have
           FXMLLoader.setDefaultClassLoader(getClass().getClassLoader());
           in their start method for the controller class to load properly */
    if (appName.endsWith(".jar")) {
        try {
            JarFile jarFile = new JarFile(appName);
            String mainClassName = jarFile.getManifest().getMainAttributes().getValue("Main-Class");
            Enumeration<JarEntry> e = jarFile.entries();
            URL[] urls = { new URL("jar:file:" + appName + "!/") };
            URLClassLoader cl = URLClassLoader.newInstance(urls);
            while (e.hasMoreElements()) {
                JarEntry je = e.nextElement();
                if (je.isDirectory() || !je.getName().endsWith(".class"))
                    continue;
                String className = je.getName().substring(0, je.getName().length() - 6);
                className = className.replace('/', '.');
                if (className.equals(mainClassName)) {
                    Class c = cl.loadClass(className);
                    activeSession = new Session(c, appArgs);
                }
            }
        } catch (FileNotFoundException e) {
            throw new JavaFXLibraryNonFatalException("Couldn't find file: " + appName);
        } catch (ClassNotFoundException e) {
            throw new JavaFXLibraryNonFatalException("Couldn't find main application class in " + appName);
        } catch (IOException e) {
            throw new JavaFXLibraryNonFatalException(e);
        }
    } else {
        activeSession = new Session(appName, appArgs);
    }
    setRobot(activeSession.sessionRobot);
    setRobotContext(activeSession.robotContext());
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URL(java.net.URL) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) URLClassLoader(java.net.URLClassLoader)

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