Time for action – showing views

To show other views, the same mechanism is followed in the UI tests, as a user would do; by going to Window | Show View | Other.

  1. Create a new method, testTimeZoneView(), with a @Test annotation.
  2. From the bot, open the Other dialog by going to Window | Show View.
  3. Get the shell with the title Show View and activate it.
  4. Expand the Timekeeping node and select the Time Zone View node (the view created in Chapter 2, Creating Views with SWT).
  5. Click on the OK button to have the view shown.
  6. Use the bot.viewByTitle() method to acquire a reference to the view.
  7. Assert that the view is not null.
  8. The code looks like this:
    @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);
    }
  9. Run the tests and ensure that they were successful.

What just happened?

Using the built-in Eclipse mechanism to switch views, the bot navigated to the Time Zone View menu inside Window | Show View | Other | Timekeeping to bring the view to the screen.

Once shown, the viewByTitle() method of the bot can be used to get a reference to the widget; verify that it is not null.

Being able to select a view programmatically is such a common occurrence that it can help to have a utility method to open a view on demand.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset