use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class WindowTargeting method setTargetWindow.
@RobotKeyword("Sets active target window\n\n" + "``locator`` is either a _query_ or _Object:Node, Scene_ for identifying the Window. In addition to normal _query_, " + "locator can be a search string for _pattern=_, _title=_ or Integer number. See `3. Locating or specifying UI elements`. \n\n" + "\nExamples for different kind of locators: \n\n" + "pattern (defaults to title):\n" + "| Set Target Window | My window title | \n" + "| Set Target Window | title=My window title | \n" + "| Set Target Window | pattern=W[i-w]{5} Title | \n\n" + "Index:\n" + "| Set Target Window | 0 | \n" + "| Set Target Window | ${2} | \n\n" + "Node:\n" + "| ${some_node}= | Find | \\#some_id | \n" + "| Set Target Window | ${some_node} | \n\n" + "Scene: \n" + "| ${some_scene}= | Get Nodes Scene | ${some_node} | \n" + "| Set Target Window | ${some_scene} | \n")
@ArgumentNames("locator")
public void setTargetWindow(Object locator) {
try {
if (locator instanceof String) {
if (((String) locator).startsWith("pattern=")) {
locator = ((String) locator).replace("pattern=", "");
HelperFunctions.robotLog("DEBUG", "String which is pattern, converting...");
setTargetWindow((Pattern) Pattern.compile((String) locator));
} else if (((String) locator).matches("[0-9]+")) {
HelperFunctions.robotLog("DEBUG", "String which is integer, converting...");
setTargetWindow(Integer.parseInt(locator.toString()));
} else {
if (((String) locator).startsWith("title=")) {
locator = ((String) locator).replace("title=", "");
}
HelperFunctions.robotLog("INFO", "Setting target window with title \"" + locator + "\"");
robot.targetWindow((String) locator);
}
}
if (locator instanceof Window) {
HelperFunctions.robotLog("INFO", "Setting target window according to window \"" + locator.toString() + "\"");
robot.targetWindow((Window) locator);
}
if (locator instanceof Integer) {
HelperFunctions.robotLog("INFO", "Setting target window according to window index \"" + locator.toString() + "\"");
robot.targetWindow((Integer) locator);
}
if (locator instanceof Scene) {
HelperFunctions.robotLog("INFO", "Setting target window according to window scene \"" + locator.toString() + "\"");
robot.targetWindow((Scene) locator);
}
if (locator instanceof Node) {
HelperFunctions.robotLog("INFO", "Setting target window according to window node \"" + locator.toString() + "\"");
robot.targetWindow((Node) locator);
}
if (locator instanceof Pattern) {
HelperFunctions.robotLog("INFO", "Setting target window according to window title pattern \"" + locator.toString() + "\"");
robot.targetWindow((Pattern) locator);
}
Platform.runLater((robot.targetWindow())::requestFocus);
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException)
throw e;
throw new JavaFXLibraryNonFatalException("Unable to set target window: \"" + locator.toString() + "\"", e);
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class BoundsLocation method getBounds.
/*
TestFX has a bug in BoundQueryUtils boundsOnScreen(Bounds b, Window w) method which causes window location data
to be incorrect. Problem is that the method first takes windows location with getMinX() and getMinY() (that
already return the location on the screen) and then add an extra offset (getMinX() and getMinY() again) to them.
This results the coordinates to be always twice as large than they should be.
This bug also affects bounds(Scene s) method, as it uses the buggy boundsOnScreen to count the offset for the
scene. Both of these method calls have been replaced with pure JavaFX, and shouldn't be affected in any way in
case TestFX gets changed.
Details:
- version: testfx-core 4.0.6-alpha
- location: main/java/org/testfx/api/util/BoundsQueryUtils.java: rows 153-160
*/
@RobotKeyword("Returns a Bounds object for a region located using given locator. \n\n" + "``locator`` is either a _query_ or _Object:Node, Point2D, Scene, or Window_ for identifying the region" + ", see `3. Locating or specifying UI elements`. \n\n" + "\nExample:\n" + "| ${bounds}= | Get Bounds | ${node} | \n" + "| ${target}= | Create Bounds | 150 | 150 | 200 | 200 | \n" + "| Should Be Equal | ${bounds} | ${target} | \n")
@ArgumentNames({ "locator", "logLevel=" })
public Object getBounds(Object locator, String logLevel) {
try {
if (locator instanceof Window) {
Window window = (Window) locator;
robotLog(logLevel, "Getting bounds with window \"" + locator.toString() + "\"");
return mapObject(new BoundingBox(window.getX(), window.getY(), window.getWidth(), window.getHeight()));
} else if (locator instanceof Scene) {
Scene scene = (Scene) locator;
robotLog(logLevel, "Getting bounds with scene \"" + locator.toString() + "\"");
return mapObject(new BoundingBox(scene.getX() + scene.getWindow().getX(), scene.getY() + scene.getWindow().getY(), scene.getWidth(), scene.getHeight()));
} else if (locator instanceof Point2D) {
robotLog(logLevel, "Getting bounds with point object \"" + locator.toString() + "\"");
return mapObject(robot.bounds((Point2D) locator).query());
} else if (locator instanceof Node) {
robotLog(logLevel, "Getting bounds with node \"" + locator.toString() + "\"");
return mapObject(robot.bounds((Node) locator).query());
} else if (locator instanceof String) {
waitUntilExists((String) locator);
Node node = robot.lookup((String) locator).query();
robotLog(logLevel, "Getting bounds with query \"" + locator.toString() + "\"");
return mapObject(robot.bounds(node).query());
} else if (locator instanceof Bounds) {
robotLog(logLevel, "Getting bounds with bounds object \"" + locator.toString() + "\"");
return mapObject(locator);
} else if (locator instanceof PointQuery) {
robotLog(logLevel, "Getting bounds with point query \"" + locator.toString() + "\"");
return mapObject(robot.bounds(((PointQuery) locator).query()).query());
}
throw new JavaFXLibraryNonFatalException("Unsupported parameter type: " + locator.toString());
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException) {
throw e;
}
throw new JavaFXLibraryNonFatalException("Couldn't find \"" + locator + "\"");
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ApplicationLauncher method launchJavafxApplication.
@RobotKeyword("Launches JavaFX application with the given arguments.\n\n" + "``appName`` is the name of the application to launch. \n\n" + "``appArgs`` is a list of arguments to be passed for the application. \n\n" + "Example:\n" + "| Launch JavaFX Application | _javafxlibrary.testapps.MenuApp_ |\n")
@ArgumentNames({ "appName", "*args" })
public void launchJavafxApplication(String appName, String... appArgs) {
try {
HelperFunctions.robotLog("INFO", "Starting application:" + appName);
createNewSession(appName, appArgs);
HelperFunctions.robotLog("INFO", "Application: " + appName + " started.");
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Unable to launch application: " + appName, e);
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ApplicationLauncher method closeJavafxApplication.
@RobotKeyword("Closes JavaFX application.\n\n" + "Example:\n" + "| Close JavaFX Application | \n")
public void closeJavafxApplication() {
try {
HelperFunctions.robotLog("INFO", "Closing application...");
deleteSession();
HelperFunctions.robotLog("INFO", "Application closed.");
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Unable to close Java FX application.", e);
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method getNodeImageUrl.
@RobotKeyword("Returns image name and path of the node. \n\n" + "``locator`` is either a _query_ or _Object_ for a node whose getHeight method will be called, see " + "`3. Locating or specifying UI elements`. \n\n" + "Returns full image path by subsequently calling impl_getUrl -method. \n\n" + "Note, impl_getUrl -method is deprecated! Support for this method will be removed from Java in the future.")
@ArgumentNames({ "node" })
public String getNodeImageUrl(Object locator) {
Node node = objectToNode(locator);
robotLog("INFO", "Getting image url from node: \"" + node.toString() + "\"");
try {
Method[] methods = node.getClass().getMethods();
for (Method m : methods) {
if (m.getName().equals("getImage") && m.getParameterCount() == 0) {
robotLog("TRACE", "Method getImage() found. Invoking it on node: \"" + node.toString() + "\"");
try {
Object result = m.invoke(node, null);
Image image = (Image) result;
robotLog("TRACE", "Calling deprecated method impl_getUrl() for image: \"" + image.toString() + "\"");
return image.impl_getUrl();
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Problem calling method: .getImage(): " + e.getMessage(), e);
}
}
}
throw new JavaFXLibraryNonFatalException("Get node image url failed for node: \"" + node.toString() + "\". Element has no method impl_getUrl()");
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException)
throw e;
throw new JavaFXLibraryNonFatalException("Unable to get node image url for node: \"" + node.toString() + "\"", e);
}
}
Aggregations