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.enterText("toto");
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]){
ui.click(widgetReference);
break;
}
}
}
}
}
Tell me if you have found a better way to send click on tool items.
Thanks,