To show other views, the same mechanism is done in the UI tests as a user would do, by navigating the Window | Show View | Other… menu.
Create a new method,
testTimeZoneView
, with an@Test
annotation.From the bot, open the Window | Show View | Other… dialog.
Get the shell with the title
Show View
and activate it.Expand the
Timekeeping
node and select theTime Zone View
node (the view created in Chapter 2, Creating Views with SWT).Click on the OK button to have the view shown.
Use the
bot.viewByTitle()
method to acquire a reference to the view.Assert that the view is not
null
.The code looks like:
@Test public void testTimeZoneView() { bot.menu("Window").menu("Show View").menu("Other...").click(); SWTBotShell shell = bot.shell("Show View"); shell.activate(); bot.tree().expandNode("Timekeeping").select("Time Zone View"); bot.button("OK").click(); SWTBotView timeZoneView = bot.viewByTitle("Time Zone View"); assertNotNull(timeZoneView); }
Run the tests...