|
|||||||||
| Home >> All >> abbot >> [ tester overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
abbot.tester
Class ComponentTester

java.lang.Objectabbot.tester.Robot
abbot.tester.ComponentTester
- All Implemented Interfaces:
- abbot.editor.i18n.Resources, abbot.i18n.Resources
- Direct Known Subclasses:
- ContainerTester
- public class ComponentTester
- extends Robot
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, ...);
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 can use the
abbot.editor.ScriptEditor.setDocumentationProperties
method to document newly added actions and assertions. For example, in the
static initializer of your add-on tester class, do:
static {
// Store properties for all exported actions
final String[][] actions = {
// key, menu label, description, args description
"actionMine", "Do Mine", "Executes the 'Mine' function", "",
"actionYours", "Do Yours", "Executes the 'Yours' function", "",
};
for (int i=0;i < actions.length;i++) {
ScriptEditor.setDocumentationProperties(actions[i]);
}
}
| Nested Class Summary |
| Nested classes inherited from class abbot.editor.i18n.Resources |
abbot.editor.i18n.Resources.ResourceLoader |
| Field Summary | |
private java.lang.reflect.Method[] |
cachedActions
|
private java.lang.reflect.Method[] |
cachedAssertions
|
private java.lang.reflect.Method[] |
cachedComponentActions
|
private java.lang.reflect.Method[] |
cachedComponentAssertions
|
private java.lang.reflect.Method[] |
cachedMethods
|
private java.lang.reflect.Method[] |
cachedPropertyChecks
|
private static java.lang.String[] |
tagMethods
|
private java.lang.Class |
testedClass
What class does this tester test? |
private static java.util.HashMap |
testers
Maps class names to their corresponding Tester object. |
| Fields inherited from class abbot.tester.Robot |
BUTTON_MASK, EM_AWT, EM_PROG, EM_ROBOT, eventMode, eventWaitDelay, MENU_SHORTCUT_KEYCODE, MENU_SHORTCUT_MASK, MENU_SHORTCUT_MODIFIER, mouseReleaseDelay, needJitter, POPUP_MASK, POPUP_MODIFIER, POPUP_ON_PRESS, TERTIARY_MASK, TERTIARY_MODIFIER |
| Fields inherited from interface abbot.editor.i18n.Resources |
bundle, STRINGS_BUNDLE |
| Constructor Summary | |
ComponentTester()
|
|
| Method Summary | |
void |
actionClick(java.awt.Component comp)
Click on the center of the component. |
void |
actionClick(java.awt.Component comp,
int x,
int y)
Click on the component at the given location. |
void |
actionClick(java.awt.Component comp,
int x,
int y,
java.lang.String buttons)
Click on the component at the given location. |
void |
actionClick(java.awt.Component comp,
int x,
int y,
java.lang.String buttons,
int count)
Click on the component at the given location. |
void |
actionDelay(int ms)
Delay the given number of ms. |
void |
actionDrag(java.awt.Component dragSource,
int sx,
int sy)
Perform a drag action. |
void |
actionDrop(java.awt.Component dropTarget,
int x,
int y)
Perform a basic drop action (implicitly causing a preceding mouse drag). |
void |
actionFocus(java.awt.Component comp)
Set the focus on to the given component. |
void |
actionKeyPress(java.lang.String kc)
Used only for modifier keys. |
void |
actionKeyRelease(java.lang.String kc)
Usually used only for modifier keys. |
void |
actionKeyString(java.lang.String string)
Send events required to generate the given string. |
void |
actionKeyStroke(java.lang.String kc)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionKeyStroke(java.lang.String kc,
java.lang.String mods)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionSelectAWTMenuItemByLabel(java.awt.Frame frame,
java.lang.String label)
|
void |
actionSelectMenuItem(java.awt.Component item)
Select the given menu item. |
void |
actionSelectPopupMenuItem(java.awt.Component invoker,
int x,
int y,
java.lang.String itemName)
Pop up a menu at the given location on the given component; Select the given item. |
void |
actionSelectPopupMenuItem(java.awt.Component invoker,
java.lang.String itemName)
Pop up a menu at the given location on the given component; Select the given item. |
void |
actionShowPopupMenu(java.awt.Component invoker)
Pop up a menu in the center of the given component. |
void |
actionShowPopupMenu(java.awt.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(abbot.script.ComponentReference ref)
|
boolean |
assertFrameShowing(java.lang.String title)
Returns whether frame/dialog with the given title is showing. |
boolean |
assertImage(java.awt.Component comp,
java.io.File fileImage,
boolean ignoreBorder)
Return whether the component's contents matches the given image. |
protected java.lang.String |
deriveAccessibleTag(javax.accessibility.AccessibleContext context)
Derive a tag from the given accessible context if possible, or return null. |
java.lang.String |
deriveTag(java.awt.Component comp)
Provide a String that is fairly distinct for the given component. |
private static ComponentTester |
findTester(java.lang.String testerName,
java.lang.Class componentClass)
Look up the given class with a specific class loader. |
java.lang.reflect.Method[] |
getActions()
Return a list of all actions defined by this class that don't depend on a component argument. |
java.lang.reflect.Method[] |
getAssertions()
Return a list of all assertions defined by this class that don't depend on a component argument. |
java.lang.reflect.Method[] |
getComponentActions()
Return a list of all actions defined by this class that require a component argument. |
java.lang.reflect.Method[] |
getComponentAssertions()
Return a list of all assertions defined by this class that require a component argument. |
protected abbot.ComponentFinder |
getFinder()
|
private java.lang.reflect.Method[] |
getMethods(java.lang.String prefix,
java.lang.Class returnType,
boolean onComponent)
Look up methods with the given prefix. |
java.lang.reflect.Method[] |
getPropertyChecks()
Return a list of all property checks defined by this class. |
static java.lang.String |
getTag(java.awt.Component comp)
Return a reasonable identifier for the given component. |
java.lang.Class |
getTestedClass()
Return the class tested by the given tester. |
static ComponentTester |
getTester(java.lang.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(java.awt.Component comp)
Return the appropriate Tester for the given object. |
boolean |
isExtension()
Return whether this tester is an extension. |
private static java.lang.Class |
resolveClass(java.lang.String testerName,
java.lang.Class componentClass)
Look up the given class, using special class loading rules to maintain framework consistency. |
static void |
setTester(java.lang.Class forClass,
ComponentTester tester)
Establish the given ComponentTester as the one to use for the given class. |
static java.lang.String |
stripHTML(java.lang.String str)
Quick and dirty strip raw text from html, for getting the basic text from html-formatted labels and buttons. |
protected void |
waitAction(java.lang.String desc,
abbot.Condition cond)
Wait for the given condition, throwing an ActionFailedException if it times out. |
static void |
waitForComponentShowing(abbot.script.ComponentReference ref)
|
static void |
waitForFrameShowing(java.lang.String title)
Convenience wait for a window to be displayed. |
| Methods inherited from class abbot.tester.Robot |
activate, bugCheck, capture, capture, capture, click, click, click, click, click, close, deiconify, delay, findFocusOwner, focus, getAutoDelay, getCanonicalClass, getEventID, getEventID, getKeyCode, getKeyCode, getKeyModifiers, getModifiers, getModifiers, getMouseModifiers, iconify, invokeAction, invokeAndWait, isModifier, isTertiaryButton, jitter, jitter, key, key, keyPress, keyRelease, keyString, keyStroke, maskToKeyCode, mouseMove, mouseMove, mouseMove, mousePress, mousePress, mousePress, mousePress, mousePress, mouseRelease, mouseRelease, move, moveBy, needMenuFix, onPopup, postEvent, resize, resizeBy, sample, selectAWTMenuItem, selectAWTMenuItemByLabel, selectMenuItem, sendEvent, setAutoDelay, showPopupMenu, simpleClassName, sleep, toString, toString, toString, wait, wait, wait, waitForIdle |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
testers
private static java.util.HashMap testers
- Maps class names to their corresponding Tester object.
testedClass
private java.lang.Class testedClass
- What class does this tester test?
tagMethods
private static final java.lang.String[] tagMethods
cachedMethods
private java.lang.reflect.Method[] cachedMethods
cachedActions
private java.lang.reflect.Method[] cachedActions
cachedComponentActions
private java.lang.reflect.Method[] cachedComponentActions
cachedPropertyChecks
private java.lang.reflect.Method[] cachedPropertyChecks
cachedAssertions
private java.lang.reflect.Method[] cachedAssertions
cachedComponentAssertions
private java.lang.reflect.Method[] cachedComponentAssertions
| Constructor Detail |
ComponentTester
public ComponentTester()
| Method Detail |
setTester
public static void setTester(java.lang.Class forClass, ComponentTester tester)
- Establish the given ComponentTester as the one to use for the given
class. This may be used to override the default tester for a given
core class. Note that this will only work with components loaded by
the framework class loader, not those loaded by the class loader for
the code under test.
getTester
public static ComponentTester getTester(java.awt.Component comp)
- Return the appropriate Tester for the given object.
getTester
public static ComponentTester getTester(java.lang.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.
The abbot tester package is searched first, followed by the tester extensions package.
isExtension
public final boolean isExtension()
- Return whether this tester is an extension.
resolveClass
private static java.lang.Class resolveClass(java.lang.String testerName, java.lang.Class componentClass) throws java.lang.ClassNotFoundException
- Look up the given class, using special class loading rules to maintain
framework consistency.
findTester
private static ComponentTester findTester(java.lang.String testerName, java.lang.Class componentClass)
- Look up the given class with a specific class loader.
getTestedClass
public final java.lang.Class getTestedClass()
- Return the class tested by the given tester.
getFinder
protected abbot.ComponentFinder getFinder()
deriveAccessibleTag
protected java.lang.String deriveAccessibleTag(javax.accessibility.AccessibleContext context)
- Derive a tag from the given accessible context if possible, or return
null.
getTag
public static java.lang.String getTag(java.awt.Component comp)
- Return a reasonable identifier for the given component.
deriveTag
public java.lang.String deriveTag(java.awt.Component comp)
- Provide a String that is fairly distinct for the given component. For
a generic component, attempt to look up some common patterns such as a
title or label. Derived classes should absolutely override this method
if such a String exists.
Don't use component names as tags.
actionWaitForIdle
public void actionWaitForIdle()
- Wait for an idle AWT event queue. Will return when there are no more
events on the event queue.
actionDelay
public void actionDelay(int ms)
- Delay the given number of ms.
actionSelectAWTMenuItemByLabel
public void actionSelectAWTMenuItemByLabel(java.awt.Frame frame, java.lang.String label)
actionSelectMenuItem
public void actionSelectMenuItem(java.awt.Component item)
- Select the given menu item.
actionSelectPopupMenuItem
public void actionSelectPopupMenuItem(java.awt.Component invoker, java.lang.String itemName)
- Pop up a menu at the given location on the given component;
Select the given item.
actionSelectPopupMenuItem
public void actionSelectPopupMenuItem(java.awt.Component invoker, int x, int y, java.lang.String itemName)
- Pop up a menu at the given location on the given component;
Select the given item.
actionShowPopupMenu
public void actionShowPopupMenu(java.awt.Component invoker)
- Pop up a menu in the center of the given component.
actionShowPopupMenu
public void actionShowPopupMenu(java.awt.Component invoker, int x, int y)
- Pop up a menu at the given location on the given component.
actionClick
public void actionClick(java.awt.Component comp)
- Click on the center of the component.
actionClick
public void actionClick(java.awt.Component comp, int x, int y)
- Click on the component at the given location.
actionClick
public void actionClick(java.awt.Component comp, int x, int y, java.lang.String buttons)
- Click on the component at the given location. The buttons string
should be the InputEvent field name for the desired masks, e.g.
"BUTTON1_MASK|CTRL_MASK".
actionClick
public void actionClick(java.awt.Component comp, int x, int y, java.lang.String buttons, int count)
- Click on the component at the given location. The buttons string
should be the InputEvent field name for the desired masks, e.g.
"BUTTON1_MASK|CTRL_MASK". This variation provides for multiple
clicks.
actionKeyPress
public void actionKeyPress(java.lang.String kc)
- Used only for modifier keys. Otherwise, use actionKeyStroke
instead.
actionKeyRelease
public void actionKeyRelease(java.lang.String kc)
- Usually used only for modifier keys. Otherwise, use actionKeyStroke
instead.
actionKeyStroke
public void actionKeyStroke(java.lang.String kc)
- Send the given keystroke, which must be the KeyEvent field name of a
KeyEvent VK_ constant to the program. Sends a key down/up, with no
modifiers. Note that this does not affect the current focus.
actionKeyStroke
public void actionKeyStroke(java.lang.String kc, java.lang.String mods)
- Send the given keystroke, which must be the KeyEvent field name of a
KeyEvent VK_ constant to the program. Sends a key down/up, with the
given modifiers, which should be the InputEvent field name modifier
masks optionally ORed together with "|". Note that this does not
affect the current focus.
NOTE: on OSX, the wait for idle is not sufficient to process the entire keystroke.
actionKeyString
public void actionKeyString(java.lang.String string)
- Send events required to generate the given string.
actionFocus
public void actionFocus(java.awt.Component comp)
- Set the focus on to the given component.
actionDrag
public void actionDrag(java.awt.Component dragSource, int sx, int sy)
- Perform a drag action. Derived classes should provide more specific
identifiers for what is being dragged, e.g. actionDragTableCell or
actionDragListElement.
actionDrop
public void actionDrop(java.awt.Component dropTarget, int x, int y)
- Perform a basic drop action (implicitly causing a preceding mouse
drag).
assertImage
public boolean assertImage(java.awt.Component comp, java.io.File fileImage, boolean ignoreBorder)
- Return whether the component's contents matches the given image.
assertFrameShowing
public boolean assertFrameShowing(java.lang.String title)
- Returns whether frame/dialog with the given title is showing.
waitForFrameShowing
public static void waitForFrameShowing(java.lang.String title)
- Convenience wait for a window to be displayed. This method is
provided as a convenience for hand-coded tests, since scripts will use
a wait step instead.
assertComponentShowing
public boolean assertComponentShowing(abbot.script.ComponentReference ref)
waitForComponentShowing
public static void waitForComponentShowing(abbot.script.ComponentReference ref)
getMethods
private java.lang.reflect.Method[] getMethods(java.lang.String prefix, java.lang.Class returnType, boolean onComponent)
- Look up methods with the given prefix.
getActions
public java.lang.reflect.Method[] getActions()
- Return a list of all actions defined by this class that don't depend
on a component argument.
getComponentActions
public java.lang.reflect.Method[] getComponentActions()
- Return a list of all actions defined by this class that require
a component argument.
getPropertyChecks
public java.lang.reflect.Method[] getPropertyChecks()
- Return a list of all property checks defined by this class. The first
argument must be a Component.
getAssertions
public java.lang.reflect.Method[] getAssertions()
- Return a list of all assertions defined by this class that don't
depend on a component argument.
getComponentAssertions
public java.lang.reflect.Method[] getComponentAssertions()
- Return a list of all assertions defined by this class that require a
component argument.
stripHTML
public static java.lang.String stripHTML(java.lang.String str)
- Quick and dirty strip raw text from html, for getting the basic text
from html-formatted labels and buttons. Behavior is undefined for
badly formatted html.
waitAction
protected void waitAction(java.lang.String desc, abbot.Condition cond) throws ActionFailedException
- Wait for the given condition, throwing an ActionFailedException if it
times out.
|
|||||||||
| Home >> All >> abbot >> [ tester overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC