Package org.fest.swing.core
Interface Robot
- All Known Implementing Classes:
BasicRobot
public interface Robot
Understands simulation of user events on a GUI
Component
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanUp()
Cleans up any used resources (keyboard, mouse, open windows and
) used by this robot.ScreenLock
void
Cleans up any used resources (keyboard, mouse and
) used by this robot.ScreenLock
void
Simulates a user clicking once the given
using the left mouse button.Component
void
Simulates a user clicking at the given position on the given
.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
.Component
void
click
(Component c, MouseButton button) Simulates a user clicking once the given
using the given mouse button.Component
void
click
(Component c, MouseButton button, int times) Simulates a user clicking the given mouse button, the given times on the given
.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
Simulates a user closing the given window.void
Simulates a user double-clicking the given
.Component
void
Simulates a user entering the given text.Returns the currently active pop-up menu, if any.finder()
Returns the
being used by this robot.ComponentFinder
void
Gives input focus to the given
.Component
void
Returns the
being used by this robot.ComponentHierarchy
boolean
isActive()
Indicates whether thisRobot
is active.boolean
Indicates whether the robot is currently in a dragging operation.boolean
Indicates whether the given
is ready for input.Component
void
Makes the mouse pointer show small quick jumpy movements on the given
.Component
void
Makes the mouse pointer show small quick jumpy movements on the given
at the given point.Component
void
moveMouse
(int x, int y) Simulates a user moving the mouse pointer to the given coordinates.void
Simulates a user moving the mouse pointer to the center of the given
.Component
void
Simulates a user moving the mouse pointer to the given coordinates relative to the given
.Component
void
Simulates a user moving the mouse pointer to the given coordinates relative to the given
.Component
void
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
pressModifiers
(int modifierMask) 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
.Component
void
pressMouse
(Component c, Point where, MouseButton button) Simulates a user pressing the given mouse button on the given
.Component
void
pressMouse
(Point where, MouseButton button) Simulates a user pressing the given mouse button on the given coordinates.void
pressMouse
(MouseButton button) Simulates a user pressing a mouse button.printer()
Returns the
being used by this robot.BasicComponentPrinter
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
Releases any mouse button(s) used by the robot.void
Ensures that there is no
showing, and potentially blocking GUI tests.JOptionPane
void
Simulates a user right-clicking the given
.Component
void
rotateMouseWheel
(int amount) Rotates the scroll wheel on wheel-equipped mice.void
rotateMouseWheel
(Component c, int amount) Moves the mouse pointer over to the given
and rotates the scroll wheel on wheel-equipped mice.Component
settings()
Returns the configuration settings for this
.Robot
showPopupMenu
(Component invoker) Shows a pop-up menu.showPopupMenu
(Component invoker, Point location) Shows a pop-up menu at the given coordinates.void
showWindow
(Window w) Safely display a window with proper EDT synchronization.void
showWindow
(Window w, Dimension size) Safely display a window with proper EDT synchronization.void
showWindow
(Window w, Dimension size, boolean pack) Safely display a window with proper EDT synchronization.void
type
(char character) Types the given character.void
Wait for an idle AWT event queue.
-
Method Details
-
hierarchy
ComponentHierarchy hierarchy()Returns the
being used by this robot.ComponentHierarchy
- Returns:
- the
ComponentHierarchy
being used by this robot.
-
finder
ComponentFinder finder()Returns the
being used by this robot.ComponentFinder
- Returns:
- the
ComponentFinder
being used by this robot.
-
printer
ComponentPrinter printer()Returns the
being used by this robot.BasicComponentPrinter
- Returns:
- the
ComponentPrinter
being used by this robot.
-
showWindow
Safely display a window with proper EDT synchronization. This method blocks until the
is showing and ready for input.Window
- Parameters:
w
- the window to display.
-
showWindow
Safely display a window with proper EDT synchronization. This method blocks until the
is showing and ready for input.Window
- Parameters:
w
- the window to display.size
- the size of the window to display.
-
showWindow
Safely display a 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. The window will be packed if the pack flag is set, and set to the given size if it is non-
Modal dialogs may be shown with this method without blocking.null
.- Parameters:
w
- the window to display.size
- the size of the window to display.pack
- flag that indicates if the window should be packed or not. By packed we mean callingw.pack()
.
-
close
Simulates a user closing the given window.- Parameters:
w
- the window to close.
-
focus
Gives input focus to the given
. Note that the component may not yet have focus when this method returns.Component
- Parameters:
c
- the component to give focus to.
-
focusAndWaitForFocusGain
- Parameters:
c
- the component to give focus to.
-
cleanUp
void cleanUp()Cleans up any used resources (keyboard, mouse, open windows and
) used by this robot.ScreenLock
-
cleanUpWithoutDisposingWindows
void cleanUpWithoutDisposingWindows()Cleans up any used resources (keyboard, mouse and
) used by this robot. This method does not dispose any open windows.ScreenLock
Note: The preferred method to use to clean up resources is
. UsingcleanUp()
may leave many windows open after each test. Use it on very special cases. Please read bug 138 for more details.cleanUpWithoutDisposingWindows()
-
click
Simulates a user clicking once the given
using the left mouse button.Component
- Parameters:
c
- theComponent
to click on.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
rightClick
Simulates a user right-clicking the given
.Component
- Parameters:
c
- theComponent
to click on.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
click
Simulates a user clicking once the given
using the given mouse button.Component
- Parameters:
c
- theComponent
to click on.button
- the mouse button to use.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
doubleClick
Simulates a user double-clicking the given
.Component
- Parameters:
c
- theComponent
to click on.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
click
Simulates a user clicking the given mouse button, the given times on the given
.Component
- Parameters:
c
- theComponent
to click on.button
- the mouse button to click.times
- the number of times to click the given mouse button.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
click
Simulates a user clicking at the given position on the given
.Component
- Parameters:
c
- theComponent
to click on.where
- the given coordinates, relative to the givenComponent
.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
click
Simulates a user clicking the given mouse button, the given times at the given position on the given
.Component
- Parameters:
c
- theComponent
to click on.where
- the given coordinates, relative to the givenComponent
.button
- the mouse button to click.times
- the number of times to click the given mouse button.- Throws:
ActionFailedException
- if the component to click is out of the boundaries of the screen.
-
click
Simulates a user clicking the given mouse button, the given times at the given absolute coordinates.- Parameters:
where
- the coordinates where to click.button
- the mouse button to click.times
- the number of times to click the given mouse button.
-
pressMouse
Simulates a user pressing a mouse button.- Parameters:
button
- the mouse button to press.
-
pressMouse
Simulates a user pressing the left mouse button on the given
.Component
- Parameters:
c
- theComponent
to click on.where
- the given coordinates, relative to the givenComponent
.
-
pressMouse
Simulates a user pressing the given mouse button on the given
.Component
- Parameters:
c
- theComponent
to click on.where
- the given coordinates, relative to the givenComponent
.button
- the mouse button to press.
-
pressMouse
Simulates a user pressing the given mouse button on the given coordinates.- Parameters:
where
- the position where to press the given mouse button.button
- the mouse button to press.- Since:
- 1.1
-
moveMouse
Simulates a user moving the mouse pointer to the center of the given
.Component
- Parameters:
c
- the givenComponent
.
-
moveMouse
Simulates a user moving the mouse pointer to the given coordinates relative to the given
.Component
- Parameters:
c
- the givenComponent
.p
- the given coordinates, relative to the givenComponent
.- Throws:
ActionFailedException
- if the given component is not showing and ready for input.
-
moveMouse
Simulates a user moving the mouse pointer to the given coordinates relative to the given
.Component
- Parameters:
c
- the givenComponent
.x
- X coordinate, relative to the givenComponent
.y
- Y coordinate, relative to the givenComponent
.- Throws:
ActionFailedException
- if the given component is not showing and ready for input.
-
moveMouse
Simulates a user moving the mouse pointer to the given coordinates.- Parameters:
p
- the given coordinates.- Since:
- 1.1
-
moveMouse
void moveMouse(int x, int y) Simulates a user moving the mouse pointer to the given coordinates.- Parameters:
x
- X coordinate.y
- Y coordinate.- Since:
- 1.1
-
releaseMouse
Releases the given mouse button.- Parameters:
button
- the mouse button to release.
-
releaseMouseButtons
void releaseMouseButtons()Releases any mouse button(s) used by the robot. -
rotateMouseWheel
Moves the mouse pointer over to the given
and rotates the scroll wheel on wheel-equipped mice.Component
- Parameters:
c
- the givenComponent
.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.
-
rotateMouseWheel
void rotateMouseWheel(int amount) Rotates the scroll wheel on wheel-equipped mice.- Parameters:
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.
-
jitter
Makes the mouse pointer show small quick jumpy movements on the given
.Component
- Parameters:
c
- the givenComponent
.
-
jitter
Makes the mouse pointer show small quick jumpy movements on the given
at the given point.Component
- Parameters:
c
- the givenComponent
.where
- the given point.
-
enterText
Simulates a user entering the given text. Note that this method the key strokes to the component that has input focus.- Parameters:
text
- the text to enter.
-
type
void type(char character) Types the given character. Note that this method sends the key strokes to the component that has input focus.- Parameters:
character
- the character to type.
-
pressAndReleaseKey
void pressAndReleaseKey(int keyCode, int... modifiers) Type the given key code with the given modifiers. Modifiers is a mask from the available
masks.InputEvent
- Parameters:
keyCode
- the code of the key to press.modifiers
- the given modifiers.- Throws:
IllegalArgumentException
- if the given code is not a valid key code.
-
pressAndReleaseKeys
void pressAndReleaseKeys(int... keyCodes) Simulates a user pressing and releasing the given keys. This method does not affect the current focus.- Parameters:
keyCodes
- one or more codes of the keys to press.- Throws:
IllegalArgumentException
- if any of the given codes is not a valid key code.- See Also:
-
pressKey
void pressKey(int keyCode) Simulates a user pressing given key. This method does not affect the current focus.- Parameters:
keyCode
- the code of the key to press.- Throws:
IllegalArgumentException
- if the given code is not a valid key code.- See Also:
-
releaseKey
void releaseKey(int keyCode) Simulates a user releasing the given key. This method does not affect the current focus.- Parameters:
keyCode
- the code of the key to release.- Throws:
IllegalArgumentException
- if the given code is not a valid key code.- See Also:
-
pressModifiers
void pressModifiers(int modifierMask) Presses the appropriate modifiers corresponding to the given mask. Use mask values from
.InputEvent
- Parameters:
modifierMask
- the given mask.- See Also:
-
releaseModifiers
void releaseModifiers(int modifierMask) Releases the appropriate modifiers corresponding to the given mask. Use mask values from
.InputEvent
- Parameters:
modifierMask
- the given mask.- See Also:
-
waitForIdle
void waitForIdle()Wait for an idle AWT event queue. Note that this is different from the implementation ofjava.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.- Throws:
IllegalThreadStateException
- if this method is called from the event dispatch thread.
-
isDragging
boolean isDragging()Indicates whether the robot is currently in a dragging operation.- Returns:
true
if the robot is currently in a dragging operation,false
otherwise.
-
isReadyForInput
Indicates whether the given
is ready for input.Component
- Parameters:
c
- the givenComponent
.- Returns:
true
if the givenComponent
is ready for input,false
otherwise.- Throws:
ActionFailedException
- if the givenComponent
does not have aWindow
ancestor.
-
showPopupMenu
Shows a pop-up menu.- Parameters:
invoker
- the component to invoke the pop-up menu from.- Returns:
- the displayed pop-up menu.
- Throws:
ComponentLookupException
- if a pop-up menu cannot be found.
-
showPopupMenu
Shows a pop-up menu at the given coordinates.- Parameters:
invoker
- the component to invoke the pop-up menu from.location
- the given coordinates for the pop-up menu.- Returns:
- the displayed pop-up menu.
- Throws:
ComponentLookupException
- if a pop-up menu cannot be found.
-
findActivePopupMenu
JPopupMenu findActivePopupMenu()Returns the currently active pop-up menu, if any. If no pop-up is currently showing, returnsnull
.- Returns:
- the currently active pop-up menu or
null
, if no pop-up is currently showing.
-
requireNoJOptionPaneIsShowing
void requireNoJOptionPaneIsShowing()Ensures that there is no
showing, and potentially blocking GUI tests.JOptionPane
- Throws:
AssertionError
- if there is one or moreJOptionPane
s showing on the screen.
-
settings
Settings settings()Returns the configuration settings for this
.Robot
- Returns:
- the configuration settings for this
Robot
.
-
isActive
boolean isActive()Indicates whether thisRobot
is active. Being "active" means that
has not been called yet.cleanUp()
- Returns:
true
if thisRobot
is active,false
otherwise.
-