|
|
|
Re: SWTBot and context menus [message #44550 is a reply to message #38116] |
Tue, 21 July 2009 20:20 |
Will Horn Messages: 265 Registered: July 2009 |
Senior Member |
|
|
I don't know if this is related to the redesign effort, but is there a
reason why there is no wrapper for a Menu? SWTBotMenu wraps MenuItem, not
Menu.
Especially with context menus, it is necessary to test certain things about
the menu, like the number of menu items it contains. Currently, my approach
is to get a SWTBotMenu, then do something like:
assertThat(menu.widget.getParent().getItemCount(), is(i));
But another thing I would like to be able to test is that no context menu
shows up under certain conditions. In this case, so the above approach
doesn't work. A Menu is a real widget, so why not have a wrapper for it?
It's trivial to do (some code below), but maybe I'm missing some reasons why
not?
Sample code:
Matcher<Tree> matcher = widgetOfType(Tree.class);
final EnhancedSWTBotTree tree = new EnhancedSWTBotTree((Tree)
bot.widget(matcher), matcher);
SWTBotMenuMenu menu = tree.contextMenu(0, 1); // select items 0 and 1
assertThat(menu.getItemCount(), is(0));
Classes used:
public class EnhancedSWTBotTree extends SWTBotTree {
// constructors omitted...
public SWTBotMenuMenu contextMenu(int... indices)
throws WidgetNotFoundException {
select(indices);
notify(SWT.MenuDetect);
return new SWTBotMenuMenu(syncExec(new Result<Menu>() {
public Menu run() {
return widget.getMenu();
}
}));
}
}
public class SWTBotMenuMenu extends AbstractSWTBot<Menu> {
// constructors omitted...
public int getItemCount() {
return syncExec(new IntResult() {
public Integer run() {
return widget.getItemCount();
}
});
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03292 seconds