Search in sources :

Example 1 with JavaFXLibraryNonFatalException

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

the class HelperFunctions method printFields.

public static void printFields(Object o, Class c) {
    try {
        Field[] fields = c.getDeclaredFields();
        if (fields.length > 0) {
            System.out.println("*HTML*Fields from class <b>" + c.getSimpleName() + "</b>:");
            System.out.println("<ul>");
            for (Field field : fields) {
                field.setAccessible(true);
                System.out.println("<li>" + field.getName() + " : " + field.get(o) + "</li>");
            }
            System.out.println("</ul>");
            System.out.println("");
        }
        if (c.getSuperclass() != null) {
            printFields(o, c.getSuperclass());
        }
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Couldn't get value of field");
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Field(java.lang.reflect.Field) TimeoutException(java.util.concurrent.TimeoutException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException)

Example 2 with JavaFXLibraryNonFatalException

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

the class HelperFunctions method callMethod.

public static Object callMethod(Object o, String method, boolean runLater) {
    robotLog("INFO", "Calling method " + method + " of object " + o);
    Class c = o.getClass();
    try {
        Method m = c.getMethod(method, null);
        try {
            if (!runLater) {
                return m.invoke(o, null);
            } else {
                Platform.runLater(() -> {
                    try {
                        m.invoke(o, null);
                    } catch (InvocationTargetException | IllegalAccessException e) {
                        throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
                    }
                });
            }
        } catch (InvocationTargetException | IllegalAccessException e) {
            throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
        }
    } catch (NoSuchMethodException e) {
        throw new JavaFXLibraryNonFatalException(c + " has no method \"" + method + "()\"");
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
    }
    return null;
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PseudoClass(javafx.css.PseudoClass) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeoutException(java.util.concurrent.TimeoutException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException)

Example 3 with JavaFXLibraryNonFatalException

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

the class HelperFunctions method callMethod.

public static Object callMethod(Object o, String method, List<Object> arguments, List<Object> argumentTypes, boolean runLater) {
    robotLog("INFO", "Calling method \"" + method + "\" of object \"" + o + "\" with arguments \"" + Arrays.toString(arguments.toArray()) + "\"");
    Class c = o.getClass();
    List<Class> aTypes = new ArrayList<>();
    for (Object className : argumentTypes) aTypes.add(parseClass((String) className));
    try {
        Method m = c.getMethod(method, aTypes.toArray(new Class[aTypes.size()]));
        if (!runLater) {
            try {
                return m.invoke(o, arguments.toArray());
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
            }
        } else {
            Platform.runLater(() -> {
                try {
                    m.invoke(o, arguments.toArray());
                } catch (IllegalAccessException | InvocationTargetException e) {
                    throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage());
                }
            });
        }
    } catch (NoSuchMethodException e) {
        throw new JavaFXLibraryNonFatalException(c + " has no method \"" + method + "\" with arguments " + Arrays.toString(aTypes.toArray()));
    } catch (Exception e) {
        throw new JavaFXLibraryNonFatalException("Couldn't execute Call Method: " + e.getMessage(), e);
    }
    return null;
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) PseudoClass(javafx.css.PseudoClass) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeoutException(java.util.concurrent.TimeoutException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException)

Example 4 with JavaFXLibraryNonFatalException

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

the class HelperFunctions method objectToBounds.

public static Bounds objectToBounds(Object object) {
    if (object instanceof Window) {
        return new BoundingBox(((Window) object).getX(), ((Window) object).getY(), ((Window) object).getWidth(), ((Window) object).getHeight());
    } else if (object instanceof Scene) {
        return new BoundingBox(((Scene) object).getX() + ((Scene) object).getWindow().getX(), ((Scene) object).getY() + ((Scene) object).getWindow().getY(), ((Scene) object).getWidth(), ((Scene) object).getHeight());
    } else if (object instanceof Point2D) {
        return robot.bounds((Point2D) object).query();
    } else if (object instanceof Node) {
        return robot.bounds((Node) object).query();
    } else if (object instanceof String) {
        waitUntilExists((String) object, waitUntilTimeout, "SECONDS");
        Node node = robot.lookup((String) object).query();
        return robot.bounds(node).query();
    } else if (object instanceof Bounds) {
        return (Bounds) object;
    } else if (object instanceof PointQuery) {
        return robot.bounds(((PointQuery) object).query()).query();
    } else if (object instanceof Rectangle2D) {
        Rectangle2D r2 = (Rectangle2D) object;
        return new BoundingBox(r2.getMinX(), r2.getMinY(), r2.getWidth(), r2.getHeight());
    } else
        throw new JavaFXLibraryNonFatalException("Unsupported parameter type: " + object.toString());
}
Also used : Window(javafx.stage.Window) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) Scene(javafx.scene.Scene) PointQuery(org.testfx.service.query.PointQuery)

Example 5 with JavaFXLibraryNonFatalException

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

the class HelperFunctions method waitUntilExists.

public static Node waitUntilExists(String target, int timeout, String timeUnit) {
    robotLog("TRACE", "Waiting until target \"" + target.toString() + "\" becomes existent, timeout=" + Integer.toString(timeout) + ", timeUnit=" + timeUnit);
    try {
        Awaitility.setDefaultTimeout(timeout, getTimeUnit(timeUnit));
        AtomicReference<Node> node = new AtomicReference<>();
        Awaitility.await().until(() -> {
            node.set(robot.lookup(target).query());
            return node.get() != null;
        });
        robotLog("TRACE", "Node located: \"" + node.get().toString() + "\"");
        return node.get();
    } catch (ConditionTimeoutException e) {
        throw new JavaFXLibraryNonFatalException("Given element \"" + target.toString() + "\" was not found within given timeout of " + Integer.toString(timeout) + " " + timeUnit);
    }
}
Also used : JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Node(javafx.scene.Node) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference)

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