Search in sources :

Example 6 with PointQuery

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);
}
Also used : ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Motion(org.testfx.robot.Motion) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) TestFXRule(org.testfx.framework.junit.TestFXRule) MouseRobot(org.testfx.robot.MouseRobot) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) MoveRobot(org.testfx.robot.MoveRobot) BDDMockito.given(org.mockito.BDDMockito.given) BaseRobot(org.testfx.robot.BaseRobot) Point2D(javafx.geometry.Point2D) SleepRobot(org.testfx.robot.SleepRobot) PointQuery(org.testfx.service.query.PointQuery) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Point2D(javafx.geometry.Point2D) PointQuery(org.testfx.service.query.PointQuery) Test(org.junit.Test)

Example 7 with PointQuery

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));
}
Also used : Point2D(javafx.geometry.Point2D) PointQuery(org.testfx.service.query.PointQuery) Test(org.junit.Test)

Example 8 with PointQuery

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());
}
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 9 with PointQuery

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 + "\"");
    }
}
Also used : Window(javafx.stage.Window) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) Point2D(javafx.geometry.Point2D) BoundingBox(javafx.geometry.BoundingBox) Node(javafx.scene.Node) Bounds(javafx.geometry.Bounds) Scene(javafx.scene.Scene) PointQuery(org.testfx.service.query.PointQuery) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 10 with PointQuery

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)));
}
Also used : Point2D(javafx.geometry.Point2D) PointQuery(org.testfx.service.query.PointQuery) Test(org.junit.Test)

Aggregations

PointQuery (org.testfx.service.query.PointQuery)22 Test (org.junit.Test)19 Point2D (javafx.geometry.Point2D)16 Before (org.junit.Before)3 Rule (org.junit.Rule)3 AdditionalMatchers.not (org.mockito.AdditionalMatchers.not)3 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)3 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)3 BDDMockito.given (org.mockito.BDDMockito.given)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.times (org.mockito.Mockito.times)3 Mockito.verify (org.mockito.Mockito.verify)3 TestFXRule (org.testfx.framework.junit.TestFXRule)3 BaseRobot (org.testfx.robot.BaseRobot)3 Motion (org.testfx.robot.Motion)3 MouseRobot (org.testfx.robot.MouseRobot)3 MoveRobot (org.testfx.robot.MoveRobot)3 SleepRobot (org.testfx.robot.SleepRobot)3 BoundingBox (javafx.geometry.BoundingBox)2 Bounds (javafx.geometry.Bounds)2