Package org.fest.swing.driver
Class ComponentDriver
java.lang.Object
org.fest.swing.driver.ComponentDriver
- Direct Known Subclasses:
ContainerDriver,JAppletDriver
Understands functional testing of
Components:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ComponentDragAndDropprivate static final Stringprotected final Robotprivate static final Stringprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidValidates that the givenis enabled and showing on the screen.ComponentvoidSimulates a user clicking once the givenusing the left mouse button.ComponentvoidSimulates a user clicking 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(Component c, MouseClickInfo mouseClickInfo) Simulates a user clicking the given mouse button, the given times on the given.ComponentvoidSimulates a user double-clicking the given.Componentprotected final voidPerforms a drag action at the given point.protected final voidMove the mouse appropriately to get from the source to the destination.protected final voidEnds a drag operation, releasing the mouse button over the given target location.private static org.fest.assertions.DescriptionvoidGives input focus to the given.ComponentvoidShows a pop-up menu using the givenas the invoker of the pop-up menu.ComponentinvokePopupMenu(Component c, Point p) Shows a pop-up menu at the given point using the givenas the invoker of the pop-up menu.Componentprotected final voidmoveMouseIgnoringAnyError(Component c, int x, int y) Simulates a user moving the mouse pointer to the given coordinates relative to the given.Componentprotected final voidSimulates a user moving the mouse pointer to the given coordinates relative to the given.Componentprotected final voidPerforms thein the givenAccessibleAction's event queue.ComponentvoidpressAndReleaseKey(Component c, int keyCode, int[] modifiers) Simulates a user pressing and releasing the given key on the.ComponentvoidpressAndReleaseKey(Component c, KeyPressInfo keyPressInfo) Simulates a user pressing and releasing the given key on the.ComponentvoidpressAndReleaseKeys(Component c, int... keyCodes) Simulates a user pressing and releasing the given keys on the.ComponentvoidSimulates a user pressing given key on the.Componentstatic org.fest.assertions.DescriptionpropertyName(Component c, String propertyName) Formats the name of a property of the givenby concatenating the value obtained fromComponentwith the given property name.Formatting.format(Component)voidreleaseKey(Component c, int keyCode) Simulates a user releasing the given key on the.Componentprivate static org.fest.assertions.DescriptionvoidAsserts that theis disabled.ComponentvoidAsserts that theis enabled.ComponentvoidrequireEnabled(Component c, Timeout timeout) Asserts that theis enabled.ComponentvoidAsserts that thehas input focus.ComponentvoidAsserts that theis not visible.ComponentvoidrequireSize(Component c, Dimension size) Asserts that the size of theis equal to given one.ComponentvoidAsserts that theis visible.ComponentvoidSimulates a user right-clicking the given.Componentprotected Settingssettings()private static org.fest.assertions.Descriptionprotected final booleanwaitForShowing(Component c, long timeout) Wait the given number of milliseconds for theto 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 givenusing the left mouse button.Component- Parameters:
c- theComponentto click on.- Throws:
IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
click
Simulates a user clicking once the givenusing the given mouse button.Component- Parameters:
c- theComponentto click on.button- the mouse button to use.- Throws:
NullPointerException- if the givenMouseButtonisnull.IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
click
Simulates a user clicking the given mouse button, the given times on the given.Component- Parameters:
c- theComponentto click on.mouseClickInfo- specifies the button to click and the times the button should be clicked.- Throws:
NullPointerException- if the givenMouseClickInfoisnull.IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
doubleClick
Simulates a user double-clicking the given.Component- Parameters:
c- theComponentto click on.- Throws:
IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
rightClick
Simulates a user right-clicking the given.Component- Parameters:
c- theComponentto click on.- Throws:
IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
click
Simulates a user clicking the given mouse button, the given times on the given.Component- Parameters:
c- theComponentto click on.button- the mouse button to click.times- the number of times to click the given mouse button.- Throws:
NullPointerException- if the givenMouseButtonisnull.IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
click
Simulates a user clicking at the given position on the given.Component- Parameters:
c- theComponentto click on.where- the position where to click.- Throws:
IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.
-
settings
-
requireSize
Asserts that the size of theis equal to given one.Component- Parameters:
c- the target component.size- the given size to match.- Throws:
AssertionError- if the size of theWindowis not equal to the given size.
-
requireVisible
Asserts that theis visible.Component- Parameters:
c- the target component.- Throws:
AssertionError- if theComponentis not visible.
-
requireNotVisible
Asserts that theis not visible.Component- Parameters:
c- the target component.- Throws:
AssertionError- if theComponentis visible.
-
visibleProperty
-
requireFocused
Asserts that thehas input focus.Component- Parameters:
c- the target component.- Throws:
AssertionError- if theComponentdoes not have input focus.
-
requiredFocusedErrorMessage
-
requireEnabled
Asserts that theis enabled.Component- Parameters:
c- the target component.- Throws:
AssertionError- if theComponentis disabled.
-
requireEnabled
Asserts that theis enabled.Component- Parameters:
c- the target component.timeout- the time this fixture will wait for the component to be enabled.- Throws:
WaitTimedOutError- if theComponentis never enabled.
-
requireDisabled
Asserts that theis disabled.Component- Parameters:
c- the target component.- Throws:
AssertionError- if theComponentis 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 theComponentis disabled.IllegalStateException- if theComponentis 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 availableComponentmasks.InputEvent- Parameters:
c- the target component.keyPressInfo- specifies the key and modifiers to press.- Throws:
NullPointerException- if the givenKeyPressInfoisnull.IllegalArgumentException- if the given code is not a valid key code.IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis 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 availableComponentmasks.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 theComponentis disabled.IllegalStateException- if theComponentis 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 theComponentis disabled.IllegalStateException- if theComponentis 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 theComponentis disabled.IllegalStateException- if theComponentis not showing on the screen.- See Also:
-
focusAndWaitForFocusGain
- Parameters:
c- the component to give focus to.- Throws:
IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis 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 theComponentis disabled.IllegalStateException- if theComponentis 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 thein the givenAccessibleAction's event queue.ComponentNote: 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- ifactionisnullor empty.
-
waitForShowing
Wait the given number of milliseconds for theto be showing and ready. ReturnsComponentfalseif 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 theComponentto be showing and ready.- Returns:
trueif theComponentis showing and ready,falseotherwise.
-
invokePopupMenu
Shows a pop-up menu using the givenas the invoker of the pop-up menu.Component- Parameters:
c- the invoker of theJPopupMenu.- Returns:
- the displayed pop-up menu.
- Throws:
IllegalStateException- if the givenComponentis disabled.IllegalStateException- if the givenComponentis 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 givenas 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 givenComponentis disabled.IllegalStateException- if the givenComponentis not showing on the screen.ComponentLookupException- if a pop-up menu cannot be found.
-
assertIsEnabledAndShowing
Validates that the givenis enabled and showing on the screen. This method is executed in the event dispatch thread.Component- Parameters:
c- theComponentto check.- Throws:
IllegalStateException- if theComponentis disabled.IllegalStateException- if theComponentis 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 givenby concatenating the value obtained fromComponentwith 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.
-