Package org.fest.swing.driver
Class ComponentDriver
java.lang.Object
org.fest.swing.driver.ComponentDriver
- Direct Known Subclasses:
ContainerDriver
,JAppletDriver
Understands functional testing of
Component
s:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture
in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ComponentDragAndDrop
private static final String
protected final Robot
private static final String
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
Validates that the given
is enabled and showing on the screen.Component
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, 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
(Component c, MouseClickInfo mouseClickInfo) Simulates a user clicking the given mouse button, the given times on the given
.Component
void
Simulates a user double-clicking the given
.Component
protected final void
Performs a drag action at the given point.protected final void
Move the mouse appropriately to get from the source to the destination.protected final void
Ends a drag operation, releasing the mouse button over the given target location.private static org.fest.assertions.Description
void
Gives input focus to the given
.Component
void
Shows a pop-up menu using the given
as the invoker of the pop-up menu.Component
invokePopupMenu
(Component c, Point p) Shows a pop-up menu at the given point using the given
as the invoker of the pop-up menu.Component
protected final void
moveMouseIgnoringAnyError
(Component c, int x, int y) Simulates a user moving the mouse pointer to the given coordinates relative to the given
.Component
protected final void
Simulates a user moving the mouse pointer to the given coordinates relative to the given
.Component
protected final void
Performs the
in the givenAccessibleAction
's event queue.Component
void
pressAndReleaseKey
(Component c, int keyCode, int[] modifiers) Simulates a user pressing and releasing the given key on the
.Component
void
pressAndReleaseKey
(Component c, KeyPressInfo keyPressInfo) Simulates a user pressing and releasing the given key on the
.Component
void
pressAndReleaseKeys
(Component c, int... keyCodes) Simulates a user pressing and releasing the given keys on the
.Component
void
Simulates a user pressing given key on the
.Component
static org.fest.assertions.Description
propertyName
(Component c, String propertyName) Formats the name of a property of the given
by concatenating the value obtained fromComponent
with the given property name.Formatting.format(Component)
void
releaseKey
(Component c, int keyCode) Simulates a user releasing the given key on the
.Component
private static org.fest.assertions.Description
void
Asserts that the
is disabled.Component
void
Asserts that the
is enabled.Component
void
requireEnabled
(Component c, Timeout timeout) Asserts that the
is enabled.Component
void
Asserts that the
has input focus.Component
void
Asserts that the
is not visible.Component
void
requireSize
(Component c, Dimension size) Asserts that the size of the
is equal to given one.Component
void
Asserts that the
is visible.Component
void
Simulates a user right-clicking the given
.Component
protected Settings
settings()
private static org.fest.assertions.Description
protected final boolean
waitForShowing
(Component c, long timeout) Wait the given number of milliseconds for the
to be showing and ready.Component
-
Field Details
-
ENABLED_PROPERTY
- See Also:
-
SIZE_PROPERTY
- See Also:
-
VISIBLE_PROPERTY
- See Also:
-
robot
-
dragAndDrop
-
-
Constructor Details
-
ComponentDriver
Creates a newComponentDriver
.- Parameters:
robot
- the robot to use to simulate user input.
-
-
Method Details
-
click
Simulates a user clicking once the given
using the left mouse button.Component
- Parameters:
c
- theComponent
to click on.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on 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:
NullPointerException
- if the givenMouseButton
isnull
.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
click
Simulates a user clicking the given mouse button, the given times on the given
.Component
- Parameters:
c
- theComponent
to click on.mouseClickInfo
- specifies the button to click and the times the button should be clicked.- Throws:
NullPointerException
- if the givenMouseClickInfo
isnull
.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
doubleClick
Simulates a user double-clicking the given
.Component
- Parameters:
c
- theComponent
to click on.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
rightClick
Simulates a user right-clicking the given
.Component
- Parameters:
c
- theComponent
to click on.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on 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:
NullPointerException
- if the givenMouseButton
isnull
.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
click
Simulates a user clicking at the given position on the given
.Component
- Parameters:
c
- theComponent
to click on.where
- the position where to click.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
settings
-
requireSize
Asserts that the size of the
is equal to given one.Component
- Parameters:
c
- the target component.size
- the given size to match.- Throws:
AssertionError
- if the size of theWindow
is not equal to the given size.
-
requireVisible
Asserts that the
is visible.Component
- Parameters:
c
- the target component.- Throws:
AssertionError
- if theComponent
is not visible.
-
requireNotVisible
Asserts that the
is not visible.Component
- Parameters:
c
- the target component.- Throws:
AssertionError
- if theComponent
is visible.
-
visibleProperty
-
requireFocused
Asserts that the
has input focus.Component
- Parameters:
c
- the target component.- Throws:
AssertionError
- if theComponent
does not have input focus.
-
requiredFocusedErrorMessage
-
requireEnabled
Asserts that the
is enabled.Component
- Parameters:
c
- the target component.- Throws:
AssertionError
- if theComponent
is disabled.
-
requireEnabled
Asserts that the
is enabled.Component
- Parameters:
c
- the target component.timeout
- the time this fixture will wait for the component to be enabled.- Throws:
WaitTimedOutError
- if theComponent
is never enabled.
-
requireDisabled
Asserts that the
is disabled.Component
- Parameters:
c
- the target component.- Throws:
AssertionError
- if theComponent
is enabled.
-
enabledProperty
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys on the
.Component
- Parameters:
c
- the target component.keyCodes
- one or more codes of the keys to press.- Throws:
NullPointerException
- if the given array of codes isnull
.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.IllegalArgumentException
- if the given code is not a valid key code.- See Also:
-
pressAndReleaseKey
Simulates a user pressing and releasing the given key on the
. Modifiers is a mask from the availableComponent
masks.InputEvent
- Parameters:
c
- the target component.keyPressInfo
- specifies the key and modifiers to press.- Throws:
NullPointerException
- if the givenKeyPressInfo
isnull
.IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.- See Also:
-
pressAndReleaseKey
Simulates a user pressing and releasing the given key on the
. Modifiers is a mask from the availableComponent
masks.InputEvent
- Parameters:
c
- the target component.keyCode
- the code of the key to press.modifiers
- the given modifiers.- Throws:
IllegalArgumentException
- if the given code is not a valid key code. *IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.- See Also:
-
pressKey
Simulates a user pressing given key on the
.Component
- Parameters:
c
- the target component.keyCode
- the code of the key to press.- Throws:
IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.- See Also:
-
releaseKey
Simulates a user releasing the given key on the
.Component
- Parameters:
c
- the target component.keyCode
- the code of the key to release.- Throws:
IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.- See Also:
-
focusAndWaitForFocusGain
- Parameters:
c
- the component to give focus to.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
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.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
drag
Performs a drag action at the given point.- Parameters:
c
- the target component.where
- the point where to start the drag action.
-
drop
Ends a drag operation, releasing the mouse button over the given target location.This method is tuned for native drag/drop operations, so if you get odd behavior, you might try using a simple
andRobot.moveMouse(Component, int, int)
.Robot.releaseMouseButtons()
- Parameters:
c
- the target component.where
- the point where the drag operation ends.- Throws:
ActionFailedException
- if there is no drag action in effect.
-
dragOver
Move the mouse appropriately to get from the source to the destination. Enter/exit events will be generated where appropriate.- Parameters:
c
- the target component.where
- the point to drag over.
-
performAccessibleActionOf
Performs the
in the givenAccessibleAction
's event queue.Component
Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.
- Parameters:
c
- the givenComponent
.- Throws:
ActionFailedException
- ifaction
isnull
or empty.
-
waitForShowing
Wait the given number of milliseconds for the
to be showing and ready. ReturnsComponent
false
if the operation times out.Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.
- Parameters:
c
- the givenComponent
.timeout
- the time in milliseconds to wait for theComponent
to be showing and ready.- Returns:
true
if theComponent
is showing and ready,false
otherwise.
-
invokePopupMenu
Shows a pop-up menu using the given
as the invoker of the pop-up menu.Component
- Parameters:
c
- the invoker of theJPopupMenu
.- Returns:
- the displayed pop-up menu.
- Throws:
IllegalStateException
- if the givenComponent
is disabled.IllegalStateException
- if the givenComponent
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-
invokePopupMenu
Shows a pop-up menu at the given point using the given
as the invoker of the pop-up menu.Component
- Parameters:
c
- the invoker of theJPopupMenu
.p
- the given point where to show the pop-up menu.- Returns:
- the displayed pop-up menu.
- Throws:
NullPointerException
- if the given point isnull
.IllegalStateException
- if the givenComponent
is disabled.IllegalStateException
- if the givenComponent
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-
assertIsEnabledAndShowing
Validates that the given
is enabled and showing on the screen. This method is executed in the event dispatch thread.Component
- Parameters:
c
- theComponent
to check.- Throws:
IllegalStateException
- if theComponent
is disabled.IllegalStateException
- if theComponent
is not showing on the screen.
-
propertyName
@RunsInEDT public static org.fest.assertions.Description propertyName(Component c, String propertyName) Formats the name of a property of the given
by concatenating the value obtained fromComponent
with the given property name.Formatting.format(Component)
- Parameters:
c
- the givenComponent
.propertyName
- the name of the property.- Returns:
- the description of a property belonging to a
Component
. - See Also:
-
moveMouseIgnoringAnyError
Simulates a user moving the mouse pointer to the given coordinates relative to the given
. This method will not throw any exceptions if the it was not possible to move the mouse pointer.Component
- Parameters:
c
- the givenComponent
.p
- coordinates relative to the givenComponent
.
-
moveMouseIgnoringAnyError
Simulates a user moving the mouse pointer to the given coordinates relative to the given
. This method will not throw any exceptions if the it was not possible to move the mouse pointer.Component
- Parameters:
c
- the givenComponent
.x
- horizontal coordinate relative to the givenComponent
.y
- vertical coordinate relative to the givenComponent
.
-