Skip to content

Commit

Permalink
Merge pull request #258 from hastebrot/bg-feat-bounds-query
Browse files Browse the repository at this point in the history
(feat) Introduce `FxRobot::bounds()` and `BoundsQuery`.
  • Loading branch information
hastebrot committed Mar 27, 2016
2 parents 49b9000 + 7667614 commit 61514e2
Show file tree
Hide file tree
Showing 14 changed files with 877 additions and 248 deletions.
366 changes: 210 additions & 156 deletions subprojects/testfx-core/src/main/java/org/testfx/api/FxRobot.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,80 @@
import com.google.common.base.Predicate;
import org.hamcrest.Matcher;
import org.testfx.api.annotation.Unstable;
import org.testfx.service.query.BoundsQuery;
import org.testfx.service.query.NodeQuery;
import org.testfx.service.query.PointQuery;

@Unstable(reason = "interface was recently added")
public interface FxRobotInterface {

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW TARGETING.
//---------------------------------------------------------------------------------------------

public Window targetWindow();
public FxRobotInterface targetWindow(Window window);
public FxRobotInterface targetWindow(Predicate<Window> predicate);

// Convenience methods:
public FxRobotInterface targetWindow(int windowIndex);
public FxRobotInterface targetWindow(String stageTitleRegex);
public FxRobotInterface targetWindow(Pattern stageTitlePattern);
public FxRobotInterface targetWindow(Scene scene);
public FxRobotInterface targetWindow(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW LOOKUP.
//---------------------------------------------------------------------------------------------

public List<Window> listWindows();
public List<Window> listTargetWindows();
public Window window(Predicate<Window> predicate);

// Convenience methods:
public Window window(int windowIndex);
public Window window(String stageTitleRegex);
public Window window(Pattern stageTitlePattern);
public Window window(Scene scene);
public Window window(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR NODE LOOKUP.
//---------------------------------------------------------------------------------------------

public NodeQuery fromAll();
public NodeQuery from(Node... parentNodes);
public NodeQuery from(Collection<Node> parentNodes);

public Node rootNode(Window window);
public Node rootNode(Scene scene);
public Node rootNode(Node node);

// Convenience methods:
public NodeQuery lookup(String query);
public <T extends Node> NodeQuery lookup(Matcher<T> matcher);
public <T extends Node> NodeQuery lookup(Predicate<T> predicate);
public NodeQuery from(NodeQuery nodeQuery);

//---------------------------------------------------------------------------------------------
// METHODS FOR BOUNDS LOCATION.
//---------------------------------------------------------------------------------------------

public BoundsQuery bounds(double minX,
double minY,
double width,
double height);
public BoundsQuery bounds(Point2D point);
public BoundsQuery bounds(Bounds bounds);
public BoundsQuery bounds(Node node);
public BoundsQuery bounds(Scene scene);
public BoundsQuery bounds(Window window);

// Convenience methods:
public BoundsQuery bounds(String query);
public <T extends Node> BoundsQuery bounds(Matcher<T> matcher);
public <T extends Node> BoundsQuery bounds(Predicate<T> predicate);

//---------------------------------------------------------------------------------------------
// METHODS FOR POINT POSITION.
//---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -98,54 +166,6 @@ public <T extends Node> PointQuery offset(Predicate<T> predicate,
double offsetX,
double offsetY);

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW TARGETING.
//---------------------------------------------------------------------------------------------

public Window targetWindow();
public FxRobotInterface targetWindow(Window window);
public FxRobotInterface targetWindow(Predicate<Window> predicate);

// Convenience methods:
public FxRobotInterface targetWindow(int windowIndex);
public FxRobotInterface targetWindow(String stageTitleRegex);
public FxRobotInterface targetWindow(Pattern stageTitlePattern);
public FxRobotInterface targetWindow(Scene scene);
public FxRobotInterface targetWindow(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW LOOKUP.
//---------------------------------------------------------------------------------------------

public List<Window> listWindows();
public List<Window> listTargetWindows();
public Window window(Predicate<Window> predicate);

// Convenience methods:
public Window window(int windowIndex);
public Window window(String stageTitleRegex);
public Window window(Pattern stageTitlePattern);
public Window window(Scene scene);
public Window window(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR NODE LOOKUP.
//---------------------------------------------------------------------------------------------

public NodeQuery fromAll();
public NodeQuery from(Node... parentNodes);
public NodeQuery from(Collection<Node> parentNodes);

public Node rootNode(Window window);
public Node rootNode(Scene scene);
public Node rootNode(Node node);

// Convenience methods:
public NodeQuery lookup(String query);
public <T extends Node> NodeQuery lookup(Matcher<T> matcher);
public <T extends Node> NodeQuery lookup(Predicate<T> predicate);
public NodeQuery from(NodeQuery nodeQuery);

//---------------------------------------------------------------------------------------------
// METHODS FOR SCREEN CAPTURING.
//---------------------------------------------------------------------------------------------
Expand All @@ -164,6 +184,14 @@ public <T extends Node> PointQuery offset(Predicate<T> predicate,
public FxRobotInterface interrupt();
public FxRobotInterface interrupt(int attemptsCount);

//---------------------------------------------------------------------------------------------
// METHODS FOR SLEEPING.
//---------------------------------------------------------------------------------------------

public FxRobotInterface sleep(long milliseconds);
public FxRobotInterface sleep(long duration,
TimeUnit timeUnit);

//---------------------------------------------------------------------------------------------
// METHODS FOR CLICKING.
//---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -325,14 +353,6 @@ public FxRobotInterface scroll(int amount,
// Convenience methods:
public FxRobotInterface scroll(VerticalDirection direction);

//---------------------------------------------------------------------------------------------
// METHODS FOR SLEEPING.
//---------------------------------------------------------------------------------------------

public FxRobotInterface sleep(long milliseconds);
public FxRobotInterface sleep(long duration,
TimeUnit timeUnit);

//---------------------------------------------------------------------------------------------
// METHODS FOR TYPING.
//---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import org.testfx.service.query.PointQuery;

public interface PointLocator {
PointQuery pointFor(Bounds bounds);
PointQuery point(Bounds bounds);

PointQuery pointFor(Point2D point);
PointQuery point(Point2D point);

PointQuery pointFor(Node node);
PointQuery point(Node node);

PointQuery pointFor(Scene scene);
PointQuery point(Scene scene);

PointQuery pointFor(Window window);
PointQuery point(Window window);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@ public PointLocatorImpl(BoundsLocator boundsLocator) {
//---------------------------------------------------------------------------------------------

@Override
public PointQuery pointFor(Bounds bounds) {
public PointQuery point(Bounds bounds) {
return new BoundsPointQuery(bounds);
}

@Override
public PointQuery pointFor(Point2D point) {
public PointQuery point(Point2D point) {
Bounds bounds = new BoundingBox(point.getX(), point.getY(), 0, 0);
return new BoundsPointQuery(bounds);
}

@Override
public PointQuery pointFor(Node node) {
public PointQuery point(Node node) {
Callable<Bounds> callable = callableBoundsFor(node);
return new CallableBoundsPointQuery(callable);
}

@Override
public PointQuery pointFor(Scene scene) {
public PointQuery point(Scene scene) {
Callable<Bounds> callable = callableBoundsFor(scene);
return new CallableBoundsPointQuery(callable);
}

@Override
public PointQuery pointFor(Window window) {
public PointQuery point(Window window) {
Callable<Bounds> callable = callableBoundsFor(window);
return new CallableBoundsPointQuery(callable);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2013-2014 SmartBear Software
* Copyright 2014-2015 The TestFX Contributors
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the
* European Commission - subsequent versions of the EUPL (the "Licence"); You may
* not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the Licence for the
* specific language governing permissions and limitations under the Licence.
*/
package org.testfx.service.query;

import javafx.geometry.Bounds;

public interface BoundsQuery {

public Bounds query();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import javafx.geometry.Point2D;

import org.testfx.api.annotation.Unstable;
import org.testfx.util.BoundsUtils;
import org.testfx.util.PointQueryUtils;

@Unstable
public class BoundsPointQuery extends PointQueryBase {
Expand Down Expand Up @@ -55,6 +55,7 @@ public void setBounds(Bounds bounds) {
// METHODS.
//---------------------------------------------------------------------------------------------

@Override
public Point2D query() {
Point2D point = pointAtPosition(this.bounds, this.getPosition());
Point2D offset = getOffset();
Expand All @@ -65,8 +66,9 @@ public Point2D query() {
// PRIVATE METHODS.
//---------------------------------------------------------------------------------------------

private Point2D pointAtPosition(Bounds bounds, Point2D position) {
return BoundsUtils.atPositionFactors(bounds, position);
private Point2D pointAtPosition(Bounds bounds,
Point2D position) {
return PointQueryUtils.atPositionFactors(bounds, position);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.testfx.api.annotation.Unstable;
import org.testfx.service.query.PointQuery;
import org.testfx.util.BoundsUtils;
import org.testfx.util.PointQueryUtils;

@Unstable
abstract public class PointQueryBase implements PointQuery {
Expand All @@ -38,27 +38,34 @@ abstract public class PointQueryBase implements PointQuery {
// METHODS.
//---------------------------------------------------------------------------------------------

@Override
public Point2D getPosition() {
return position;
}

@Override
public Point2D getOffset() {
return offset;
}

@Override
public PointQuery atPosition(Point2D position) {
this.position = position;
return this;
}

public PointQuery atPosition(double positionX, double positionY) {
@Override
public PointQuery atPosition(double positionX,
double positionY) {
return atPosition(new Point2D(positionX, positionY));
}

@Override
public PointQuery atPosition(Pos position) {
return atPosition(BoundsUtils.computePositionFactors(position));
return atPosition(PointQueryUtils.computePositionFactors(position));
}

@Override
public PointQuery atOffset(Point2D offset) {
this.offset = new Point2D(
this.offset.getX() + offset.getX(),
Expand All @@ -67,7 +74,9 @@ public PointQuery atOffset(Point2D offset) {
return this;
}

public PointQuery atOffset(double offsetX, double offsetY) {
@Override
public PointQuery atOffset(double offsetX,
double offsetY) {
return atOffset(new Point2D(offsetX, offsetY));
}

Expand Down

0 comments on commit 61514e2

Please sign in to comment.