Checking Tree Items

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

Checking Tree Items

Postby rcraddock » Mon Jul 07, 2008 3:16 am


I'm trying to write a check that there are only certain items displayed in my Tree View, but I'm having trouble accessing the underlying Tree.

I have a TreeItemLocator that gets me to the top of the branch I wish to check, and I'm sure I can get the children once I have the actual TreeItem, I juts can't make the leap from the Locator to the actual widget in this case.

I'm sure it must be something to do with WidgetReferences, and that I'm just having a bad Monday morning :-)


Posts: 3
Joined: Wed Apr 02, 2008 8:22 am

Re: Checking Tree Items

Postby Phil Quitslund » Mon Jul 07, 2008 8:56 am

Something like this should work:

Code: Select all
IWidgetReference ref = (IWidgetReference)ui.find(new TreeItemLocator(...));
final TreeItem item = (TreeItem)ref.getWidget();

With the tree item in hand, you should be able to get at the tree like this:

Code: Select all
Tree tree = item.getParent();

and it's children like so:

Code: Select all
TreeItem[] items = tree.getItems();

Do note that you'll have to be mindful to access the widgets on the UI thread (and not the test thread). In other words, wrap the above in a runnable passed to the display something like this:

Code: Select all
Display.getDefault().syncExec(new Runnable() {
   public void run() {
      Tree tree = item.getParent();
      TreeItem[] items = tree.getItems();

See this entry for a bit more: ... test_state

Finally, what are you trying to assert? Perhaps we can help you craft a custom condition?

Hope this helps.
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest