When a matching component could not be found, regardless of the lookup type, the thrown
ComponentLookupException includes a formatted component hierarchy that can help us determine why the component lookup failed.
For our example, we are going to use a frame of type
org.fest.swing.test.TestFrame that contains a
JButton with name 'click'. The following code listing shows a mistake we made when looking up that button in our test. We accidentally used the name 'ok' instead of 'click':
When we run our test, it will obviously fail, because the frame does not have any button with name 'ok.' To help us diagnose the problem, the thrown
ComponentLookupException displays a nicely formatted component hierarchy:
The displayed component hierarchy, unlike the default
toString method in Swing components, does not contain any information related to how the components look (e.g. component sizes, colors, layouts, etc.) That information is pretty much useless, since functional testing focuses on the behavior of the GUI. Instead, FEST-Swing uses custom formatters to show properties 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.