Having been able to acquire a reference to the view, the next step is to deal with specific user-interface components. For standard controls such as Button
and Text
labels, the bot provides standard methods. To get hold of other components, the widget hierarchy will have to be interrogated directly.
testTimeZoneView()
method, get the Widget
from the returned SWTBotView
.Matcher
that is based on widgetsOfType(CTabItem.class)
.bot.widgets()
to search for a list of CTabItem
instances in the view's widget.SWTBotView timeZoneView = bot.viewByTitle("Time Zone View"); assertNotNull(timeZoneView); Widget widget = timeZoneView.getWidget(); org.hamcrest.Matcher<CTabItem> matcher = WidgetMatcherFactory.widgetOfType(CTabItem.class); final java.util.List<? extends CTabItem> ctabs = bot.widgets(matcher,widget); assertEquals(18,ctabs.size());
It is possible to write code to walk the user interface tree directly. However, because the widgets have to be interrogated on the UI thread, care has to be taken to find the children.
SWTBot provides a generic Matcher
mechanism, which is a predicate that can return true
if a certain condition occurs. The Matcher
provided by widgetOfType()
matches items that have a certain class type; similarly many other matchers can be instantiated with the withXxx()
calls, such as withLabel()
and withId()
. Matchers can be combined with the allOf()
and anyOf()
methods, by providing AND/OR logic respectively.
The widgets()
call walks through the tree recursively to find all widgets that match a particular specification. A single-argument version finds all elements from the active shell; the two-argument version allows a specific parent to be searched, which in this case is the TimeZoneView
itself.
Finally, the size of the list is compared with the number of time-zone groups, which in this case is 18.