|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--abbot.tester.Robot | +--abbot.tester.ComponentTester
Provide basic actions and assertions for anything of class Component.
Derive from this class to implement actions and assertions specific to
a given component class. Actions are generally user-driven actions such
as menu selection, table selection, popup menus, etc. Assertions are
either independent of any component (and should be implemented in this
class), or take a component as the first argument, and perform some check
on that component. Testers for any classes found in the JRE should be in
the abbot.tester
package. Extensions (testers for any
Component subclasses not found in the JRE) must be in the
abbot.tester.extensions
package and be named the name of
the Component subclass followed by "Tester". For example, the
javax.swing.JButton tester class is
abbot.tester.JButtonTester
, and a tester for org.me.MyButton
would be abbot.tester.extensions.MyButton
.
All actions should have the following signature:
public void actionWhat(Component c, ...);
It is essential that the argument is of type Component; if you use a more
derived class then the actual invocation becomes ambiguous since method
parsing doesn't attempt to determine which identically-named method is the
most-derived.
NOTE: All actions should ensure that the actions they trigger are finished
or will be finished before subsequent operations before returning.
All assertions should have one of the following signatures:
public boolean assertWhat(...);
public boolean assertWhat(Component c, ...);
FIXME need an explanation about how this assert (which returns boolean)
is different from the Assert, which will throw
Property checks may also be implemented in cases where the component
"property" might not be readily available or easily comparable, e.g.
see JPopupMenuTester.getMenuLabels()
.
public Object getProperty(Component c);
public boolean isProperty(Component c);
Be careful not to name any support methods with the property signature, since these are scanned dynamically to populate the editor's action menus.
There are two sets of event-generating methods. The internal, protected methods inherited from abbot.tester.Robot are for normal programmatic use within derived Tester classes. No event queue synchronization should be performed except when modifying a component.
The public actionX functions are meant to be invoked from a script or directly from a hand-written test. These actions are distinguished by name and number of arguments, but not by argument type. Therefore you should be very careful when overloading actionX method names. The actionX methods will be synchronized with the event dispatch thread when invoked, so you should only do synchronization with waitForIdle when performing several consecutively dependent steps.
Add-on tester classes should set the following system properties so that
the actions provided by their tester can be properly displayed in the
script editor. For an action "actionWiggle" provided by class
abbot.tester.extensions.ExtendedTester, the following properties
should be defined:
actionWiggle.menu
short name for Insert menu
actionWiggle.desc
short description
actionWiggle.icon
icon for the action
ExtendedTester.actionWiggle.args
javadoc-style description of method
Fields inherited from class abbot.tester.Robot |
BUTTON_MASK, componentDelay, defaultDelay, dragMask, EM_AWT, EM_PROG, EM_ROBOT, MENU_SHORTCUT_KEYCODE, MENU_SHORTCUT_MASK, MENU_SHORTCUT_MODIFIER, MULTI_CLICK_INTERVAL, POPUP_MASK, POPUP_MODIFIER, POPUP_ON_PRESS, popupDelay, state, TERTIARY_MASK, TERTIARY_MODIFIER |
Constructor Summary | |
ComponentTester()
|
Method Summary | |
void |
actionClick(Component comp)
Click on the center of the component. |
void |
actionClick(Component comp,
int x,
int y)
Click on the component at the given location. |
void |
actionClick(Component comp,
int x,
int y,
String buttons)
Click on the component at the given location. |
void |
actionClick(Component comp,
int x,
int y,
String buttons,
int count)
Click on the component at the given location. |
void |
actionDelay(int ms)
Delay the given number of ms. |
void |
actionDrag(Component dragSource,
int sx,
int sy)
Perform a drag action. |
void |
actionDrag(Component dragSource,
int sx,
int sy,
String modifiers)
Perform a drag action. |
void |
actionDrop(Component dropTarget,
int x,
int y)
Perform a basic drop action (implicitly causing a preceding mouse drag). |
void |
actionFocus(Component comp)
Set the focus on to the given component. |
void |
actionKeyPress(String kc)
Used only for modifier keys. |
void |
actionKeyRelease(String kc)
Usually used only for modifier keys. |
void |
actionKeyString(String string)
Send events required to generate the given string. |
void |
actionKeyStroke(String kc)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionKeyStroke(String kc,
String mods)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionSelectAWTMenuItemByLabel(Frame frame,
String label)
|
void |
actionSelectAWTPopupMenuItemByLabel(Component invoker,
String label)
|
void |
actionSelectMenuItem(Component item)
Select the given menu item. |
void |
actionSelectPopupMenuItem(Component invoker,
int x,
int y,
String itemName)
Pop up a menu at the given location on the given component; Select the given item. |
void |
actionSelectPopupMenuItem(Component invoker,
String itemName)
Pop up a menu at the given location on the given component; Select the given item. |
void |
actionShowPopupMenu(Component invoker)
Pop up a menu in the center of the given component. |
void |
actionShowPopupMenu(Component invoker,
int x,
int y)
Pop up a menu at the given location on the given component. |
void |
actionWaitForIdle()
Wait for an idle AWT event queue. |
boolean |
assertComponentShowing(ComponentReference ref)
Return whether the Component represented by the given ComponentReference is available. |
boolean |
assertFrameShowing(String identifier)
Returns whether a Window corresponding to the given String is showing. |
boolean |
assertImage(Component comp,
File fileImage,
boolean ignoreBorder)
Return whether the component's contents matches the given image. |
protected String |
deriveAccessibleTag(AccessibleContext context)
Derive a tag from the given accessible context if possible, or return null. |
String |
deriveTag(Component comp)
Provide a String that is fairly distinct for the given component. |
Method[] |
getActions()
Return a list of all actions defined by this class that don't depend on a component argument. |
Method[] |
getAssertMethods()
Return a list of all assertions defined by this class that don't depend on a component argument. |
Method[] |
getComponentActions()
Return a list of all actions defined by this class that require a component argument. |
Method[] |
getComponentAssertMethods()
Return a list of all assertions defined by this class that require a component argument. |
protected ComponentFinder |
getFinder()
|
Method[] |
getPropertyMethods()
Return an array of all property check methods defined by this class. |
static String |
getTag(Component comp)
Return a reasonable identifier for the given component. |
Class |
getTestedClass(Class cls)
Return the Component class that corresponds to this ComponentTester class. |
static ComponentTester |
getTester(Class componentClass)
Find the corresponding Tester object for the given component class, chaining up the inheritance tree if no specific tester is found for that class. |
static ComponentTester |
getTester(Component comp)
Return the appropriate Tester for the given object. |
boolean |
isExtension()
Return whether this tester is an extension. |
static void |
setTester(Class forClass,
ComponentTester tester)
Establish the given ComponentTester as the one to use for the given class. |
static String |
stripHTML(String str)
Quick and dirty strip raw text from html, for getting the basic text from html-formatted labels and buttons. |
protected void |
waitAction(String desc,
Condition cond)
Wait for the given condition, throwing an ActionFailedException if it times out. |
void |
waitForComponentShowing(ComponentReference ref)
Wait for the Component represented by the given ComponentReference to become available. |
void |
waitForFrameShowing(String identifier)
Convenience wait for a window to be displayed. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ComponentTester()
Method Detail |
public static void setTester(Class forClass, ComponentTester tester)
public static ComponentTester getTester(Component comp)
public static ComponentTester getTester(Class componentClass)
The abbot tester package is searched first, followed by the tester extensions package.
public final boolean isExtension()
protected ComponentFinder getFinder()
protected String deriveAccessibleTag(AccessibleContext context)
public static String getTag(Component comp)
public String deriveTag(Component comp)
Don't use component names as tags.
public void actionWaitForIdle()
public void actionDelay(int ms)
public void actionSelectAWTMenuItemByLabel(Frame frame, String label)
public void actionSelectAWTPopupMenuItemByLabel(Component invoker, String label)
public void actionSelectMenuItem(Component item)
public void actionSelectPopupMenuItem(Component invoker, String itemName)
public void actionSelectPopupMenuItem(Component invoker, int x, int y, String itemName)
public void actionShowPopupMenu(Component invoker)
public void actionShowPopupMenu(Component invoker, int x, int y)
public void actionClick(Component comp)
public void actionClick(Component comp, int x, int y)
public void actionClick(Component comp, int x, int y, String buttons)
public void actionClick(Component comp, int x, int y, String buttons, int count)
public void actionKeyPress(String kc)
public void actionKeyRelease(String kc)
public void actionKeyStroke(String kc)
public void actionKeyStroke(String kc, String mods)
NOTE: on OSX, the wait for idle is not sufficient to process the entire keystroke.
public void actionKeyString(String string)
public void actionFocus(Component comp)
public void actionDrag(Component dragSource, int sx, int sy)
public void actionDrag(Component dragSource, int sx, int sy, String modifiers)
public void actionDrop(Component dropTarget, int x, int y)
public boolean assertImage(Component comp, File fileImage, boolean ignoreBorder)
public boolean assertFrameShowing(String identifier)
public void waitForFrameShowing(String identifier)
The property abbot.robot.component_delay affects the default timeout.
public boolean assertComponentShowing(ComponentReference ref)
public void waitForComponentShowing(ComponentReference ref)
public Method[] getActions()
public Method[] getComponentActions()
public Method[] getPropertyMethods()
public Method[] getAssertMethods()
public Method[] getComponentAssertMethods()
public static String stripHTML(String str)
protected void waitAction(String desc, Condition cond) throws ActionFailedException
public Class getTestedClass(Class cls)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |