public interface Robot
Component
.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 . |
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 ComponentHierarchy hierarchy()
ComponentHierarchy
being used by this robot.@Nonnull ComponentFinder finder()
ComponentFinder
being used by this robot.@Nonnull ComponentPrinter printer()
ComponentPrinter
being used by this robot.void showWindow(@Nonnull Window w)
Window
with proper EDT synchronization. This method blocks until the
Window
is showing and ready for input.w
- the window to display.void showWindow(@Nonnull Window w, @Nonnull Dimension size)
Window
with proper EDT synchronization. This method blocks until the
Window
is showing and ready for input.w
- the window to display.size
- the size of the window to display.void showWindow(@Nonnull Window w, @Nullable Dimension size, boolean pack)
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.
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()
.void close(@Nonnull Window w)
Window
.w
- the Window
to close.void focus(@Nonnull Component c)
Component
. Note that the Component
may not yet have
focus when this method returns.c
- the Component
to give focus to.void focusAndWaitForFocusGain(@Nonnull Component c)
Component
and waits until the Component
has focus.c
- the Component
to give focus to.void cleanUp()
ScreenLock
) used by
this Robot
.void cleanUpWithoutDisposingWindows()
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 cleanUp()
. Using
cleanUpWithoutDisposingWindows()
may leave many windows open after each test. Use it on very special
cases. Please read bug 138 for
more details.
void click(@Nonnull Component c)
Component
using the left mouse button.c
- the Component
to click on.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void rightClick(@Nonnull Component c)
Component
.c
- the Component
to click on.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void click(@Nonnull Component c, @Nonnull MouseButton button)
Component
using the given mouse button.c
- the Component
to click on.button
- the mouse button to use.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void doubleClick(@Nonnull Component c)
Component
.c
- the Component
to click on.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void click(@Nonnull Component c, @Nonnull MouseButton button, int times)
Component
.c
- the Component
to click on.button
- the mouse button to click.times
- the number of times to click the given mouse button.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void click(@Nonnull Component c, @Nonnull Point where)
Component
.c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void click(@Nonnull Component c, @Nonnull Point where, @Nonnull MouseButton button, int times)
Component
.c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.button
- the mouse button to click.times
- the number of times to click the given mouse button.ActionFailedException
- if the Component
to click is out of the
boundaries of the screen.void click(@Nonnull Point where, @Nonnull MouseButton button, int times)
where
- the coordinates where to click.button
- the mouse button to click.times
- the number of times to click the given mouse button.void pressMouse(@Nonnull MouseButton button)
button
- the mouse button to press.pressMouseWhileRunning(MouseButton, Runnable)
void pressMouseWhileRunning(@Nonnull MouseButton button, @Nonnull Runnable runnable)
button
- the mouse button to press.runnable
- the runnable being run while pressing the given buttonpressMouse(MouseButton)
,
releaseMouse(MouseButton)
void pressMouse(@Nonnull Component c, @Nonnull Point where)
Component
.c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.pressMouseWhileRunning(Component, Point, Runnable)
void pressMouseWhileRunning(@Nonnull Component c, @Nonnull Point where, @Nonnull Runnable runnable)
Component
, running the given
runnable and releasing the mouse button again.c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.runnable
- the Runnable
to run while the mouse is pressedpressMouse(Component, Point)
void pressMouse(@Nonnull Component c, @Nonnull Point where, @Nonnull MouseButton button)
Component
.c
- the Component
to click on.where
- the given coordinates, relative to the given Component
.button
- the mouse button to press.pressMouseWhileRunning(Component, Point, MouseButton, Runnable)
void pressMouseWhileRunning(@Nonnull Component c, @Nonnull Point where, @Nonnull MouseButton button, @Nonnull Runnable runnable)
Component
, running the given
runnable and releasing the mouse button again.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 pressedpressMouse(Component, Point, MouseButton)
void pressMouse(@Nonnull Point where, @Nonnull MouseButton button)
where
- the position where to press the given mouse button.button
- the mouse button to press.pressMouseWhileRunning(Point, MouseButton, Runnable)
void pressMouseWhileRunning(@Nonnull Point where, @Nonnull MouseButton button, @Nonnull Runnable runnable)
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 pressedpressMouse(Point, MouseButton)
void moveMouse(@Nonnull Component c)
Component
.c
- the given Component
.void moveMouse(@Nonnull Component c, @Nonnull Point p)
Component
.c
- the given Component
.p
- the given coordinates, relative to the given Component
.ActionFailedException
- if the given Component
is not showing and ready
for input.void moveMouse(@Nonnull Component c, int x, int y)
Component
.c
- the given Component
.x
- X coordinate, relative to the given Component
.y
- Y coordinate, relative to the given Component
.ActionFailedException
- if the given Component
is not showing and ready
for input.void moveMouse(@Nonnull Point p)
p
- the given coordinates.void moveMouse(int x, int y)
x
- X coordinate.y
- Y coordinate.void releaseMouse(@Nonnull MouseButton button)
button
- the mouse button to release.pressMouseWhileRunning(MouseButton, Runnable)
,
pressMouseWhileRunning(Component, Point, Runnable)
,
pressMouseWhileRunning(Point, MouseButton, Runnable)
,
pressMouseWhileRunning(Component, Point, MouseButton, Runnable)
void releaseMouseButtons()
void rotateMouseWheel(@Nonnull Component c, int amount)
Component
and rotates the scroll wheel on
wheel-equipped mice.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.void rotateMouseWheel(int amount)
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.void jitter(@Nonnull Component c)
Component
.c
- the given Component
.void jitter(@Nonnull Component c, @Nonnull Point where)
Component
at the given
point.c
- the given Component
.where
- the given point.void enterText(@Nonnull String text)
Component
that has input focus.text
- the text to enter.void type(char character)
Component
that
has input focus.character
- the character to type.void pressAndReleaseKey(int keyCode, @Nonnull int... modifiers)
java.awt.event.InputEvent
masks.keyCode
- the code of the key to press.modifiers
- the given modifiers.IllegalArgumentException
- if the given code is not a valid key code.void pressAndReleaseKeys(@Nonnull int... keyCodes)
keyCodes
- one or more codes of the keys to press.IllegalArgumentException
- if any of the given codes is not a valid key code.KeyEvent
void pressKey(int keyCode)
keyCode
- the code of the key to press.IllegalArgumentException
- if the given code is not a valid key code.KeyEvent
,
pressKeyWhileRunning(int, Runnable)
void pressKeyWhileRunning(int keyCode, @Nonnull Runnable runnable)
keyCode
- the code of the key to press.runnable
- the Runnable
to run while the key is pressedIllegalArgumentException
- if the given code is not a valid key code.KeyEvent
,
pressKey(int)
void releaseKey(int keyCode)
keyCode
- the code of the key to release.IllegalArgumentException
- if the given code is not a valid key code.KeyEvent
void pressModifiers(int modifierMask)
java.awt.event.InputEvent
.modifierMask
- the given mask.pressModifiersWhileRunning(int, Runnable)
,
InputEvent
void pressModifiersWhileRunning(int modifierMask, @Nonnull Runnable runnable)
java.awt.event.InputEvent
. Runs the given runnable and then releases the modifiers again.modifierMask
- the given mask.runnable
- the runnable being run while pressing the given buttonpressModifiers(int)
,
InputEvent
void releaseModifiers(int modifierMask)
java.awt.event.InputEvent
.modifierMask
- the given mask.InputEvent
void waitForIdle()
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.IllegalThreadStateException
- if this method is called from the event dispatch thread (EDT).boolean isDragging()
true
if the robot is currently in a dragging operation, false
otherwise.boolean isReadyForInput(@Nonnull Component c)
Component
is ready for input.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.@Nonnull JPopupMenu showPopupMenu(@Nonnull Component invoker)
JPopupMenu
.invoker
- the Component
to invoke the JPopupMenu
from.JPopupMenu
.ComponentLookupException
- if a JPopupMenu
cannot be found.@Nonnull JPopupMenu showPopupMenu(@Nonnull Component invoker, @Nonnull Point location)
JPopupMenu
at the given coordinates.invoker
- the Component
to invoke the JPopupMenu
from.location
- the given coordinates for the JPopupMenu
.JPopupMenu
.ComponentLookupException
- if a JPopupMenu
cannot be found.@Nullable JPopupMenu findActivePopupMenu()
JPopupMenu
or null
, if no pop-up is currently showing.void requireNoJOptionPaneIsShowing()
JOptionPane
showing, and potentially blocking GUI tests.AssertionError
- if there is one or more JOptionPane
s showing on the screen.boolean isActive()
Robot
is active. Being "active" means that cleanUp()
has not been called
yet.true
if this Robot
is active, false
otherwise.Copyright © 2014–2019 AssertJ. All rights reserved.