public class ComponentDriver extends Object
Component
s:
org.fest.swing.fixture
in your tests.Constructor and Description |
---|
ComponentDriver(Robot robot)
Creates a new
ComponentDriver . |
Modifier and Type | Method and Description |
---|---|
protected static void |
assertIsEnabledAndShowing(Component c)
Validates that the given
is enabled and showing on the screen. |
void |
click(Component c)
Simulates a user clicking once the given
using the left mouse button. |
void |
click(Component c,
MouseButton button)
Simulates a user clicking once the given
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
. |
void |
click(Component c,
MouseClickInfo mouseClickInfo)
Simulates a user clicking the given mouse button, the given times on the given
. |
void |
click(Component c,
Point where)
Simulates a user clicking at the given position on the given
. |
void |
doubleClick(Component c)
Simulates a user double-clicking the given
. |
protected void |
drag(Component c,
Point where)
Performs a drag action at the given point.
|
protected void |
dragOver(Component c,
Point where)
Move the mouse appropriately to get from the source to the destination.
|
protected void |
drop(Component c,
Point where)
Ends a drag operation, releasing the mouse button over the given target location.
|
void |
focus(Component c)
Gives input focus to the given
. |
void |
focusAndWaitForFocusGain(Component c)
|
JPopupMenu |
invokePopupMenu(Component c)
Shows a pop-up menu using the given
as the invoker of the pop-up menu. |
JPopupMenu |
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. |
protected void |
moveMouseIgnoringAnyError(Component c,
int x,
int y)
Simulates a user moving the mouse pointer to the given coordinates relative to the given
. |
protected void |
moveMouseIgnoringAnyError(Component c,
Point p)
Simulates a user moving the mouse pointer to the given coordinates relative to the given
. |
protected void |
performAccessibleActionOf(Component c)
Performs the
in the given 's event queue. |
void |
pressAndReleaseKey(Component c,
int keyCode,
int[] modifiers)
Simulates a user pressing and releasing the given key on the
. |
void |
pressAndReleaseKey(Component c,
KeyPressInfo keyPressInfo)
Simulates a user pressing and releasing the given key on the
. |
void |
pressAndReleaseKeys(Component c,
int... keyCodes)
Simulates a user pressing and releasing the given keys on the
. |
void |
pressKey(Component c,
int keyCode)
Simulates a user pressing given key on the
. |
static org.fest.assertions.Description |
propertyName(Component c,
String propertyName)
Formats the name of a property of the given
by concatenating the value obtained
from with the given property name. |
void |
releaseKey(Component c,
int keyCode)
Simulates a user releasing the given key on the
. |
void |
requireDisabled(Component c)
Asserts that the
is disabled. |
void |
requireEnabled(Component c)
Asserts that the
is enabled. |
void |
requireEnabled(Component c,
Timeout timeout)
Asserts that the
is enabled. |
void |
requireFocused(Component c)
Asserts that the
has input focus. |
void |
requireNotVisible(Component c)
Asserts that the
is not visible. |
void |
requireSize(Component c,
Dimension size)
Asserts that the size of the
is equal to given one. |
void |
requireVisible(Component c)
Asserts that the
is visible. |
void |
rightClick(Component c)
Simulates a user right-clicking the given
. |
protected Settings |
settings() |
protected boolean |
waitForShowing(Component c,
long timeout)
Wait the given number of milliseconds for the
to be showing and ready. |
protected final Robot robot
public ComponentDriver(Robot robot)
ComponentDriver
.robot
- the robot to use to simulate user input.@RunsInEDT public void click(Component c)
Component
using the left mouse button.c
- the Component
to click on.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void click(Component c, MouseButton button)
Component
using the given mouse button.c
- the Component
to click on.button
- the mouse button to use.NullPointerException
- if the given MouseButton
is null
.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void click(Component c, MouseClickInfo mouseClickInfo)
Component
.c
- the Component
to click on.mouseClickInfo
- specifies the button to click and the times the button should be clicked.NullPointerException
- if the given MouseClickInfo
is null
.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void doubleClick(Component c)
Component
.c
- the Component
to click on.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void rightClick(Component c)
Component
.c
- the Component
to click on.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void click(Component c, 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.NullPointerException
- if the given MouseButton
is null
.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void click(Component c, Point where)
Component
.c
- the Component
to click on.where
- the position where to click.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.protected Settings settings()
@RunsInEDT public void requireSize(Component c, Dimension size)
Component
is equal to given one.c
- the target component.size
- the given size to match.AssertionError
- if the size of the Window
is not equal to the given size.@RunsInEDT public void requireVisible(Component c)
Component
is visible.c
- the target component.AssertionError
- if the Component
is not visible.@RunsInEDT public void requireNotVisible(Component c)
Component
is not visible.c
- the target component.AssertionError
- if the Component
is visible.@RunsInEDT public void requireFocused(Component c)
Component
has input focus.c
- the target component.AssertionError
- if the Component
does not have input focus.@RunsInEDT public void requireEnabled(Component c)
Component
is enabled.c
- the target component.AssertionError
- if the Component
is disabled.@RunsInEDT public void requireEnabled(Component c, Timeout timeout)
Component
is enabled.c
- the target component.timeout
- the time this fixture will wait for the component to be enabled.WaitTimedOutError
- if the Component
is never enabled.@RunsInEDT public void requireDisabled(Component c)
Component
is disabled.c
- the target component.AssertionError
- if the Component
is enabled.@RunsInEDT public void pressAndReleaseKeys(Component c, int... keyCodes)
Component
.c
- the target component.keyCodes
- one or more codes of the keys to press.NullPointerException
- if the given array of codes is null
.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.IllegalArgumentException
- if the given code is not a valid key code.KeyEvent
@RunsInEDT public void pressAndReleaseKey(Component c, KeyPressInfo keyPressInfo)
Component
. Modifiers is a
mask from the available InputEvent
masks.c
- the target component.keyPressInfo
- specifies the key and modifiers to press.NullPointerException
- if the given KeyPressInfo
is null
.IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.KeyEvent
,
InputEvent
@RunsInEDT public void pressAndReleaseKey(Component c, int keyCode, int[] modifiers)
Component
. Modifiers is a
mask from the available InputEvent
masks.c
- the target component.keyCode
- the code of the key to press.modifiers
- the given modifiers.IllegalArgumentException
- if the given code is not a valid key code. *IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.KeyEvent
,
InputEvent
@RunsInEDT public void pressKey(Component c, int keyCode)
Component
.c
- the target component.keyCode
- the code of the key to press.IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.KeyEvent
@RunsInEDT public void releaseKey(Component c, int keyCode)
Component
.c
- the target component.keyCode
- the code of the key to release.IllegalArgumentException
- if the given code is not a valid key code.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.KeyEvent
@RunsInEDT public void focusAndWaitForFocusGain(Component c)
c
- the component to give focus to.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public void focus(Component c)
Component
. Note that the component may not yet have focus when
this method returns.c
- the component to give focus to.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT protected final void drag(Component c, Point where)
c
- the target component.where
- the point where to start the drag action.@RunsInEDT protected final void drop(Component c, Point where)
This method is tuned for native drag/drop operations, so if you get odd behavior, you might try using a simple
and Robot.moveMouse(Component, int, int)
.Robot.releaseMouseButtons()
c
- the target component.where
- the point where the drag operation ends.ActionFailedException
- if there is no drag action in effect.protected final void dragOver(Component c, Point where)
c
- the target component.where
- the point to drag over.@RunsInCurrentThread protected final void performAccessibleActionOf(Component c)
AccessibleAction
in the given Component
's event queue.
Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.
c
- the given Component
.ActionFailedException
- if action
is null
or empty.@RunsInCurrentThread protected final boolean waitForShowing(Component c, long timeout)
Component
to be showing and ready. Returns
false
if the operation times out.
Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.
c
- the given Component
.timeout
- the time in milliseconds to wait for the Component
to be showing and ready.true
if the Component
is showing and ready, false
otherwise.@RunsInEDT public JPopupMenu invokePopupMenu(Component c)
Component
as the invoker of the pop-up menu.c
- the invoker of the JPopupMenu
.IllegalStateException
- if the given Component
is disabled.IllegalStateException
- if the given Component
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.@RunsInEDT public JPopupMenu invokePopupMenu(Component c, Point p)
Component
as the invoker of the pop-up
menu.c
- the invoker of the JPopupMenu
.p
- the given point where to show the pop-up menu.NullPointerException
- if the given point is null
.IllegalStateException
- if the given Component
is disabled.IllegalStateException
- if the given Component
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.@RunsInEDT protected static void assertIsEnabledAndShowing(Component c)
Component
is enabled and showing on the screen. This method is
executed in the event dispatch thread.c
- the Component
to check.IllegalStateException
- if the Component
is disabled.IllegalStateException
- if the Component
is not showing on the screen.@RunsInEDT public static org.fest.assertions.Description propertyName(Component c, String propertyName)
Component
by concatenating the value obtained
from Formatting.format(Component)
with the given property name.c
- the given Component
.propertyName
- the name of the property.Component
.ComponentFormatter
,
Formatting.format(Component)
@RunsInEDT protected final void moveMouseIgnoringAnyError(Component c, Point p)
Component
. This method will not throw any exceptions if the it was not possible to
move the mouse pointer.c
- the given Component
.p
- coordinates relative to the given Component
.@RunsInEDT protected final void moveMouseIgnoringAnyError(Component c, int x, int y)
Component
. This method will not throw any exceptions if the it was not possible to
move the mouse pointer.c
- the given Component
.x
- horizontal coordinate relative to the given Component
.y
- vertical coordinate relative to the given Component
.Copyright © 2007-2013 FEST (Fixtures for Easy Software Testing). All Rights Reserved.