use of org.testfx.service.query.PointQuery in project TestFX by TestFX.
the class MoveRobotImplTest method moveTo_a_point_with_motion_HORIZONTAL_FIRST.
@Test
public void moveTo_a_point_with_motion_HORIZONTAL_FIRST() {
// given:
Point2D sourcePoint = new Point2D(0, 0);
given(baseRobot.retrieveMouse()).willReturn(sourcePoint);
// and:
Point2D targetPoint = new Point2D(300, 100);
PointQuery pointQuery = mock(PointQuery.class);
given(pointQuery.query()).willReturn(targetPoint);
// when:
moveRobot.moveTo(pointQuery, Motion.HORIZONTAL_FIRST);
// then:
verify(mouseRobot, times(199)).moveNoWait(argThat(argument -> sourcePoint.getY() == argument.getY() || targetPoint.getX() == argument.getX()));
verify(mouseRobot, times(2)).move(targetPoint);
}
use of org.testfx.service.query.PointQuery in project TestFX by TestFX.
the class MoveRobotImplTest method moveTo_a_point_within_10_pixels.
@Test
public void moveTo_a_point_within_10_pixels() {
// given:
Point2D sourcePoint = new Point2D(0, 0);
given(baseRobot.retrieveMouse()).willReturn(sourcePoint);
// and:
Point2D targetPoint = new Point2D(10, 0);
PointQuery pointQuery = mock(PointQuery.class);
given(pointQuery.query()).willReturn(targetPoint);
// when:
moveRobot.moveTo(pointQuery);
// then:
for (double x = 1.0; x <= 9.0; x++) {
verify(mouseRobot, times(1)).moveNoWait(new Point2D(x, 0));
}
verify(mouseRobot, times(2)).move(new Point2D(10, 0));
}
use of org.testfx.service.query.PointQuery 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());
}
use of org.testfx.service.query.PointQuery 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 org.testfx.service.query.PointQuery in project TestFX by TestFX.
the class PointLocatorImplTest method pointFor_Scene_atOffset_afterChange.
@Test
public void pointFor_Scene_atOffset_afterChange() {
// given:
boundsLocatorStub.bounds = sceneBounds;
PointQuery pointQuery = pointLocator.point((Scene) null);
// when:
boundsLocatorStub.bounds = sceneBoundsAfterChange;
Point2D point = pointQuery.atOffset(0, 0).query();
// then:
assertThat(point, CoreMatchers.equalTo(topLeftPointFrom(sceneBoundsAfterChange)));
}
Aggregations