Modifier and Type | Method and Description |
---|---|
void |
cleanUp()
Cleans up any used resources (keyboard, mouse, open windows and
ScreenLock ) used by
this Robot . |
void |
cleanUpWithoutDisposingWindows()
Cleans up any used resources (keyboard, mouse and
ScreenLock ) used by this
Robot . |
void |
click(Component c)
Simulates a user clicking once the given AWT or Swing
Component using the left mouse button. |
void |
click(Component c,
MouseButton button)
Simulates a user clicking once the given AWT or Swing
Component using the given mouse button. |
void |
click(Component c,
MouseButton button,
int times)
Simulates a user clicking the given mouse button, the given times on the given AWT or Swing
Component . |
void |
click(Component c,
Point where)
Simulates a user clicking at the given position on the given AWT or Swing
Component . |
void |
click(Component c,
Point where,
MouseButton button,
int times)
Simulates a user clicking the given mouse button, the given times at the given position on the given AWT or Swing
Component . |
void |
click(Point where,
MouseButton button,
int times)
Simulates a user clicking the given mouse button, the given times at the given absolute coordinates.
|
void |
close(Window w)
Simulates a user closing the given AWT or Swing
Window . |
void |
doubleClick(Component c)
Simulates a user double-clicking the given AWT or Swing
Component . |
void |
enterText(String text)
Simulates a user entering the given text.
|
JPopupMenu |
findActivePopupMenu() |
ComponentFinder |
finder() |
void |
focus(Component c)
Gives input focus to the given AWT or Swing
Component . |
void |
focusAndWaitForFocusGain(Component c)
Gives input focus to the given AWT or Swing
Component and waits until the Component has focus. |
ComponentHierarchy |
hierarchy() |
boolean |
isActive()
Indicates whether this
Robot is active. |
boolean |
isDragging()
Indicates whether the robot is currently in a dragging operation.
|
boolean |
isReadyForInput(Component c)
Indicates whether the given AWT or Swing
Component is ready for input. |
void |
jitter(Component c)
Makes the mouse pointer show small quick jumpy movements on the given AWT or Swing
Component . |
void |
jitter(Component c,
Point where)
Makes the mouse pointer show small quick jumpy movements on the given AWT or Swing
Component at the given
point. |
void |
moveMouse(Component c)
Simulates a user moving the mouse pointer to the center of the given AWT or Swing
Component . |
void |
moveMouse(Component c,
int x,
int y)
Simulates a user moving the mouse pointer to the given coordinates relative to the given AWT or Swing
Component . |
void |
moveMouse(Component c,
Point p)
Simulates a user moving the mouse pointer to the given coordinates relative to the given AWT or Swing
Component . |
void |
moveMouse(int x,
int y)
Simulates a user moving the mouse pointer to the given coordinates.
|
void |
moveMouse(Point p)
Simulates a user moving the mouse pointer to the given coordinates.
|
void |
pressAndReleaseKey(int keyCode,
int... modifiers)
Type the given key code with the given modifiers.
|
void |
pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys.
|
void |
pressKey(int keyCode)
Simulates a user pressing given key.
|
void |
pressKeyWhileRunning(int keyCode,
Runnable runnable)
Simulates a user pressing given key, running the given runnable and releasing the key again.
|
void |
pressModifiers(int modifierMask)
Presses the appropriate modifiers corresponding to the given mask.
|
void |
pressModifiersWhileRunning(int modifierMask,
Runnable runnable)
Presses the appropriate modifiers corresponding to the given mask.
|
void |
pressMouse(Component c,
Point where)
Simulates a user pressing the left mouse button on the given AWT or Swing
Component . |
void |
pressMouse(Component c,
Point where,
MouseButton button)
Simulates a user pressing the given mouse button on the given AWT or Swing
Component . |
void |
pressMouse(MouseButton button)
Simulates a user pressing a mouse button.
|
void |
pressMouse(Point where,
MouseButton button)
Simulates a user pressing the given mouse button on the given coordinates.
|
void |
pressMouseWhileRunning(Component c,
Point where,
MouseButton button,
Runnable runnable)
Simulates a user pressing the given mouse button on the given AWT or Swing
Component , running the given
runnable and releasing the mouse button again. |
void |
pressMouseWhileRunning(Component c,
Point where,
Runnable runnable)
Simulates a user pressing the left mouse button on the given AWT or Swing
Component , running the given
runnable and releasing the mouse button again. |
void |
pressMouseWhileRunning(MouseButton button,
Runnable runnable)
Simulates a user pressing a mouse button, running the given runnable and releasing the mouse button again.
|
void |
pressMouseWhileRunning(Point where,
MouseButton button,
Runnable runnable)
Simulates a user pressing the given mouse button on the given coordinates, running the given
runnable and releasing the mouse button again.
|
ComponentPrinter |
printer() |
void |
releaseKey(int keyCode)
Simulates a user releasing the given key.
|
void |
releaseModifiers(int modifierMask)
Releases the appropriate modifiers corresponding to the given mask.
|
void |
releaseMouse(MouseButton button)
Releases the given mouse button.
|
void |
releaseMouseButtons()
Releases any mouse button(s) used by the robot.
|
void |
requireNoJOptionPaneIsShowing()
Ensures that there is no
JOptionPane showing, and potentially blocking GUI tests. |
void |
rightClick(Component c)
Simulates a user right-clicking the given AWT or Swing
Component . |
static Robot |
robotWithCurrentAwtHierarchy()
Creates a new
Robot that has access to all the AWT and Swing Component s in the AWT hierarchy. |
static Robot |
robotWithCurrentAwtHierarchyWithoutScreenLock() |
static Robot |
robotWithNewAwtHierarchy()
Creates a new
Robot with a new AWT hierarchy. |
static Robot |
robotWithNewAwtHierarchyWithoutScreenLock() |
void |
rotateMouseWheel(Component c,
int amount)
Moves the mouse pointer over to the given AWT or Swing
Component and rotates the scroll wheel on
wheel-equipped mice. |
void |
rotateMouseWheel(int amount)
Rotates the scroll wheel on wheel-equipped mice.
|
Settings |
settings() |
JPopupMenu |
showPopupMenu(Component invoker)
Shows a
JPopupMenu . |
JPopupMenu |
showPopupMenu(Component invoker,
Point location)
Shows a
JPopupMenu at the given coordinates. |
void |
showWindow(Window w)
Safely display an AWT or Swing
Window with proper EDT synchronization. |
void |
showWindow(Window w,
Dimension size)
Safely display an AWT or Swing
Window with proper EDT synchronization. |
void |
showWindow(Window w,
Dimension size,
boolean pack)
Safely display an AWT or Swing
Window with proper EDT synchronization. |
void |
type(char character)
Types the given character.
|
void |
waitForIdle()
Wait for an idle AWT event queue.
|
@Nonnull public static Robot robotWithNewAwtHierarchy()
Robot
with a new AWT hierarchy. The created Robot
will not be able to access any AWT
and Swing Component
s that were created before it.Robot
.@Nonnull public static Robot robotWithNewAwtHierarchyWithoutScreenLock()
@Nonnull public static Robot robotWithCurrentAwtHierarchy()
Robot
that has access to all the AWT and Swing Component
s in the AWT hierarchy.Robot
.@Nonnull public static Robot robotWithCurrentAwtHierarchyWithoutScreenLock()
@Nonnull public ComponentPrinter printer()
@Nonnull public ComponentFinder finder()
@RunsInEDT public void showWindow(@Nonnull Window w)
Robot
Window
with proper EDT synchronization. This method blocks until the
Window
is showing and ready for input.showWindow
in interface Robot
w
- the window to display.@RunsInEDT public void showWindow(@Nonnull Window w, @Nonnull Dimension size)
Robot
Window
with proper EDT synchronization. This method blocks until the
Window
is showing and ready for input.showWindow
in interface Robot
w
- the window to display.size
- the size of the window to display.@RunsInEDT public void showWindow(@Nonnull Window w, @Nullable Dimension size, boolean pack)
Robot
Safely display an AWT or Swing Window
with proper EDT synchronization. This method blocks until the
Window
is showing. This method will return even when the window is a modal dialog, since the show method is
called on the event dispatch thread (EDT). The Window
will be packed if the pack flag is set, and set to
the given size if it is non-null
.
Modal dialogs may be shown with this method without blocking.
showWindow
in interface Robot
w
- the window to display.size
- the size of the window to display. A null
value indicates that the window does not need to be
resized.pack
- flag that indicates if the window should be packed or not. By packed we mean calling w.pack()
.@RunsInEDT public void close(@Nonnull Window w)
Robot
Window
.@RunsInEDT public void focusAndWaitForFocusGain(@Nonnull Component c)
Robot
Component
and waits until the Component
has focus.focusAndWaitForFocusGain
in interface Robot
c
- the Component
to give focus to.@RunsInEDT public void focus(@Nonnull Component c)
Robot
Component
. Note that the Component
may not yet have
focus when this method returns.@RunsInEDT public void cleanUp()
Robot
ScreenLock
) used by
this Robot
.@RunsInEDT public void cleanUpWithoutDisposingWindows()
Robot
Cleans up any used resources (keyboard, mouse and ScreenLock
) used by this
Robot
. This method does not dispose any open windows.
Note: The preferred method to use to clean up resources is Robot.cleanUp()
. Using
Robot.cleanUpWithoutDisposingWindows()
may leave many windows open after each test. Use it on very special
cases. Please read bug 138 for
more details.
cleanUpWithoutDisposingWindows
in interface Robot
@RunsInEDT public void click(@Nonnull Component c)
Robot
Component
using the left mouse button.@RunsInEDT public void rightClick(@Nonnull Component c)
Robot
Component
.rightClick
in interface Robot
c
- the Component
to click on.@RunsInEDT public void click(@Nonnull Component c, @Nonnull MouseButton button)
Robot
Component
using the given mouse button.@RunsInEDT public void doubleClick(@Nonnull Component c)
Robot
Component
.doubleClick
in interface Robot
c
- the Component
to click on.@RunsInEDT public void click(@Nonnull Component c, @Nonnull MouseButton button, int times)
Robot
Component
.@RunsInEDT public void click(@Nonnull Component c, @Nonnull Point where)
Robot
Component
.@RunsInEDT public void click(@Nonnull Point where, @Nonnull MouseButton button, int times)
Robot
@RunsInEDT public void click(@Nonnull Component c, @Nonnull Point where, @Nonnull MouseButton button, int times)
Robot
Component
.public void pressModifiers(int modifierMask)
Robot
java.awt.event.InputEvent
.pressModifiers
in interface Robot
modifierMask
- the given mask.Robot.pressModifiersWhileRunning(int, Runnable)
,
InputEvent
public void pressModifiersWhileRunning(int modifierMask, Runnable runnable)
Robot
java.awt.event.InputEvent
. Runs the given runnable and then releases the modifiers again.pressModifiersWhileRunning
in interface Robot
modifierMask
- the given mask.runnable
- the runnable being run while pressing the given buttonRobot.pressModifiers(int)
,
InputEvent
public void releaseModifiers(int modifierMask)
Robot
java.awt.event.InputEvent
.releaseModifiers
in interface Robot
modifierMask
- the given mask.InputEvent
@RunsInEDT public void moveMouse(@Nonnull Component c)
Robot
Component
.@RunsInEDT public void moveMouse(@Nonnull Component c, @Nonnull Point p)
Robot
Component
.@RunsInEDT public void moveMouse(@Nonnull Component c, int x, int y)
Robot
Component
.public void moveMouse(@Nonnull Point p)
Robot
public void moveMouse(int x, int y)
Robot
public void pressMouse(@Nonnull MouseButton button)
Robot
pressMouse
in interface Robot
button
- the mouse button to press.Robot.pressMouseWhileRunning(MouseButton, Runnable)
public void pressMouseWhileRunning(@Nonnull MouseButton button, @Nonnull Runnable runnable)
Robot
pressMouseWhileRunning
in interface Robot
button
- the mouse button to press.runnable
- the runnable being run while pressing the given buttonRobot.pressMouse(MouseButton)
,
Robot.releaseMouse(MouseButton)
public void pressMouse(@Nonnull Component c, @Nonnull Point where)
Robot
Component
.pressMouse
in interface Robot
c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.Robot.pressMouseWhileRunning(Component, Point, Runnable)
public void pressMouseWhileRunning(@Nonnull Component c, @Nonnull Point where, @Nonnull Runnable runnable)
Robot
Component
, running the given
runnable and releasing the mouse button again.pressMouseWhileRunning
in interface Robot
c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.runnable
- the Runnable
to run while the mouse is pressedRobot.pressMouse(Component, Point)
public void pressMouse(@Nonnull Component c, @Nonnull Point where, @Nonnull MouseButton button)
Robot
Component
.pressMouse
in interface Robot
c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.button
- the mouse button to press.Robot.pressMouseWhileRunning(Component, Point, MouseButton, Runnable)
public void pressMouseWhileRunning(@Nonnull Component c, @Nonnull Point where, @Nonnull MouseButton button, @Nonnull Runnable runnable)
Robot
Component
, running the given
runnable and releasing the mouse button again.pressMouseWhileRunning
in interface Robot
c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.button
- the mouse button to press.runnable
- the Runnable
to run while the mouse is pressedRobot.pressMouse(Component, Point, MouseButton)
public void pressMouse(@Nonnull Point where, @Nonnull MouseButton button)
Robot
pressMouse
in interface Robot
where
- the position where to press the given mouse button.button
- the mouse button to press.Robot.pressMouseWhileRunning(Point, MouseButton, Runnable)
public void pressMouseWhileRunning(@Nonnull Point where, @Nonnull MouseButton button, @Nonnull Runnable runnable)
Robot
pressMouseWhileRunning
in interface Robot
where
- the position where to press the given mouse button.button
- the mouse button to press.runnable
- the Runnable
to run while the mouse is pressedRobot.pressMouse(Point, MouseButton)
@RunsInEDT public void releaseMouse(@Nonnull MouseButton button)
Robot
releaseMouse
in interface Robot
button
- the mouse button to release.Robot.pressMouseWhileRunning(MouseButton, Runnable)
,
Robot.pressMouseWhileRunning(Component, Point, Runnable)
,
Robot.pressMouseWhileRunning(Point, MouseButton, Runnable)
,
Robot.pressMouseWhileRunning(Component, Point, MouseButton, Runnable)
@RunsInEDT public void releaseMouseButtons()
Robot
releaseMouseButtons
in interface Robot
public void rotateMouseWheel(@Nonnull Component c, int amount)
Robot
Component
and rotates the scroll wheel on
wheel-equipped mice.rotateMouseWheel
in interface Robot
c
- the given Component
.amount
- number of "notches" to move the mouse wheel. Negative values indicate movement up/away from the user,
while positive values indicate movement down/towards the user.public void rotateMouseWheel(int amount)
Robot
rotateMouseWheel
in interface Robot
amount
- number of "notches" to move the mouse wheel. Negative values indicate movement up/away from the user,
while positive values indicate movement down/towards the user.@RunsInEDT public void jitter(@Nonnull Component c)
Robot
Component
.@RunsInEDT public void jitter(@Nonnull Component c, @Nonnull Point where)
Robot
Component
at the given
point.@RunsInEDT public void enterText(@Nonnull String text)
Robot
Component
that has input focus.@RunsInEDT public void type(char character)
Robot
Component
that
has input focus.@RunsInEDT public void pressAndReleaseKey(int keyCode, @Nonnull int... modifiers)
Robot
java.awt.event.InputEvent
masks.pressAndReleaseKey
in interface Robot
keyCode
- the code of the key to press.modifiers
- the given modifiers.@RunsInEDT public void pressAndReleaseKeys(@Nonnull int... keyCodes)
Robot
pressAndReleaseKeys
in interface Robot
keyCodes
- one or more codes of the keys to press.KeyEvent
@RunsInEDT public void pressKey(int keyCode)
Robot
pressKey
in interface Robot
keyCode
- the code of the key to press.KeyEvent
,
Robot.pressKeyWhileRunning(int, Runnable)
public void pressKeyWhileRunning(int keyCode, Runnable runnable)
Robot
pressKeyWhileRunning
in interface Robot
keyCode
- the code of the key to press.runnable
- the Runnable
to run while the key is pressedKeyEvent
,
Robot.pressKey(int)
@RunsInEDT public void releaseKey(int keyCode)
Robot
releaseKey
in interface Robot
keyCode
- the code of the key to release.KeyEvent
@RunsInEDT public void waitForIdle()
Robot
java.awt.Robot.waitForIdle()
, which may have events on the queue when it returns. Do NOT
use this method if there are animations or other continual refreshes happening, since in that case it may never
return.waitForIdle
in interface Robot
public boolean isDragging()
Robot
isDragging
in interface Robot
true
if the robot is currently in a dragging operation, false
otherwise.@RunsInEDT @Nonnull public JPopupMenu showPopupMenu(@Nonnull Component invoker)
Robot
JPopupMenu
.showPopupMenu
in interface Robot
invoker
- the Component
to invoke the JPopupMenu
from.JPopupMenu
.@RunsInEDT @Nonnull public JPopupMenu showPopupMenu(@Nonnull Component invoker, @Nonnull Point location)
Robot
JPopupMenu
at the given coordinates.showPopupMenu
in interface Robot
invoker
- the Component
to invoke the JPopupMenu
from.location
- the given coordinates for the JPopupMenu
.JPopupMenu
.@RunsInCurrentThread public boolean isReadyForInput(@Nonnull Component c)
Indicates whether the given AWT or Swing Component
is ready for input.
Note: This method is accessed in the current executing thread. Such thread may or may not be the event dispatch thread (EDT). Client code must call this method from the EDT.
isReadyForInput
in interface Robot
c
- the given Component
.true
if the given Component
is ready for input, false
otherwise.ActionFailedException
- if the given Component
does not have a
Window
ancestor.@RunsInEDT @Nullable public JPopupMenu findActivePopupMenu()
findActivePopupMenu
in interface Robot
JPopupMenu
or null
, if no pop-up is currently showing.@RunsInEDT public void requireNoJOptionPaneIsShowing()
Robot
JOptionPane
showing, and potentially blocking GUI tests.requireNoJOptionPaneIsShowing
in interface Robot
@Nonnull public ComponentHierarchy hierarchy()
public boolean isActive()
Robot
Robot
is active. Being "active" means that Robot.cleanUp()
has not been called
yet.Copyright © 2014–2019 AssertJ. All rights reserved.