Most of the time, you will start with a
Panel or a
Window instance representing
a given panel or the whole application. In order to test your system, you will
first need to retrieve the UISpec4J components representing the
displayed buttons, tables or trees that let you interact with the application
and check its status.
To this end, the Panel class provides a set of getXxx() methods, for instance getButton(),
getTree(), etc.:
public void MyFunctionalTestCase extends UISpecTestCase {
public void test() {
Window mainWindow = getMainWindow();
mainWindow.getMenuBar().getMenu("File").getSubMenu("Open...").click();
...
assertTrue(mainWindow.getTree().contentEquals(...));
...
mainWindow.getButton("Apply").click();
}
Each getXxx() method comes in three flavors:
- getXxx() can be used when there is only one instance of this
component type in the panel - for instance when you know there is a single
Tree in the panel, or a single List in a small selection dialog
- getXxx(String name) lets you specify the name of the component to
be found. For most components, this name will be an internal name assigned
by the developers. For some components such as Buttons, CheckBoxes or RadioButtons,
the name will be the text displayed on the component. When searching for components
this way, the system will use the following priorities:
- Exact match for the displayed text, if the component supports them
- Substring for the displayed text, if the component supports them
- Substring for the displayed text of the bound JLabel component, if it exists
- Exact match for the internal name
- Substring for the internal name
- getXxx(ComponentMatcher matcher) lets you define your own matching
policy.
For all three signatures, two exceptions will be thrown: ComponentNotFoundException if
nothing was found, and ComponentAmbiguityException if several matches were found.
NB: It is possible to add getXxx() methods for other components than those shipped with
UISpec4J. Please refer to the extension mechanism
documentation for further details.