Package org.fest.swing.core
Class BasicRobot
java.lang.Object
org.fest.swing.core.BasicRobot
- All Implemented Interfaces:
Robot
Understands simulation of user events on a GUI
Component.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static final intprivate static final Runnableprivate final InputEventGeneratorprivate final AWTEventPosterprivate final ComponentFinderLooks ups.Componentprivate final ComponentHierarchyProvides access to all the components in the hierarchy.private static InputStateprivate static final intprivate static final ComponentMatcherprivate static final intprivate final Objectprivate final Settingsprivate static Toolkitprivate final UnexpectedJOptionPaneFinderprivate static final intprivate static WindowMonitor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Objectprivate voidActivates the given.Windowprivate voidactivateWindowOfFocusTarget(Component target, Component currentOwner) private JPopupMenuvoidcleanUp()Cleans up any used resources (keyboard, mouse, open windows and) used by this robot.ScreenLockprivate voidcleanUp(boolean disposeWindows) voidCleans up any used resources (keyboard, mouse and) used by this robot.ScreenLockvoidSimulates a user clicking once the givenusing the left mouse button.ComponentvoidSimulates a user clicking at the given position on the given.Componentvoidclick(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.Componentvoidclick(Component c, MouseButton button) Simulates a user clicking once the givenusing the given mouse button.Componentvoidclick(Component c, MouseButton button, int times) Simulates a user clicking the given mouse button, the given times on the given.Componentvoidclick(Point where, MouseButton button, int times) Simulates a user clicking the given mouse button, the given times at the given absolute coordinates.voidSimulates a user closing the given window.private static voiddispose(ComponentHierarchy hierarchy, Window w) private static voiddisposeWindows(ComponentHierarchy hierarchy) private voiddoPressKey(int keyCode) voidSimulates a user double-clicking the given.ComponentvoidSimulates a user entering the given text.Returns the currently active pop-up menu, if any.private Appletfinder()Returns thebeing used by this robot.ComponentFindervoidGives input focus to the given.Componentprivate voidvoidReturns thebeing used by this robot.ComponentHierarchyinvokerAndCenterOfInvoker(JPopupMenu popupMenu) booleanisActive()Indicates whether thisRobotis active.booleanIndicates whether the robot is currently in a dragging operation.booleanIndicates whether the givenis ready for input.Componentprivate booleanvoidMakes the mouse pointer show small quick jumpy movements on the given.ComponentvoidMakes the mouse pointer show small quick jumpy movements on the givenat the given point.Componentprivate KeyEventkeyEventFor(Component c, char character) private voidkeyPressAndRelease(int keyCode, int modifiers) private voidmouseRelease(int buttons) voidmoveMouse(int x, int y) Simulates a user moving the mouse pointer to the given coordinates.voidSimulates a user moving the mouse pointer to the center of the given.ComponentvoidSimulates a user moving the mouse pointer to the given coordinates relative to the given.ComponentvoidSimulates a user moving the mouse pointer to the given coordinates relative to the given.ComponentvoidSimulates a user moving the mouse pointer to the given coordinates.private voidprivate booleanpostInvocationEvent(EventQueue eventQueue, long timeout) voidpressAndReleaseKey(int keyCode, int... modifiers) Type the given key code with the given modifiers.voidpressAndReleaseKeys(int... keyCodes) Simulates a user pressing and releasing the given keys.voidpressKey(int keyCode) Simulates a user pressing given key.voidpressModifiers(int modifierMask) Presses the appropriate modifiers corresponding to the given mask.voidpressMouse(Component c, Point where) Simulates a user pressing the left mouse button on the given.ComponentvoidpressMouse(Component c, Point where, MouseButton button) Simulates a user pressing the given mouse button on the given.ComponentvoidpressMouse(Point where, MouseButton button) Simulates a user pressing the given mouse button on the given coordinates.voidpressMouse(MouseButton button) Simulates a user pressing a mouse button.printer()Returns thebeing used by this robot.BasicComponentPrintervoidreleaseKey(int keyCode) Simulates a user releasing the given key.voidreleaseModifiers(int modifierMask) Releases the appropriate modifiers corresponding to the given mask.voidreleaseMouse(MouseButton button) Releases the given mouse button.voidReleases any mouse button(s) used by the robot.private voidvoidEnsures that there is noshowing, and potentially blocking GUI tests.JOptionPanevoidSimulates a user right-clicking the given.Componentstatic RobotCreates a newthat has access to all the GUI components in the AWT hierarchy.Robotstatic RobotCreates a newwith a new AWT hierarchy.RobotvoidrotateMouseWheel(int amount) Rotates the scroll wheel on wheel-equipped mice.voidrotateMouseWheel(Component c, int amount) Moves the mouse pointer over to the givenand rotates the scroll wheel on wheel-equipped mice.Component(package private) final Objectprivate PointscrollIfNecessary(JComponent c, Point p) settings()Returns the configuration settings for this.Robotprivate booleanshowPopupMenu(Component invoker) Shows a pop-up menu.showPopupMenu(Component invoker, Point location) Shows a pop-up menu at the given coordinates.voidshowWindow(Window w) Safely display a window with proper EDT synchronization.voidshowWindow(Window w, Dimension size) Safely display a window with proper EDT synchronization.voidshowWindow(Window w, Dimension size, boolean pack) Safely display a window with proper EDT synchronization.voidtype(char character) Types the given character.private booleanwaitForComponentToBeReady(Component c, long timeout) voidWait for an idle AWT event queue.private voidwaitForIdle(EventQueue eventQueue) private voidprivate voidwindowAncestorsOf(Component one, Component two)
-
Field Details
-
POPUP_DELAY
private static final int POPUP_DELAY- See Also:
-
POPUP_TIMEOUT
private static final int POPUP_TIMEOUT- See Also:
-
WINDOW_DELAY
private static final int WINDOW_DELAY- See Also:
-
POPUP_MATCHER
-
active
private volatile boolean active -
EMPTY_RUNNABLE
-
BUTTON_MASK
private static final int BUTTON_MASK- See Also:
-
toolkit
-
windowMonitor
-
inputState
-
hierarchy
Provides access to all the components in the hierarchy. -
screenLockOwner
-
finder
Looks ups.Component -
settings
-
eventPoster
-
eventGenerator
-
unexpectedJOptionPaneFinder
-
-
Constructor Details
-
BasicRobot
BasicRobot(Object screenLockOwner, ComponentHierarchy hierarchy)
-
-
Method Details
-
robotWithNewAwtHierarchy
Creates a newwith a new AWT hierarchy. The createdRobotRobotwill not be able to access any components that were created before it.- Returns:
- the created
Robot.
-
robotWithCurrentAwtHierarchy
Creates a newthat has access to all the GUI components in the AWT hierarchy.Robot- Returns:
- the created
Robot.
-
acquireScreenLock
-
printer
Returns thebeing used by this robot.BasicComponentPrinter -
finder
Returns thebeing used by this robot.ComponentFinder -
showWindow
Safely display a window with proper EDT synchronization. This method blocks until theis showing and ready for input.Window- Specified by:
showWindowin interfaceRobot- Parameters:
w- the window to display.
-
showWindow
Safely display a window with proper EDT synchronization. This method blocks until theis showing and ready for input.Window- Specified by:
showWindowin interfaceRobot- 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.- Specified by:
showWindowin interfaceRobot- 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().
-
packAndEnsureSafePosition
-
waitForWindow
-
close
Simulates a user closing the given window. -
findAppletDescendent
- Parameters:
c- the givenContainer.- Returns:
- the
Appletdescendant of the givenContainer, ornullif none is found.
-
focusAndWaitForFocusGain
- Specified by:
focusAndWaitForFocusGainin interfaceRobot- Parameters:
c- the component to give focus to.
-
focus
Gives input focus to the given. Note that the component may not yet have focus when this method returns.Component -
focus
-
activateWindowOfFocusTarget
-
windowAncestorsOf
-
activate
Activates the given. "Activate" means that the given window gets the keyboard focus.Window- Parameters:
w- the window to activate.
-
cleanUp
Cleans up any used resources (keyboard, mouse, open windows and) used by this robot.ScreenLock -
cleanUpWithoutDisposingWindows
Cleans up any used resources (keyboard, mouse and) used by this robot. This method does not dispose any open windows.ScreenLockNote: The preferred method to use to clean up resources is
. UsingRobot.cleanUp()may leave many windows open after each test. Use it on very special cases. Please read bug 138 for more details.Robot.cleanUpWithoutDisposingWindows()- Specified by:
cleanUpWithoutDisposingWindowsin interfaceRobot
-
cleanUp
-
releaseScreenLock
private void releaseScreenLock() -
disposeWindows
-
dispose
-
click
Simulates a user clicking once the givenusing the left mouse button.Component -
rightClick
Simulates a user right-clicking the given.Component- Specified by:
rightClickin interfaceRobot- Parameters:
c- theComponentto click on.
-
click
Simulates a user clicking once the givenusing the given mouse button.Component -
doubleClick
Simulates a user double-clicking the given.Component- Specified by:
doubleClickin interfaceRobot- Parameters:
c- theComponentto click on.
-
click
Simulates a user clicking the given mouse button, the given times on the given.Component -
scrollIfNecessary
-
click
Simulates a user clicking at the given position on the given.Component -
click
Simulates a user clicking the given mouse button, the given times at the given absolute coordinates. -
click
Simulates a user clicking the given mouse button, the given times at the given position on the given.Component -
shouldSetDelayBetweenEventsToZeroWhenClicking
private boolean shouldSetDelayBetweenEventsToZeroWhenClicking(int times) -
pressModifiers
public void pressModifiers(int modifierMask) Presses the appropriate modifiers corresponding to the given mask. Use mask values from.InputEvent- Specified by:
pressModifiersin interfaceRobot- Parameters:
modifierMask- the given mask.- See Also:
-
releaseModifiers
public void releaseModifiers(int modifierMask) Releases the appropriate modifiers corresponding to the given mask. Use mask values from.InputEvent- Specified by:
releaseModifiersin interfaceRobot- Parameters:
modifierMask- the given mask.- See Also:
-
moveMouse
Simulates a user moving the mouse pointer to the center of the given.Component -
moveMouse
Simulates a user moving the mouse pointer to the given coordinates relative to the given.Component -
moveMouse
Simulates a user moving the mouse pointer to the given coordinates relative to the given.Component -
moveMouse
Simulates a user moving the mouse pointer to the given coordinates. -
moveMouse
public void moveMouse(int x, int y) Simulates a user moving the mouse pointer to the given coordinates. -
pressMouse
Simulates a user pressing a mouse button.- Specified by:
pressMousein interfaceRobot- Parameters:
button- the mouse button to press.
-
pressMouse
Simulates a user pressing the left mouse button on the given.Component- Specified by:
pressMousein interfaceRobot- Parameters:
c- theComponentto click on.where- the given coordinates, relative to the givenComponent.
-
pressMouse
Simulates a user pressing the given mouse button on the given.Component- Specified by:
pressMousein interfaceRobot- Parameters:
c- theComponentto 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.- Specified by:
pressMousein interfaceRobot- Parameters:
where- the position where to press the given mouse button.button- the mouse button to press.
-
releaseMouse
Releases the given mouse button.- Specified by:
releaseMousein interfaceRobot- Parameters:
button- the mouse button to release.
-
releaseMouseButtons
Releases any mouse button(s) used by the robot.- Specified by:
releaseMouseButtonsin interfaceRobot
-
rotateMouseWheel
Moves the mouse pointer over to the givenand rotates the scroll wheel on wheel-equipped mice.Component- Specified by:
rotateMouseWheelin interfaceRobot- 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
public void rotateMouseWheel(int amount) Rotates the scroll wheel on wheel-equipped mice.- Specified by:
rotateMouseWheelin interfaceRobot- 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 -
jitter
Makes the mouse pointer show small quick jumpy movements on the givenat the given point.Component -
waitForComponentToBeReady
-
invokerAndCenterOfInvoker
-
enterText
Simulates a user entering the given text. Note that this method the key strokes to the component that has input focus. -
type
Types the given character. Note that this method sends the key strokes to the component that has input focus. -
keyEventFor
-
pressAndReleaseKey
Type the given key code with the given modifiers. Modifiers is a mask from the availablemasks.InputEvent- Specified by:
pressAndReleaseKeyin interfaceRobot- Parameters:
keyCode- the code of the key to press.modifiers- the given modifiers.
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys. This method does not affect the current focus.- Specified by:
pressAndReleaseKeysin interfaceRobot- Parameters:
keyCodes- one or more codes of the keys to press.- See Also:
-
keyPressAndRelease
-
pressKey
Simulates a user pressing given key. This method does not affect the current focus. -
doPressKey
-
releaseKey
Simulates a user releasing the given key. This method does not affect the current focus.- Specified by:
releaseKeyin interfaceRobot- Parameters:
keyCode- the code of the key to release.- See Also:
-
mouseRelease
-
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.- Specified by:
waitForIdlein interfaceRobot
-
waitIfNecessary
private void waitIfNecessary() -
waitForIdle
-
postInvocationEvent
-
isDragging
public boolean isDragging()Indicates whether the robot is currently in a dragging operation.- Specified by:
isDraggingin interfaceRobot- Returns:
trueif the robot is currently in a dragging operation,falseotherwise.
-
showPopupMenu
Shows a pop-up menu.- Specified by:
showPopupMenuin interfaceRobot- Parameters:
invoker- the component to invoke the pop-up menu from.- Returns:
- the displayed pop-up menu.
-
showPopupMenu
Shows a pop-up menu at the given coordinates.- Specified by:
showPopupMenuin interfaceRobot- 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.
-
isWindowAncestorReadyForInput
-
isReadyForInput
Indicates whether the givenis ready for input.ComponentNote: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.
- Specified by:
isReadyForInputin interfaceRobot- Parameters:
c- the givenComponent.- Returns:
trueif the givenComponentis ready for input,falseotherwise.- Throws:
ActionFailedException- if the givenComponentdoes not have aWindowancestor.
-
findActivePopupMenu
Returns the currently active pop-up menu, if any. If no pop-up is currently showing, returnsnull.- Specified by:
findActivePopupMenuin interfaceRobot- Returns:
- the currently active pop-up menu or
null, if no pop-up is currently showing.
-
activePopupMenu
-
requireNoJOptionPaneIsShowing
Ensures that there is noshowing, and potentially blocking GUI tests.JOptionPane- Specified by:
requireNoJOptionPaneIsShowingin interfaceRobot
-
settings
Returns the configuration settings for this.Robot -
hierarchy
Returns thebeing used by this robot.ComponentHierarchy -
isActive
public boolean isActive()Indicates whether thisRobotis active. Being "active" means thathas not been called yet.Robot.cleanUp() -
screenLockOwner
-