@InternalApi public class ComponentDriver extends Object
Supports functional testing of AWT or Swing Components.
Note: This class is intended for internal use only. Please use the classes in the package
org.assertj.swing.fixture in your tests.
| Constructor and Description |
|---|
ComponentDriver(Robot robot)
Creates a new
ComponentDriver. |
| Modifier and Type | Method and Description |
|---|---|
Color |
backgroundOf(Component c)
Returns the background color of the given AWT or Swing
Component. |
protected static void |
checkInEdtEnabledAndShowing(Component c)
Verifies that the given AWT or Swing
Component is enabled and showing on the screen. |
void |
click(Component c)
Simulates a user clicking once the given AWT or Swing
Component using the left mouse button. |
void |
click(Component c,
MouseButton button)
Simulates a user clicking once the given AWT or Swing
Component 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 AWT or Swing
Component. |
void |
click(Component c,
MouseClickInfo mouseClickInfo)
Simulates a user clicking the given mouse button, the given times on the given AWT or Swing
Component. |
void |
click(Component c,
Point where)
Simulates a user clicking at the given position on the given AWT or Swing
Component. |
void |
doubleClick(Component c)
Simulates a user double-clicking the given AWT or Swing
Component. |
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 AWT or Swing
Component. |
void |
focusAndWaitForFocusGain(Component c)
Gives input focus to the given AWT or Swing
Component and waits until the Component has focus. |
Font |
fontOf(Component c)
Returns the font of the given AWT or Swing
Component. |
Color |
foregroundOf(Component c)
Returns the foreground color of the given AWT or Swing
Component. |
JPopupMenu |
invokePopupMenu(Component c)
Shows a pop-up menu using the given AWT or Swing
Component 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 AWT or Swing
Component 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 AWT or Swing
Component. |
protected void |
moveMouseIgnoringAnyError(Component c,
Point p)
Simulates a user moving the mouse pointer to the given coordinates relative to the given AWT or Swing
Component. |
protected void |
performAccessibleActionOf(Component c)
Performs the
AccessibleAction in the given AWT or Swing Component's event queue. |
void |
pressAndReleaseKey(Component c,
int keyCode,
int[] modifiers)
Simulates a user pressing and releasing the given key on the AWT or Swing
Component. |
void |
pressAndReleaseKey(Component c,
KeyPressInfo keyPressInfo)
Simulates a user pressing and releasing the given key on the AWT or Swing
Component. |
void |
pressAndReleaseKeys(Component c,
int... keyCodes)
Simulates a user pressing and releasing the given keys on the AWT or Swing
Component. |
void |
pressKey(Component c,
int keyCode)
Simulates a user pressing given key on the AWT or Swing
Component. |
static org.assertj.core.description.Description |
propertyName(Component c,
String propertyName)
Formats the name of a property of the given AWT or Swing
Component by concatenating the value obtained from
Formatting.format(Component) with the given property name. |
void |
releaseKey(Component c,
int keyCode)
Simulates a user releasing the given key on the AWT or Swing
Component. |
void |
requireDisabled(Component c)
Asserts that the AWT or Swing
Component is disabled. |
void |
requireEnabled(Component c)
Asserts that the AWT or Swing
Component is enabled. |
void |
requireEnabled(Component c,
Timeout timeout)
Asserts that the AWT or Swing
Component is enabled. |
void |
requireFocused(Component c)
Asserts that the AWT or Swing
Component has input focus. |
void |
requireNotVisible(Component c)
Asserts that the AWT or Swing
Component is not visible. |
void |
requireSize(Component c,
Dimension size)
Asserts that the size of the AWT or Swing
Component is equal to given one. |
void |
requireVisible(Component c)
Asserts that the AWT or Swing
Component is visible. |
void |
rightClick(Component c)
Simulates a user right-clicking the given AWT or Swing
Component. |
protected Settings |
settings() |
protected boolean |
waitForShowing(Component c,
long timeout)
Wait the given number of milliseconds for the AWT or Swing
Component to be showing and ready. |
protected final Robot robot
public ComponentDriver(@Nonnull Robot robot)
ComponentDriver.robot - the robot to use to simulate user input.@RunsInEDT public void click(@Nonnull 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(@Nonnull Component c, @Nonnull 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(@Nonnull Component c, @Nonnull 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(@Nonnull 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(@Nonnull 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(@Nonnull Component c, @Nonnull 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(@Nonnull Component c, @Nonnull 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.@RunsInEDT public void requireSize(@Nonnull Component c, @Nonnull Dimension size)
Component is equal to given one.c - the target Component.size - the given size to match.AssertionError - if the size of the Component is not equal to the given size.@RunsInEDT public void requireVisible(@Nonnull Component c)
Component is visible.c - the target Component.AssertionError - if the Component is not visible.@RunsInEDT public void requireNotVisible(@Nonnull Component c)
Component is not visible.c - the target Component.AssertionError - if the Component is visible.@RunsInEDT public void requireFocused(@Nonnull Component c)
Component has input focus.c - the target Component.AssertionError - if the Component does not have input focus.@RunsInEDT public void requireEnabled(@Nonnull Component c)
Component is enabled.c - the target Component.AssertionError - if the Component is disabled.@RunsInEDT public void requireEnabled(@Nonnull Component c, @Nonnull 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(@Nonnull Component c)
Component is disabled.c - the target Component.AssertionError - if the Component is enabled.@RunsInEDT public void pressAndReleaseKeys(@Nonnull Component c, @Nonnull 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(@Nonnull Component c, @Nonnull KeyPressInfo keyPressInfo)
Component. Modifiers is a mask
from the available AWT 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(@Nonnull Component c, int keyCode, @Nonnull int[] modifiers)
Component. Modifiers is a mask
from the available AWT 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(@Nonnull 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(@Nonnull 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(@Nonnull Component c)
Component and waits until the Component has focus.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(@Nonnull 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(@Nonnull Component c, @Nonnull Point where)
c - the target Component.where - the point where to start the drag action.@RunsInEDT protected final void drop(@Nonnull Component c, @Nonnull Point where)
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
Robot.moveMouse(Component, int, int) and 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(@Nonnull Component c, @Nonnull Point where)
c - the target Component.where - the point to drag over.@RunsInCurrentThread protected final void performAccessibleActionOf(@Nonnull Component c)
Performs the AccessibleAction in the given AWT or Swing Component's event queue.
Note: This method is accessed in the current executing thread. Such thread may or may not be the event dispatch thread (EDT.) Client code must call this method from the EDT.
c - the given Component.ActionFailedException - if something goes wrong.@RunsInCurrentThread protected final boolean waitForShowing(@Nonnull Component c, long timeout)
Wait the given number of milliseconds for the AWT or Swing Component to be showing and ready. Returns
false if the operation times out.
Note: This method is accessed in the current executing thread. Such thread may or may not be the event dispatch thread (EDT.) Client code must call 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 @Nonnull public JPopupMenu invokePopupMenu(@Nonnull 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 @Nonnull public JPopupMenu invokePopupMenu(@Nonnull Component c, @Nonnull 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 checkInEdtEnabledAndShowing(@Nonnull Component c)
Component is enabled and showing on the screen. This method is
executed in the event dispatch thread (EDT.)c - the Component to check.IllegalStateException - if the Component is disabled.IllegalStateException - if the Component is not showing on the screen.@RunsInEDT @Nonnull public static org.assertj.core.description.Description propertyName(@Nonnull Component c, @Nonnull 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(@Nonnull Component c, @Nonnull 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(@Nonnull 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.@RunsInEDT @Nonnull public Font fontOf(@Nonnull Component c)
Component.c - the given Component.Component.@RunsInEDT @Nonnull public Color backgroundOf(@Nonnull Component c)
Component.c - the given Component.Component.@RunsInEDT @Nonnull public Color foregroundOf(@Nonnull Component c)
Component.c - the given Component.Component.Copyright © 2014 AssertJ. All rights reserved.