|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object abbot.tester.Robot abbot.tester.ComponentTester
public class ComponentTester
Provides basic programmatic operation of a Component
and related
UI objects such as windows, menus and menu bars throuh action methods.
Also provides some useful assertions about properties of a Component
.
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 actionXXX
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).
All public action methods should ensure that the actions they
trigger are finished on return, or will be finished before any subsequent
actions are requested.
Action methods generally represent user-driven actions such as menu selection, table selection, popup menus, etc. All actions should have the following signature:
public void actionSpinMeRoundLikeARecord(Component c, ...);
public void actionPinchMe(Component c, ComponentLocation loc);
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.
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.
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:
Note that these assertions do not throw exceptions but rather return apublic boolean assertMyself(...);
public boolean assertBorderIsAtrociouslyUgly(Component c, ...);
boolean
value indicating success or failure. 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 if the method returns false.
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(Component)
.
Any non-property methods with the property signature, should be added to thepublic Object getHairpiece(Component c);
public boolean isRighteouslyIndignant(Component c);
IGNORED_METHODS
set, since property-like methods are scanned
dynamically to populate the editor
's
action menus.
When naming a selection method, include the logical substructure target of
the selection in the name (e.g.
Extending ComponentTester
Following are the steps required to implement a Tester object for a custom
class.
Create the Tester Class
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.PR0NViewer
would be
abbot.tester.extensions.PR0NViewerTester
.
Add Action Methods
Add action
methods which effect user actions.
See the section on naming conventions below.
Add Assertion Methods
Add assert
methods to access attributes not readily available
as properties
Add Substructure Support
Add a corresponding ComponentLocation
implementation to
handle any substructure present in your Component
.
See ComponentLocation
for details.
Add Substructure-handling Methods
parseLocation(String)
Convert the given String
into an instance of
ComponentLocation
specific to your Tester. Here is an example
implementation from JListTester
:
public ComponentLocation parseLocation(String encoded) {
return new JListLocation().parse(encoded);
}
getLocation(Component,Point)
Use the given Point
to create a ComponentLocation
instance appropriate for the Component
substructure
available at that location. For example, on a JList
,
you would return a JListLocation
based on the
stringified value at that location, the row/index at that
location, or the raw Point
,
in order of preference. If a stringified value is unavailable,
fall back to an indexed position; if that is not possible (if, for
instance, the location is outside the list contents), return a
ComponentLocation
based on the raw Point
.
Set Editor Properties
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.PR0NViewerTester
, the following
properties should be defined:
Since these properties are global, if your Tester class defines a method
which is also defined by another Tester class, you must supply the class
name as a prefix to the property.
actionWiggle.menu
short name for Insert menu
actionWiggle.desc
short description (optional)
actionWiggle.icon
icon for the action (optional)
PR0NViewerTester.actionWiggle.args
javadoc-style
description of method, displayed when asking the user for its arguments
Method Naming Conventions
Action methods should be named according to the human-centric action that
is being performed if at all possible. For example, use
actionSelectRow
in a List rather than
actionSelectIndex
. If there's no common usage, or if the
usage is too vague or diverse, use the specific terms used in code.
For example, JScrollBarTester
uses
actionScrollUnitUp()
and
actionScrollBlockUp()
;
since there is no common language usage for these
concepts (line and page exist, but are not appropriate if what is scrolled
is not text).
JTableTester.actionSelectCell(Component,JTableLocation)
JTableTester.actionSelectCell()),
since some components may have more than one type of selectable item
within them.
Field Summary | |
---|---|
protected static Set |
IGNORED_METHODS
Add any method names here which should not show up in a dynamically generated list of property methods. |
Fields inherited from class abbot.tester.Robot |
---|
componentDelay, defaultDelay, EM_AWT, EM_ROBOT, IDLE_TIMEOUT, MOUSELESS_MODIFIER, MOUSELESS_MODIFIER_MASK, popupDelay |
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 | |
---|---|
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 comp,
int x,
int y)
Click on the component at the given location (mouse button 1). |
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 |
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,
int buttons)
Perform a drag action with the given modifiers. |
void |
actionDrag(Component dragSource,
ComponentLocation loc,
String buttons)
Deprecated. Use the integer modifier mask
version instead. |
void |
actionDrag(Component dragSource,
int sx,
int sy)
Perform a drag action. |
void |
actionDrag(Component dragSource,
int sx,
int sy,
String buttons)
Deprecated. Use the ComponentLocation/
integer modifier mask version instead. |
void |
actionDragOver(Component target)
Drag the current dragged object over the given component. |
void |
actionDragOver(Component target,
ComponentLocation where)
Drag the current dragged object over the given target/location. |
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(int keyCode)
Generate a key press event for the given virtual key code. |
void |
actionKeyRelease(Component comp,
int keyCode)
Generate a key release event sent to the given component. |
void |
actionKeyRelease(int keyCode)
Generate a key release event. |
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(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 |
actionMouseMove(Component comp,
ComponentLocation loc)
Move the mouse/pointer to the given location. |
void |
actionMousePress(Component comp,
ComponentLocation loc)
Press mouse button 1 at the given location. |
void |
actionMousePress(Component comp,
ComponentLocation loc,
int mask)
Press mouse buttons corresponding to the given mask at the given location. |
void |
actionMouseRelease()
Release any currently held mouse buttons. |
void |
actionSelectAWTMenuItem(Frame menuFrame,
String path)
Selects an AWT menu item ( MenuItem ) and returns when
the invocation has triggered (though not necessarily completed). |
void |
actionSelectAWTMenuItemByLabel(Frame menuFrame,
String path)
Deprecated. Renamed to actionSelectAWTMenuItem(Frame,String) . |
void |
actionSelectAWTPopupMenuItem(Component invoker,
String path)
Selects an AWT menu item and returns when the invocation has triggered (though not necessarily completed). |
void |
actionSelectAWTPopupMenuItemByLabel(Component invoker,
String path)
Deprecated. Renamed to actionSelectAWTPopupMenuItem(Component,String) . |
void |
actionSelectMenuItem(Component item)
Select the given menu item. |
void |
actionSelectMenuItem(Component sameWindow,
String path)
Select the given menu item, given its path and a component on the same window. |
void |
actionSelectPopupMenuItem(Component invoker,
ComponentLocation loc,
String path)
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 path)
Pop up a menu at the given coordinates on the given component and select the given item. |
void |
actionSelectPopupMenuItem(Component invoker,
String path)
Pop up a menu at the center of the given component and select the given item. |
void |
actionSetModifiers(int mask,
boolean pressed)
Set the state of the given modifier keys. |
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(Hierarchy h,
String id)
Returns whether a Window corresponding to the given String is showing. |
boolean |
assertFrameShowing(String id)
Deprecated. This method does not specify the proper context for the lookup. Use assertFrameShowing(Hierarchy,String) instead. |
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)
Return a shared instance of the corresponding ComponentTester 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 a shared instance of the appropriate ComponentTester for the given Component . |
protected boolean |
isCustom(Class c)
Returns whether the given class is not a core JRE class. |
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(Hierarchy h,
String identifier)
Convenience wait for a window to be displayed. |
void |
waitForFrameShowing(String identifier)
Deprecated. This method does not provide sufficient context to reliably find a component. Use waitForFrameShowing(Hierarchy,String)
instead. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Set IGNORED_METHODS
Constructor Detail |
---|
public ComponentTester()
Method Detail |
---|
public static void setTester(Class forClass, ComponentTester tester)
public static ComponentTester getTester(Component comp)
ComponentTester
for the given Component
.
This method is primarily used by the scripting system, since the
appropriate ComponentTester
for a given Component
is not known a priori. Coded unit tests should generally just
create an instance of the desired type of ComponentTester
for local use.
public static ComponentTester getTester(Class componentClass)
ComponentTester
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.
This method is primarily used by the scripting system, since the
appropriate ComponentTester
for a given Component is not
known a priori. Coded unit tests should generally just create
an instance of the desired type of ComponentTester
for
local use.
public final boolean isExtension()
protected String deriveAccessibleTag(AccessibleContext context)
public static String getTag(Component comp)
protected boolean isCustom(Class c)
public String deriveTag(Component comp)
public void actionWaitForIdle()
public void actionDelay(int ms)
public void actionSelectAWTMenuItemByLabel(Frame menuFrame, String path)
actionSelectAWTMenuItem(Frame,String)
.
public void actionSelectAWTMenuItem(Frame menuFrame, String path)
MenuItem
) and returns when
the invocation has triggered (though not necessarily completed).
menuFrame
- path
- either a unique label or the menu path.Robot.selectAWTMenuItem(Frame,String)
public void actionSelectAWTPopupMenuItemByLabel(Component invoker, String path)
actionSelectAWTPopupMenuItem(Component,String)
.
public void actionSelectAWTPopupMenuItem(Component invoker, String path)
Robot.selectAWTPopupMenuItem(Component,String)
public void actionSelectMenuItem(Component item)
public void actionSelectMenuItem(Component sameWindow, String path)
public void actionSelectPopupMenuItem(Component invoker, String path)
public void actionSelectPopupMenuItem(Component invoker, ComponentLocation loc, String path)
public void actionSelectPopupMenuItem(Component invoker, int x, int y, String path)
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
AWTConstants.POPUP_MASK
and AWTConstants.TERTIARY_MASK
for
platform-independent masks for those buttons. Key modifiers other
than InputEvent.ALT_MASK
and InputEvent.META_MASK
may
also be used as a convenience.
public void actionClick(Component comp, int x, int y, int buttons, int count)
InputEvent.BUTTON1_MASK
. ComponentTester also defines
AWTConstants.POPUP_MASK
and AWTConstants.TERTIARY_MASK
for
platform-independent masks for those buttons. Key modifiers other
than InputEvent.ALT_MASK
and InputEvent.META_MASK
may
also be used as a convenience.
public void actionKeyPress(Component comp, int keyCode)
public void actionKeyPress(int keyCode)
public void actionKeyRelease(Component comp, int keyCode)
public void actionKeyRelease(int keyCode)
public void actionSetModifiers(int mask, boolean pressed)
public void actionKeyStroke(Component c, int keyCode)
public void actionKeyStroke(int keyCode)
public void actionKeyStroke(Component c, int keyCode, int modifiers)
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 actionMouseMove(Component comp, ComponentLocation loc)
public void actionMousePress(Component comp, ComponentLocation loc)
public void actionMousePress(Component comp, ComponentLocation loc, int mask)
public void actionMouseRelease()
public void actionDrag(Component dragSource, ComponentLocation loc)
JTreeLocation
might encapsulate the expansion
control location for the path [root, node A, child B].
public void actionDrag(Component dragSource)
public void actionDrag(Component dragSource, ComponentLocation loc, String buttons)
integer modifier mask
version instead.
dragSource
- source of the dragloc
- identifies where on the given Component
to begin the
drag.buttons
- a String
representation of key modifiers,
e.g. "ALT|SHIFT", based on the InputEvent
_MASK
fields
.public void actionDrag(Component dragSource, ComponentLocation loc, int buttons)
dragSource
- source of the dragloc
- identifies where on the given Component
to begin the
drag.buttons
- one or more of the
InputEvent BUTTONN_MASK
fields
.public void actionDrag(Component dragSource, int sx, int sy)
public void actionDrag(Component dragSource, int sx, int sy, String buttons)
ComponentLocation/
integer modifier mask
version instead.
dragSource
- source of the dragsx
- X coordinatesy
- Y coordinatebuttons
- a String
representation of key modifiers,
e.g. "ALT|SHIFT", based on the InputEvent
_MASK
fields
.public void actionDragOver(Component target)
public void actionDragOver(Component target, ComponentLocation where)
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(Hierarchy h, String id)
Component.getName()
.
public boolean assertFrameShowing(String id)
assertFrameShowing(Hierarchy,String)
instead.
Component.getName()
.
public void waitForFrameShowing(Hierarchy h, String identifier)
Component.getName()
.
This method is provided as a convenience for hand-coded tests, since
scripts will use a wait step instead.
The property abbot.robot.component_delay
affects the
default timeout.
public void waitForFrameShowing(String identifier)
waitForFrameShowing(Hierarchy,String)
instead.
Component.getName()
.
This method is provided as a convenience for hand-coded tests, since
scripts will use a wait step instead.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
ActionFailedException
public Class getTestedClass(Class cls)
public ComponentLocation parseLocation(String encoded)
public ComponentLocation getLocation(Component c, Point where)
JTree
, for example, might provide a
JTreeLocation
indicating a path or row in the tree.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |