|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectabbot.tester.Robot
abbot.tester.ComponentTester
Provides basic programmatic operation of a Component. Also provides some useful assertions about properties of a Component.
Actions are generally user-driven actions such as menu selection, table selection, popup menus, etc. 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.
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. All assertions should have one of the following signatures:
public boolean assertWhat(...);
public boolean assertWhat(Component c, ...);
Note that these assertions do not throw exceptions; normally these assertions will be wrapped by an abbot.script.Assert step if you want to cause a test failure, or you can manually throw the proper failure exception.
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 for which results are required for the action itself.
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, number of arguments, and by argument type. The actionX methods will be synchronized with the event dispatch thread when invoked, so you should only do synchronization with waitForIdle when you depend on the results of a particular event prior to sending the next one (e.g. scrolling a table cell into view before selecting it).
The ComponentLocation abstraction allows all derived tester classes to
inherit click, popup menu, and drag variants without having to explicitly
define new methods for component-specific substructures. The new class
need only define the parseLocation(String)
method, which
should return a location specific to the component in question.
Derive from this class to implement actions and assertions specific to
a given component class. Testers for any classes found in the JRE
(i.e. in the java.awt or javax.swing packages) 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
.
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
Field Summary |
Fields inherited from class abbot.tester.Robot |
BUTTON_MASK, componentDelay, defaultDelay, DRAG_THRESHOLD, EM_AWT, EM_ROBOT, MENU_SHORTCUT_KEYCODE, MENU_SHORTCUT_MASK, MENU_SHORTCUT_MODIFIER, MENU_SHORTCUT_STRING, MULTI_CLICK_INTERVAL, POPUP_MASK, POPUP_MODIFIER, POPUP_ON_PRESS, popupDelay, TERTIARY_MASK, TERTIARY_MODIFIER |
Constructor Summary | |
ComponentTester()
|
Method Summary | |
void |
actionClick(Component comp)
Click on the center of the component. |
void |
actionClick(Component c,
ComponentLocation loc)
Click on the component at the given location. |
void |
actionClick(Component c,
ComponentLocation loc,
int buttons)
Click on the component at the given location with the given modifiers. |
void |
actionClick(Component c,
ComponentLocation loc,
int buttons,
int count)
Click on the component at the given location, with the given modifiers and click count. |
void |
actionClick(Component c,
ComponentLocation loc,
String buttons)
Deprecated. Use actionClick(Component, ComponentLocation, int) instead |
void |
actionClick(Component c,
ComponentLocation loc,
String buttons,
int count)
Deprecated. Use actionClick(Component, ComponentLocation, int, int) instead |
void |
actionClick(Component comp,
int x,
int y)
Click on the component at the given location. |
void |
actionClick(Component comp,
int x,
int y,
int buttons)
Click on the component at the given location. |
void |
actionClick(Component comp,
int x,
int y,
int buttons,
int count)
Click on the component at the given location, specifying buttons and the number of clicks. |
void |
actionClick(Component comp,
int x,
int y,
String buttons)
Deprecated. Use actionClick(Component, ComponentLocation, int) instead. |
void |
actionClick(Component comp,
int x,
int y,
String buttons,
int count)
Deprecated. Use actionClick(Component, ComponentLocation, int, int) instead |
void |
actionDelay(int ms)
Delay the given number of ms. |
void |
actionDrag(Component dragSource)
Perform a drag action. |
void |
actionDrag(Component dragSource,
ComponentLocation loc)
Perform a drag action. |
void |
actionDrag(Component dragSource,
ComponentLocation loc,
String modifiers)
Perform a drag action with the given modifiers. |
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)
Perform a basic drop action (implicitly causing preceding mouse drag motion). |
void |
actionDrop(Component dropTarget,
ComponentLocation loc)
Perform a basic drop action (implicitly causing preceding mouse drag motion). |
void |
actionDrop(Component dropTarget,
int x,
int y)
Perform a basic drop action (implicitly causing preceding mouse drag motion). |
void |
actionFocus(Component comp)
Set the focus on to the given component. |
void |
actionKeyPress(Component comp,
int keyCode)
Send a key press event for the given virtual key code to the given Component. |
void |
actionKeyPress(Component comp,
String kc)
Deprecated. Use actionKeyPress(Component, int) instead. |
void |
actionKeyPress(int keyCode)
Generate a key press event for the given virtual key code. |
void |
actionKeyPress(String kc)
Deprecated. Use actionKeyPress(int) instead. |
void |
actionKeyRelease(Component comp,
int keyCode)
Generate a key release event sent to the given component. |
void |
actionKeyRelease(Component comp,
String kc)
Deprecated. Use actionKeyRelease(Component, int) instead. |
void |
actionKeyRelease(int keyCode)
Generate a key release event. |
void |
actionKeyRelease(String kc)
Deprecated. Use actionKeyRelease(int) instead. |
void |
actionKeyString(Component c,
String string)
Send events required to generate the given string on the given component. |
void |
actionKeyString(String string)
Send events required to generate the given string. |
void |
actionKeyStroke(Component c,
int keyCode)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionKeyStroke(Component c,
int keyCode,
int modifiers)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionKeyStroke(Component c,
String code)
Deprecated. Use actionKeyStroke(Component, int) instead. |
void |
actionKeyStroke(Component c,
String code,
String modifiers)
Deprecated. Use actionKeyStroke(Component, int, int)
instead. |
void |
actionKeyStroke(int keyCode)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant. |
void |
actionKeyStroke(int keyCode,
int modifiers)
Send the given keystroke, which must be the KeyEvent field name of a KeyEvent VK_ constant to the program. |
void |
actionKeyStroke(String code)
Deprecated. Use actionKeyStroke(int) instead. |
void |
actionKeyStroke(String keyCode,
String modifiers)
Deprecated. Use actionKeyStroke(int, int) instead. |
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,
ComponentLocation loc,
String itemName)
Pop up a menu at the given location on the given component and select the given item. |
void |
actionSelectPopupMenuItem(Component invoker,
int x,
int y,
String itemName)
Pop up a menu at the given coordinates on the given component and select the given item. |
void |
actionSelectPopupMenuItem(Component invoker,
String itemName)
Pop up a menu at the center of the given component and select the given item. |
void |
actionShowPopupMenu(Component invoker)
Pop up a menu in the center of the given component. |
void |
actionShowPopupMenu(Component invoker,
ComponentLocation loc)
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 id)
Deprecated. This method does not provide sufficient context to reliably find a component. |
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)
Determine a component-specific identifier not already defined in other component attributes. |
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. |
ComponentLocation |
getLocation(Component c,
Point where)
Return a ComponentLocation for the given Point. |
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. |
ComponentLocation |
parseLocation(String encoded)
Parse the String representation of a ComponentLocation into the actual ComponentLocation object. |
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)
Deprecated. This method does not provide sufficient context to reliably find a component. |
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 String deriveAccessibleTag(AccessibleContext context)
public static String getTag(Component comp)
public String deriveTag(Component comp)
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, ComponentLocation loc, String itemName)
public void actionSelectPopupMenuItem(Component invoker, int x, int y, String itemName)
public void actionShowPopupMenu(Component invoker)
public void actionShowPopupMenu(Component invoker, ComponentLocation loc)
public void actionShowPopupMenu(Component invoker, int x, int y)
public void actionClick(Component comp)
public void actionClick(Component c, ComponentLocation loc)
public void actionClick(Component c, ComponentLocation loc, int buttons)
public void actionClick(Component c, ComponentLocation loc, int buttons, int count)
public void actionClick(Component comp, int x, int y)
public void actionClick(Component comp, int x, int y, int buttons)
InputEvent.BUTTON1_MASK
. ComponentTester also defines
POPUP_MASK
and TERTIARY_MASK
for
platform-independent masks for those buttons.
public void actionClick(Component comp, int x, int y, int buttons, int count)
InputEvent.BUTTON1_MASK
. ComponentTester also defines
POPUP_MASK
and TERTIARY_MASK
for
platform-independent masks for those buttons.
public void actionClick(Component c, ComponentLocation loc, String buttons)
public void actionClick(Component c, ComponentLocation loc, String buttons, int count)
public void actionClick(Component comp, int x, int y, String buttons)
BUTTON1_MASK
. The special names POPUP_MASK
,
and TERTIARY_MASK
are also available.
public void actionClick(Component comp, int x, int y, String buttons, int count)
BUTTON1_MASK
. The special names POPUP_MASK
,
and TERTIARY_MASK
are also available.
This variation provides for multiple clicks.
public void actionKeyPress(Component comp, String kc)
actionKeyPress(Component, int)
instead.
actionKeyPress(Component, int)
public void actionKeyPress(Component comp, int keyCode)
public void actionKeyPress(String kc)
actionKeyPress(int)
instead.
actionKeyPress(int)
public void actionKeyPress(int keyCode)
public void actionKeyRelease(Component comp, String kc)
actionKeyRelease(Component, int)
instead.
actionKeyRelease(Component, int)
public void actionKeyRelease(Component comp, int keyCode)
public void actionKeyRelease(String kc)
actionKeyRelease(int)
instead.
actionKeyRelease(int)
public void actionKeyRelease(int keyCode)
public void actionKeyStroke(Component c, String code)
actionKeyStroke(Component, int)
instead.
actionKeyStroke(Component, int)
public void actionKeyStroke(Component c, int keyCode)
public void actionKeyStroke(String code)
actionKeyStroke(int)
instead.
actionKeyStroke(int)
public void actionKeyStroke(int keyCode)
public void actionKeyStroke(Component c, String code, String modifiers)
actionKeyStroke(Component, int, int)
instead.
actionKeyStroke(Component, int, int)
public void actionKeyStroke(Component c, int keyCode, int modifiers)
public void actionKeyStroke(String keyCode, String modifiers)
actionKeyStroke(int, int)
instead.
actionKeyStroke(int, int)
public void actionKeyStroke(int keyCode, int modifiers)
public void actionKeyString(Component c, String string)
actionKeyString(String)
.
public void actionKeyString(String string)
public void actionFocus(Component comp)
public void actionDrag(Component dragSource, ComponentLocation loc)
public void actionDrag(Component dragSource)
public void actionDrag(Component dragSource, ComponentLocation loc, String modifiers)
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)
public void actionDrop(Component dropTarget, ComponentLocation loc)
public void actionDrop(Component dropTarget, int x, int y)
public boolean assertImage(Component comp, File fileImage, boolean ignoreBorder)
public boolean assertFrameShowing(String id)
ComponentTestFixture.isShowing(String)
public void waitForFrameShowing(String identifier)
The property abbot.robot.component_delay affects the default timeout.
ComponentTestFixture.isShowing(String)
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
ActionFailedException
public Class getTestedClass(Class cls)
public ComponentLocation parseLocation(String encoded)
public ComponentLocation getLocation(Component c, Point where)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |