There are cases that more than one GUI component matches the search criteria used in a lookup. Typical examples are:
- looking up a component by type and there is more than one component of such type in the frame or dialog
- looking up a component by name and there is more than one component with the same name in the frame or dialog
For our example, we are going to use a frame of type org.fest.swing.test.TestFrame that contains two instances of JButton with names 'first' and 'second'. In the following code listing we are looking up a JButton by type:
This test will fail, because the frame has two components of type JButton. To help us diagnose the problem, the thrown ComponentLookupException displays all the matching components found:
org.fest.swing.exception.ComponentLookupException: Found more than one component using matcher org.fest.swing.core.TypeMatcher[type=javax.swing.JButton, requireShowing=false].
Found:
javax.swing.JButton[name='first', text='First Button', enabled=true]
javax.swing.JButton[name='second', text='Second Button', enabled=true]
at org.fest.swing.core.BasicComponentFinder.multipleComponentsFound(BasicComponentFinder.java:102)
The thrown ComponentLookupException uses component formatters to display information that can help us solve problems in our functional tests. For more details about custom component formatters (including how to override the provided ones with your own,) please visit the Component Formatters section.