Time for action: showing views

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.

  1. Create a new method, testTimeZoneView, with an @Test annotation.
  2. From the bot, open the Window | Show View | Other… dialog.
  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:
    @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 pass.

What just happened?

Using the built-in Eclipse mechanism to switch views, the bot navigated the Window | Show View | Other… | Timekeeping | Time Zone View menu hierarchy 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, and 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 be able 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
18.225.98.111