Locate Show Next Match, Show Previous Match from SearchView

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

Locate Show Next Match, Show Previous Match from SearchView

Postby hyshyshys » Tue Aug 03, 2010 5:05 am

I am trying to locate buttons Show Next Match and Show Previous Match from the toolbar of the SearchView results. This SearchView come from Eclipse RCP plugins. I want to know how I can click on these buttons.

I am using version 5.1.0.

This code has been generated by the recorder:
Code: Select all
public void testTest_search_file() throws Exception {
   IUIContext ui = getUI();
   ui.click(new MenuItemLocator("Search/File..."));
   ui.wait(new ShellShowingCondition("Search"));
   ui.click(new ButtonLocator("&Search"));
   ui.wait(new ShellDisposedCondition("Search"));
   // Click on Show next match
   //WARNING: unsupported widget selection ignored - Widget Selection event: null
   // Click on Show previous match
   //WARNING: unsupported widget selection ignored - Widget Selection event: null

The next code was generated by the recorder. This example shows a valid record for the button Remove All Matches:
Code: Select all
ui.click(new SWTWidgetLocator(ToolItem.class, "", 4,
   new SWTWidgetLocator(ToolBar.class, 2, new SWTWidgetLocator(Composite.class))));

These indexes generated by the recorder could be wrong if there is new ToolItem or ToolBar added in the application. So, I don’t want to update these indexes when a new button is added to my apps or when eclipse team modify its toolbar.

It could be great to have the possibility to click on a ToolBar button by specifying a tooltipText. So, ui.click is call when the specified tooltipText match the tooltip of a toolItem. No need to update the indexes.

This snippet shows an example of this functionality:
Code: Select all
* Search and click on the toolBar button that match the specified tool tip text.
* @param ui context ui
* @param widgetTooltipText tooltip text of the widget
* @throws WidgetSearchException
* @throws InterruptedException
private void clickToolBarButtonWithToolTipText(IUIContext ui, final String widgetTooltipText) throws WidgetSearchException, InterruptedException {
   SWTWidgetLocator swtWidgetLocator = new SWTWidgetLocator(ToolItem.class);
   IWidgetLocator[] widgetLocators = swtWidgetLocator.findAll(ui);
   for (IWidgetLocator widgetLocator : widgetLocators) {
      if(widgetLocator instanceof IWidgetReference) {
         IWidgetReference widgetReference = (IWidgetReference) widgetLocator;
         Object widget = widgetReference.getWidget();
         if (widget instanceof ToolItem) {
            final ToolItem toolItem = (ToolItem) widget;
            final Boolean [] result = new Boolean[1];
            result[0] = false;
            Display.getDefault().syncExec(new Runnable() {
               public void run() {
                  String toolTip = toolItem.getToolTipText();
                  if (toolTip != null) {
                     result[0] = toolTip.compareToIgnoreCase(widgetTooltipText)==0;
            if (result[0]){

Tell me if you have found a better way to send click on tool items.

Posts: 37
Joined: Thu Jul 03, 2008 12:27 pm

Re: Locate Show Next Match, Show Previous Match from SearchV

Postby keertip » Fri Aug 06, 2010 9:44 am

ToolItems can be identified either by their text or action/contribution ID. For eg. to click on the New Wizard ToolITem

Code: Select all
ui.click(new ContributedToolItemLocator("newWizardDropDown"));      

or to click on New Task Toolitem in the task list view
Code: Select all
ui.click(new ContributedToolItemLocator("org.eclipse.mylyn.tasklist.ui.repositories.actions.create"));

At present we do not have built in support for identifying ToolItems by their tooltip text. So if you do want to use tooltip text, then the code that you are currently using is the way to do it.
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am

Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest