Package org.testfx.service.adapter.impl
Class JavafxRobotAdapter
- java.lang.Object
-
- org.testfx.service.adapter.impl.JavafxRobotAdapter
-
- All Implemented Interfaces:
RobotAdapter<JavafxRobotAdapter>
public class JavafxRobotAdapter extends java.lang.Object implements RobotAdapter<JavafxRobotAdapter>
ARobotAdapter
implementation that uses the only the JavaFX public API.Developer's Note: Forcing the type parameter to be
JavafxRobotAdapter
is a bit of a kludge. Ideally we would use aJavafxRobot
instead but such a type does not exist.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
isAltDown
private boolean
isButton1Pressed
private boolean
isButton2Pressed
private boolean
isButton3Pressed
private boolean
isControlDown
private boolean
isMetaDown
private boolean
isShiftDown
private javafx.scene.input.MouseButton
lastButtonPressed
private javafx.scene.Scene
scene
private double
sceneMouseX
private double
sceneMouseY
private double
screenMouseX
private double
screenMouseY
-
Constructor Summary
Constructors Constructor Description JavafxRobotAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private javafx.scene.input.KeyEvent
createKeyEvent(javafx.event.EventType<javafx.scene.input.KeyEvent> eventType, javafx.scene.input.KeyCode keyCode, java.lang.String character)
private javafx.scene.input.MouseEvent
createMouseEvent(javafx.event.EventType<javafx.scene.input.MouseEvent> eventType, double x, double y, javafx.scene.input.MouseButton mouseButton, int clickCount)
private javafx.scene.input.ScrollEvent
createScrollEvent(int wheelAmount)
javafx.scene.paint.Color
getCapturePixelColor(javafx.geometry.Point2D location)
Gets the color of a pixel at the given JavaFx coordinates.javafx.scene.image.Image
getCaptureRegion(javafx.geometry.Rectangle2D region)
Captures a region of the screen.private javafx.event.EventTarget
getEventTarget(javafx.scene.Scene scene)
javafx.geometry.Point2D
getMouseLocation()
Returns the current position of the cursor in JavaFx coordinatesvoid
keyPress(javafx.scene.input.KeyCode key)
Function used to make the robot press a key.void
keyRelease(javafx.scene.input.KeyCode key)
Function used to make the robot release a key.void
keyType(javafx.scene.input.KeyCode key, java.lang.String character)
void
mouseClick(javafx.scene.input.MouseButton button)
void
mouseClick(javafx.scene.input.MouseButton button, int clickCount)
void
mouseDrag(javafx.scene.input.MouseButton button)
void
mouseMove(javafx.geometry.Point2D location)
Moves the mouse cursor to the given position in JavaFx coordinatesvoid
mousePress(javafx.scene.input.MouseButton button)
Makes the robot press a mouse button.void
mousePress(javafx.scene.input.MouseButton button, int clickCount)
void
mouseRelease(javafx.scene.input.MouseButton button)
Makes the robot release a mouse button.void
mouseRelease(javafx.scene.input.MouseButton button, int clickCount)
void
mouseWheel(int wheelAmount)
Makes the robot to simulate a action of the mouse wheel.
Negative values indicate movement up/away from the user, positive values indicate movement down/towards the user.void
robotCreate()
Creates a robot.void
robotCreate(javafx.scene.Scene scene)
void
robotDestroy()
Destroys the robot
-
-
-
Field Detail
-
scene
private javafx.scene.Scene scene
-
isShiftDown
private boolean isShiftDown
-
isControlDown
private boolean isControlDown
-
isAltDown
private boolean isAltDown
-
isMetaDown
private boolean isMetaDown
-
lastButtonPressed
private javafx.scene.input.MouseButton lastButtonPressed
-
isButton1Pressed
private boolean isButton1Pressed
-
isButton2Pressed
private boolean isButton2Pressed
-
isButton3Pressed
private boolean isButton3Pressed
-
sceneMouseX
private double sceneMouseX
-
sceneMouseY
private double sceneMouseY
-
screenMouseX
private double screenMouseX
-
screenMouseY
private double screenMouseY
-
-
Method Detail
-
robotCreate
public void robotCreate(javafx.scene.Scene scene)
-
robotCreate
public void robotCreate()
Description copied from interface:RobotAdapter
Creates a robot.- Specified by:
robotCreate
in interfaceRobotAdapter<JavafxRobotAdapter>
-
robotDestroy
public void robotDestroy()
Description copied from interface:RobotAdapter
Destroys the robot- Specified by:
robotDestroy
in interfaceRobotAdapter<JavafxRobotAdapter>
-
keyPress
public void keyPress(javafx.scene.input.KeyCode key)
Description copied from interface:RobotAdapter
Function used to make the robot press a key. The key must be a physical existing key on the keyboard.- Specified by:
keyPress
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
key
- the key to press (must exist on a keyboard)
-
keyRelease
public void keyRelease(javafx.scene.input.KeyCode key)
Description copied from interface:RobotAdapter
Function used to make the robot release a key. The key must be a physical existing key on the keyboard.- Specified by:
keyRelease
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
key
- the key to press (must exist on a keyboard)
-
keyType
public void keyType(javafx.scene.input.KeyCode key, java.lang.String character)
-
getMouseLocation
public javafx.geometry.Point2D getMouseLocation()
Description copied from interface:RobotAdapter
Returns the current position of the cursor in JavaFx coordinates- Specified by:
getMouseLocation
in interfaceRobotAdapter<JavafxRobotAdapter>
- Returns:
- the current position of the mouse cursor
-
mouseMove
public void mouseMove(javafx.geometry.Point2D location)
Description copied from interface:RobotAdapter
Moves the mouse cursor to the given position in JavaFx coordinates- Specified by:
mouseMove
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
location
- the location in JavaFx coordinates to move the cursor to
-
mousePress
public void mousePress(javafx.scene.input.MouseButton button, int clickCount)
-
mouseRelease
public void mouseRelease(javafx.scene.input.MouseButton button, int clickCount)
-
mouseClick
public void mouseClick(javafx.scene.input.MouseButton button, int clickCount)
-
mousePress
public void mousePress(javafx.scene.input.MouseButton button)
Description copied from interface:RobotAdapter
Makes the robot press a mouse button.- Specified by:
mousePress
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
button
- the button to press
-
mouseRelease
public void mouseRelease(javafx.scene.input.MouseButton button)
Description copied from interface:RobotAdapter
Makes the robot release a mouse button.- Specified by:
mouseRelease
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
button
- the button to release
-
mouseClick
public void mouseClick(javafx.scene.input.MouseButton button)
-
mouseDrag
public void mouseDrag(javafx.scene.input.MouseButton button)
-
mouseWheel
public void mouseWheel(int wheelAmount)
Description copied from interface:RobotAdapter
Makes the robot to simulate a action of the mouse wheel.
Negative values indicate movement up/away from the user, positive values indicate movement down/towards the user.- Specified by:
mouseWheel
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
wheelAmount
- the amount to scroll
-
getCapturePixelColor
public javafx.scene.paint.Color getCapturePixelColor(javafx.geometry.Point2D location)
Description copied from interface:RobotAdapter
Gets the color of a pixel at the given JavaFx coordinates. The returned Color is in the JavaFx color space. //TODO Due to technical reasons, there might be a deviation in color.- Specified by:
getCapturePixelColor
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
location
- of the pixel in JavaFx coordinates, to retrieve the color for- Returns:
- the Color of the given Pixel in the JavaFx color space
-
getCaptureRegion
public javafx.scene.image.Image getCaptureRegion(javafx.geometry.Rectangle2D region)
Description copied from interface:RobotAdapter
Captures a region of the screen. The returned Image is in the JavaFx color space. //TODO Due to technical reasons, there might be a deviation.- Specified by:
getCaptureRegion
in interfaceRobotAdapter<JavafxRobotAdapter>
- Parameters:
region
- the region to capture in JavaFx coordinates- Returns:
- a image of the region
-
getEventTarget
private javafx.event.EventTarget getEventTarget(javafx.scene.Scene scene)
-
createKeyEvent
private javafx.scene.input.KeyEvent createKeyEvent(javafx.event.EventType<javafx.scene.input.KeyEvent> eventType, javafx.scene.input.KeyCode keyCode, java.lang.String character)
-
createMouseEvent
private javafx.scene.input.MouseEvent createMouseEvent(javafx.event.EventType<javafx.scene.input.MouseEvent> eventType, double x, double y, javafx.scene.input.MouseButton mouseButton, int clickCount)
-
createScrollEvent
private javafx.scene.input.ScrollEvent createScrollEvent(int wheelAmount)
-
-