|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object abbot.tester.Robot
public class Robot
Provide a higher level of abstraction for user input (A Better Robot).
The Robot's operation may be affected by the following properties:
abbot.robot.auto_delay
abbot.robot.mode
abbot.robot.event_post_delay
abbot.robot.default_delay
abbot.robot.popup_delay
abbot.robot.component_delay
The Robot class provides a generic solution for dealing with asynchronous
updates to the UI with the wait(Condition,long, int)
method.
This allows the testing thread to pause until a given component of data value
in a component is ready.
NOTE: Only use event queue synchronization (e.g.
invokeAndWait(Runnable)
or waitForIdle()
when a
subsequent robot-level action is being applied to the results of a prior
action (e.g. focus, deiconify, menu selection). Otherwise, don't
introduce a mandatory delay (e.g. use invokeLater(Runnable)
).
NOTE: If a robot action isn't reproduced properly, you may need to introduce either additional events or extra delay. Adding enforced delay for a given platform is usually preferable to generating additional events, so always try that first, but be sure to restrict it to the platform in question.
NOTE: Robot actions should never be invoked on the event dispatch thread.
Field Summary | |
---|---|
static int |
componentDelay
Delay before failing to find a component that should be visible. |
static int |
defaultDelay
Base delay setting. |
static int |
EM_AWT
Post events to the AWT event queue. |
static int |
EM_ROBOT
Use java.awt.Robot to generate events. |
protected static long |
IDLE_TIMEOUT
|
static String |
MOUSELESS_MODIFIER
|
static int |
MOUSELESS_MODIFIER_MASK
|
protected static int |
popupDelay
Delay before failing to find a popup menu that should appear. |
Fields inherited from interface abbot.tester.AWTConstants |
---|
BUTTON_MASK, COPY_MASK, DRAG_THRESHOLD, LINK_MASK, MENU_SHORTCUT_KEYCODE, MENU_SHORTCUT_MASK, MENU_SHORTCUT_MODIFIER, MENU_SHORTCUT_STRING, MOVE_MASK, MULTI_CLICK_INTERVAL, POPUP_MASK, POPUP_MODIFIER, POPUP_ON_PRESS, TERTIARY_MASK, TERTIARY_MODIFIER |
Constructor Summary | |
---|---|
Robot()
Default constructor. |
Method Summary | |
---|---|
void |
activate(Window win)
Activate the given window. |
static boolean |
canMoveWindows()
Returns whether it is possible to move windows that are not an instance of Frame or Dialog. |
static boolean |
canResizeWindows()
Returns whether it is possible to resize windows that are not an instance of Frame or Dialog. |
BufferedImage |
capture(Component comp)
Capture the contents of the given component, sans any border or insets. |
BufferedImage |
capture(Component comp,
boolean ignoreBorder)
Capture the contents of the given component, optionally including the border and/or insets. |
BufferedImage |
capture(Rectangle bounds)
Capture the contents of the given rectangle. |
void |
click(Component comp)
Click in the center of the given component. |
void |
click(Component comp,
int mask)
Click in the center of the given component, specifying which button. |
void |
click(Component comp,
int x,
int y)
Click in the component at the given location. |
void |
click(Component comp,
int x,
int y,
int mask)
Click in the component at the given location with the given button. |
void |
click(Component comp,
int x,
int y,
int mask,
int count)
Click in the given part of the component. |
void |
close(Window w)
Invoke the window close operation. |
void |
deiconify(Frame frame)
|
void |
delay(int ms)
Sleep the given duration of ms. |
protected static String |
descriptiveClassName(Class cls)
|
void |
drag(Component src,
int sx,
int sy)
Begin a drag operation using button 1. |
void |
drag(Component src,
int sx,
int sy,
int buttons)
Begin a drag operation using the given button mask. |
void |
dragOver(Component dst,
int x,
int y)
Move the mouse appropriately to get from the source to the destination. |
void |
drop(Component target,
int x,
int y)
End a drag operation, releasing the mouse button over the given target location. |
Component |
findFocusOwner()
Return the Component which currently owns the focus. |
protected void |
fireAccessibleAction(Component context,
AccessibleAction action,
String name)
|
void |
focus(Component comp)
Move keyboard focus to the given component. |
void |
focus(Component comp,
boolean wait)
Move keyboard focus to the given component. |
static int |
getAutoDelay()
|
static String |
getBorderTitle(Component c)
|
static Class |
getCanonicalClass(Class refClass)
|
protected Point |
getCloseLocation(Container c)
|
static String |
getDescriptiveName(Component c)
Return a descriptive name for the given component for use in UI text (may be localized if appropriate and need not be re-usable across locales. |
static String |
getEventID(AWTEvent event)
Return the symbolic name of the given event's ID. |
static int |
getEventID(Class cls,
String id)
Return the numeric event ID corresponding to the given string. |
static int |
getEventMode()
Returns the current event-generation mode. |
static String |
getEventModeDescription()
|
static int |
getEventPostDelay()
|
protected EventQueue |
getEventQueue(Component c)
Usually only needed when dealing with Applets. |
protected Point |
getIconifyLocation(Container c)
Identify the coordinates of the iconify button where we can, returning (0, 0) if we can't. |
static String |
getIconName(Component c)
|
static int |
getIndex(Container parent,
Component comp)
Returns the index of the given component within the given container. |
static String |
getLabel(Component c)
|
protected Point |
getMaximizeLocation(Container c)
Identify the coordinates of the maximize button where possible, returning null if not. |
protected Point |
getMoveLocation(Container c)
Return where the mouse usually grabs to move a window. |
static String |
getName(Component c)
|
static int |
getPreferredRobotAutoDelay()
Returns the appropriate auto delay for robot-generated events. |
protected Point |
getResizeLocation(Container c)
Return where the mouse usually grabs to resize a window. |
static Robot |
getRobot()
Returns a functioning instance of java.awt.Robot. |
static InputState |
getState()
Return a singleton InputState object. |
static String |
getText(Component c)
|
static String |
getTitle(Component c)
|
void |
iconify(Frame frame)
Iconify the given Frame. |
void |
invokeAction(Component c,
Runnable action)
Deprecated. Method renamed to invokeLater(Component, Runnable) |
void |
invokeAction(Runnable action)
Deprecated. Method renamed to invokeLater(Runnable) |
void |
invokeAndWait(Component c,
Runnable action)
Post a runnable on the given component's event queue and wait for it to finish. |
void |
invokeAndWait(Runnable action)
Run the given action on the event dispatch thread, but don't return until it's been run. |
void |
invokeLater(Component context,
Runnable action)
Post a runnable on the given component's event queue. |
void |
invokeLater(Runnable action)
Run the given action on the event dispatch thread. |
protected boolean |
isReadyForInput(Component c)
Is the given component ready for robot input? |
protected void |
jitter(Component comp,
int x,
int y)
|
protected void |
jitter(int x,
int y)
|
void |
key(int keycode)
Type the given keycode with no modifiers. |
void |
key(int keycode,
int modifiers)
Type the given keycode with the given modifiers. |
void |
keyPress(int keycode)
|
void |
keyRelease(int keycode)
Send a key release event. |
void |
keyString(String str)
Type the given string. |
void |
keyStroke(char ch)
Type the given character. |
void |
maximize(Frame frame)
Make the window full size. |
void |
mouseMove(Component comp)
Move the pointer to the center of the given component. |
void |
mouseMove(Component comp,
int x,
int y)
Move the pointer to the given coordinates relative to the given component. |
void |
mousePress(Component comp)
|
void |
mousePress(Component comp,
int mask)
|
void |
mousePress(Component comp,
int x,
int y)
|
void |
mousePress(Component comp,
int x,
int y,
int mask)
Mouse down in the given part of the component. |
void |
mousePress(int buttons)
Send a button press event. |
void |
mouseRelease()
Send a button release event for button 1. |
void |
mouseRelease(int buttons)
Send a button release event. |
void |
move(Container comp,
int newx,
int newy)
Move the given Frame/Dialog to the requested location. |
void |
moveBy(Container comp,
int dx,
int dy)
Move the given Window by the given amount. |
void |
normalize(Frame frame)
|
protected void |
postEvent(Component comp,
AWTEvent ev)
Post the given event to the corresponding event queue for the given component. |
protected boolean |
postInvocationEvent(EventQueue eq,
Toolkit toolkit,
long timeout)
|
protected boolean |
queueBlocked()
Check for a blocked event queue (symptomatic of an active w32 AWT popup menu). |
void |
reset()
|
void |
resize(Container comp,
int width,
int height)
Resize the given Frame/Dialog to the given size. |
void |
resizeBy(Container comp,
int dx,
int dy)
Resize the given Frame/Dialog by the given amounts. |
Color |
sample(Component c,
ComponentLocation loc)
Sample the color at the given location on the component. |
Color |
sample(Component c,
int x,
int y)
Sample the color at the given point on the component. |
Color |
sample(int x,
int y)
Sample the color at the given point on the screen. |
void |
selectAWTMenuItem(Frame frame,
String path)
Select the given menu item from the given Frame. |
void |
selectAWTMenuItem(MenuComponent item)
Select an AWT menu item. |
void |
selectAWTMenuItemByLabel(Frame frame,
String path)
Deprecated. Renamed to selectAWTMenuItem(Frame,String) . |
void |
selectAWTPopupMenuItem(Component invoker,
String path)
Select the given menu item from a PopupMenu on the given Component. |
void |
selectAWTPopupMenuItem(MenuComponent item)
Select an AWT popup menu item. |
void |
selectAWTPopupMenuItemByLabel(Component invoker,
String path)
Deprecated. Renamed to selectAWTPopupMenuItem(Component,String) . |
void |
selectMenuItem(Component item)
Find and select the given menu item. |
void |
selectMenuItem(Component sameWindow,
String path)
Find and select the given menu item, by path. |
void |
selectPopupMenuItem(Component invoker,
ComponentLocation loc,
String path)
|
void |
sendEvent(AWTEvent event)
Send the given event as appropriate to the event-generation mode. |
static void |
setAutoDelay(int ms)
Allow this to be adjusted, mostly for testing. |
static void |
setEventMode(int mode)
Set the event-generation mode. |
static void |
setEventPostDelay(int delay)
|
void |
setModifiers(int modifiers,
boolean press)
Press or release the appropriate modifiers corresponding to the given mask. |
Component |
showPopupMenu(Component invoker)
Attempt to display a popup menu at center of the component. |
Component |
showPopupMenu(Component invoker,
int x,
int y)
Attempt to display a popup menu at the given coordinates. |
static String |
simpleClassName(Class cls)
Strip the package from the class name. |
void |
sleep()
Sleep for a little bit, measured in UI time. |
static String |
toHierarchyPath(Component c)
Provides the hierarchic path of the given component by component class, e.g. |
static String |
toString(AWTEvent event)
Provide a more concise representation of the event than the default AWTEvent.toString(). |
static String |
toString(Component comp)
Provides a more concise representation of the component than the default Component.toString(). |
static String |
toString(Object obj)
Provide a string representation of the given component (Component or MenuComponent. |
protected boolean |
userMovable(Component comp)
Return whether it is possible for the user to move the given component. |
protected boolean |
userResizable(Component comp)
Return whether it is possible for the user to resize the given component. |
protected static boolean |
useScreenMenuBar()
OS X using screenMenuBar actually uses an AWT menu as the live component. |
void |
wait(Condition condition)
Wait for the given Condition to return true. |
void |
wait(Condition condition,
long timeout)
Wait for the given Condition to return true, waiting for timeout ms. |
void |
wait(Condition condition,
long timeout,
int interval)
Wait for the given Condition to return true, waiting for timeout ms, polling at the given interval. |
void |
waitForIdle()
Wait for an idle AWT event queue. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int EM_ROBOT
public static int EM_AWT
public static final int MOUSELESS_MODIFIER_MASK
public static final String MOUSELESS_MODIFIER
public static int defaultDelay
protected static long IDLE_TIMEOUT
protected static int popupDelay
public static int componentDelay
Constructor Detail |
---|
public Robot()
Method Detail |
---|
protected static final boolean useScreenMenuBar()
public static int getAutoDelay()
public static Robot getRobot()
public static InputState getState()
public static int getEventMode()
public static String getEventModeDescription()
public static void setEventMode(int mode)
IllegalStateException
- if the requested mode is EM_ROBOT and
java.awt.Robot is unavailable in the current environment.public static int getEventPostDelay()
public static void setEventPostDelay(int delay)
public static void setAutoDelay(int ms)
public void mousePress(int buttons)
public void mouseRelease()
public void mouseRelease(int buttons)
public void focus(Component comp)
public void focus(Component comp, boolean wait)
protected EventQueue getEventQueue(Component c)
public void invokeLater(Component context, Runnable action)
public void invokeAndWait(Component c, Runnable action)
public void invokeAction(Runnable action)
invokeLater(Runnable)
action
- public void invokeAction(Component c, Runnable action)
invokeLater(Component, Runnable)
c
- action
- public void invokeLater(Runnable action)
public void invokeAndWait(Runnable action)
public void keyPress(int keycode)
public void keyRelease(int keycode)
public void sleep()
public void delay(int ms)
protected boolean queueBlocked()
protected boolean postInvocationEvent(EventQueue eq, Toolkit toolkit, long timeout)
public void waitForIdle()
java.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.
public Color sample(int x, int y)
public Color sample(Component c, int x, int y)
public Color sample(Component c, ComponentLocation loc)
public BufferedImage capture(Rectangle bounds)
public BufferedImage capture(Component comp)
public BufferedImage capture(Component comp, boolean ignoreBorder)
protected void jitter(Component comp, int x, int y)
protected void jitter(int x, int y)
public void mouseMove(Component comp)
public void mouseMove(Component comp, int x, int y)
public void dragOver(Component dst, int x, int y)
public void drag(Component src, int sx, int sy)
This method is tuned for native drag/drop operations, so if you get
odd behavior, you might try using a simple
mousePress(Component,int,int)
instead.
public void drag(Component src, int sx, int sy, int buttons)
This method is tuned for native drag/drop operations, so if you get
odd behavior, you might try using a simple
mousePress(Component,int,int,int)
instead.
public void drop(Component target, int x, int y)
This method is tuned for native drag/drop operations, so if you get
odd behavior, you might try using a simple
mouseMove(Component,int,int)
, mouseRelease()
instead.
public void key(int keycode)
public void setModifiers(int modifiers, boolean press)
public void key(int keycode, int modifiers)
public void keyStroke(char ch)
public void keyString(String str)
public void mousePress(Component comp)
public void mousePress(Component comp, int mask)
public void mousePress(Component comp, int x, int y)
public void mousePress(Component comp, int x, int y, int mask)
public final void click(Component comp)
public final void click(Component comp, int mask)
public final void click(Component comp, int x, int y)
public final void click(Component comp, int x, int y, int mask)
public void click(Component comp, int x, int y, int mask, int count)
public void selectAWTMenuItemByLabel(Frame frame, String path)
selectAWTMenuItem(Frame,String)
.
public void selectAWTMenuItem(Frame frame, String path)
public void selectAWTPopupMenuItemByLabel(Component invoker, String path)
selectAWTPopupMenuItem(Component,String)
.
public void selectAWTPopupMenuItem(Component invoker, String path)
protected void fireAccessibleAction(Component context, AccessibleAction action, String name)
public void selectAWTMenuItem(MenuComponent item)
public void selectAWTPopupMenuItem(MenuComponent item)
protected boolean isReadyForInput(Component c)
public void selectMenuItem(Component sameWindow, String path)
public void selectMenuItem(Component item)
public void selectPopupMenuItem(Component invoker, ComponentLocation loc, String path)
public Component showPopupMenu(Component invoker)
public Component showPopupMenu(Component invoker, int x, int y)
public void activate(Window win)
protected Point getCloseLocation(Container c)
public void close(Window w)
protected Point getMoveLocation(Container c)
public void move(Container comp, int newx, int newy)
public void moveBy(Container comp, int dx, int dy)
protected Point getResizeLocation(Container c)
protected boolean userMovable(Component comp)
protected boolean userResizable(Component comp)
public void resize(Container comp, int width, int height)
public void resizeBy(Container comp, int dx, int dy)
protected Point getIconifyLocation(Container c)
protected Point getMaximizeLocation(Container c)
public void iconify(Frame frame)
public void deiconify(Frame frame)
public void normalize(Frame frame)
public void maximize(Frame frame)
public void sendEvent(AWTEvent event)
public static String getEventID(AWTEvent event)
public static Class getCanonicalClass(Class refClass)
public static String toString(Component comp)
public static String toString(Object obj)
protected static String descriptiveClassName(Class cls)
public static String toHierarchyPath(Component c)
public static String toString(AWTEvent event)
public static int getEventID(Class cls, String id)
public static String simpleClassName(Class cls)
protected void postEvent(Component comp, AWTEvent ev)
public void wait(Condition condition)
WaitTimedOutError
- if the default timeout (30s) is exceeded.Robot.wait For a description of the use of this function to support lazy loading in class files
public void wait(Condition condition, long timeout)
WaitTimedOutError
- if the timeout is exceeded.Robot.wait For a description of the use of this function to support lazy loading in class files
public void wait(Condition condition, long timeout, int interval)
Take for example the simple case of trying to select an item in a list. If the model for this list is populate asynchronously then you may need to poll the list for a given amount of time until the item appears. This is very common in an application that contains many long running tasks.
A general solution to the problem can be seen in this pseudo code:
wait(new Condition() { public boolean test() { return whether the ui element is avaliable } }); performAction(ui element);
If you are writing a tester method then it is a good idea to use a standard
timeout such as componentDelay
to ensure they are consistently
handled accross different testers.
WaitTimedOutError
- if the timeout is exceeded.public void reset()
public Component findFocusOwner()
public static String getDescriptiveName(Component c)
public static String getName(Component c)
public static int getIndex(Container parent, Component comp)
public static String getText(Component c)
public static String getLabel(Component c)
public static String getIconName(Component c)
public static String getBorderTitle(Component c)
public static String getTitle(Component c)
public static boolean canResizeWindows()
public static boolean canMoveWindows()
public static int getPreferredRobotAutoDelay()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |