Search in sources :

Example 16 with JavaFXLibraryNonFatalException

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

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

Example 18 with JavaFXLibraryNonFatalException

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

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

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

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