use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.
the class ScreenCapturing method captureImage.
@RobotKeyword("Returns a screenshot of the given locator.\n\n" + "``locator`` is either a _query_ or _Object:Bounds, Node, Point2D, Rectangle, PointQuery, Scene, Window_ for identifying the element, see " + "`3. Locating or specifying UI elements`. \n\n" + "Argument ``logImage`` is a boolean value that specifies whether a captured image is also printed to test execution log. \n\n " + "\nExample:\n" + "| ${region}= | Create Rectangle | 11 | 22 | 33 | 44 | \n" + "| ${capture}= | Capture Image | ${region} | \n" + "| ${capture}= | Capture Image | ${node} | \n" + "| ${capture}= | Capture Image | ${window} | \n" + "| ${capture}= | Capture Image | \\#id | logImage=False |\n")
@ArgumentNames({ "locator", "logImage=True" })
public Object captureImage(Object locator, boolean logImage) {
if (locator == null)
throw new JavaFXLibraryNonFatalException("Unable to capture image, given locator was null!");
robotLog("INFO", "Capturing screenshot from locator: \"" + locator.toString() + "\"");
Image image = null;
Bounds targetBounds = objectToBounds(locator);
try {
image = robot.capture(targetBounds).getImage();
Path path = createNewImageFileNameWithPath();
robotContext.getCaptureSupport().saveImage(image, path);
if (logImage) {
Double printSize = (targetBounds.getWidth() > 800) ? 800 : targetBounds.getWidth();
System.out.println("*HTML* <img src=\"" + path + "\" width=\"" + printSize + "px\">");
}
return mapObject(image);
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException)
throw e;
throw new JavaFXLibraryNonFatalException("Unable to take capture : \"" + locator.toString() + "\"", e);
}
}
use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.
the class ScrollRobot method scrollHorizontally.
/*
* Current version of TestFX uses java.awt.Robots mouseWheel-method for scrolling, which only supports
* vertical scrolling. This solution uses SHIFT + MWHEEL combination for horizontal scrolling. Note that this
* combination does not work out of the box on Linux desktops.
*/
@RobotKeyword("Scrolls horizontally by amount (in terms of ticks of a mouse wheel) in given direction.\n\n" + "``amount`` is the number of scroll ticks, defaults to 1. \n\n" + "``direction`` specifies whether to scroll RIGHT or LEFT. \n\n" + "\nExample:\n" + "| Move To | ${some node} | \n" + "| Scroll Horizontally | RIGHT | \n")
@ArgumentNames({ "direction", "amount=1" })
public void scrollHorizontally(String direction, int amount) {
try {
HelperFunctions.robotLog("INFO", "Scrolling \"" + direction + "\" by \"" + Integer.toString(amount) + "\" ticks.");
robot.press(KeyCode.SHIFT);
robot.scroll(amount, HelperFunctions.getHorizontalDirection(direction));
robot.release(KeyCode.SHIFT);
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException)
throw e;
throw new JavaFXLibraryNonFatalException("Unable to scroll horizontally to direction: \"" + direction + "\"", e);
}
}
use of org.robotframework.javalib.annotation.RobotKeyword in project JavaFXLibrary by eficode.
the class WindowLookup method getWindow.
@RobotKeyword("Returns window object.\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" + "| ${window}= | Get Window | My window title | \n" + "| ${window}= | Get Window | title=My window title | \n" + "| ${window}= | Get Window | pattern=W[i-w]{5} Title | \n\n" + "Index:\n" + "| ${window}= | Get Window | 0 | \n" + "| ${window}= | Get Window | ${2} | \n\n" + "Node:\n" + "| ${some_node}= | Find | \\#some_id | \n" + "| ${window}= | Get Window | ${some_node} | \n\n" + "Scene: \n" + "| ${some_scene}= | Get Nodes Scene | ${some_node} | \n" + "| ${window}= | Get Window | ${some_scene} | \n")
@ArgumentNames({ "locator" })
public Object getWindow(Object locator) {
try {
if (locator instanceof String) {
if (((String) locator).startsWith("pattern=")) {
locator = ((String) locator).replace("pattern=", "");
HelperFunctions.robotLog("INFO", "Getting window with pattern \"" + locator + "\"");
return HelperFunctions.mapObject(robot.window((String) locator));
} else if (((String) locator).matches("[0-9]+")) {
return getWindow(Integer.parseInt(locator.toString()));
} else {
if (((String) locator).startsWith("title=")) {
locator = ((String) locator).replace("title=", "");
}
HelperFunctions.robotLog("INFO", "Getting window with title \"" + locator + "\"");
return HelperFunctions.mapObject(robot.window((String) locator));
}
}
if (locator instanceof Node) {
HelperFunctions.robotLog("INFO", "Getting window with node \"" + locator.toString() + "\"");
return HelperFunctions.mapObject(robot.window((Node) locator));
}
if (locator instanceof Scene) {
HelperFunctions.robotLog("INFO", "Getting window with scene \"" + locator.toString() + "\"");
return HelperFunctions.mapObject(robot.window((Scene) locator));
}
if (locator instanceof Integer) {
HelperFunctions.robotLog("INFO", "Getting window with index \"" + locator.toString() + "\"");
return HelperFunctions.mapObject(robot.window((Integer) locator));
}
throw new JavaFXLibraryNonFatalException("Unable to handle argument \"" + locator.toString() + "\"");
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException)
throw e;
throw new JavaFXLibraryNonFatalException("Unable to find window: \"" + locator.toString() + "\"", e);
}
}
use of org.robotframework.javalib.annotation.RobotKeyword 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 org.robotframework.javalib.annotation.RobotKeyword 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 + "\"");
}
}
Aggregations