Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #651033] |
Thu, 27 January 2011 14:22 |
Aivar Annamaa Messages: 33 Registered: July 2009 |
Member |
|
|
Hi!
I'm trying to get started with SWTBot and followed this guide: http://swtbot.com/user-guide/, but I was using Eclipse IDE as the application to test.
I chose to select "Help" -> "About Eclipse" menu item:
@RunWith(SWTBotJunit4ClassRunner.class)
public class SampleTest {
private SWTWorkbenchBot bot;
@Test
public void selectSomeMenus() throws Exception {
SWTBotMenu m1 = bot.menu("Help");
SWTBotMenu m2 = m1.menu("About Eclipse");
m2.click();
Thread.sleep(5000);
}
@Before
public void setup() {
bot = new SWTWorkbenchBot();
}
}
but got back WidgetNotFoundException.
I was about to give up but tried with other menu items (eg. "Help -> Welcome") and to my surprise most of them worked.
Unfortunately, one that I'm interested of ("Project -> Clean...") does not work.
Why are "Help -> About Eclipse" or "Project -> Clean..." special? How can I select them?
I have 32bit Eclipse Helios on 64bit Win7. SWTBot is 2.0.2
Aivar
[Updated on: Thu, 27 January 2011 14:23] Report message to a moderator
|
|
|
|
|
|
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #687941 is a reply to message #671846] |
Thu, 23 June 2011 14:53 |
Benjamin Ratiarisolo Messages: 16 Registered: January 2010 Location: Paris, France |
Junior Member |
|
|
Aivar,
Did you check the syntax of the menu item's label you are trying to activate. In my Helios IDE for instance, in the "Help" workbench menu, there isn't any "About Eclipse" menu item but there is one "About Eclipse SDK". Sorry if this seems like a lame answer, but I have faced this kind of label syntax errors quite a few times.
Regarding the 'Project -> Clean' scenario submitted by Joanna, I was quite surprised to face the very same issue. I investigated a little bit and finally decided to refactor Stefan Seelmanns' ContextMenuHelper contribution (usually pops-up in lots of context menu related issues in this forum) into a WorkbenchMenuHelper class (note that I had very little to-do to adapt his code to the workbench menu-bar items scenario).
It seems to work fine for me.
/**
* Clicks the context menu matching the text.
*
* @param text
* the text on the context menu.
* @throws WidgetNotFoundException
* if the widget is not found.
*/
public static void clickContextMenu(
final SWTBotShell shell, final String... texts) {
// fetch
final MenuItem menuItem = getContextMenu(shell, texts);
// click
click(menuItem);
// hide
UIThreadRunnable.syncExec(new VoidResult() {
public void run() {
hide(menuItem.getParent());
}
});
}
private static MenuItem getContextMenu(
final SWTBotShell shell, final String... texts) {
final MenuItem menuItem = getContextMenuImpl(shell, texts);
if (menuItem == null) {
throw new WidgetNotFoundException("Could not find menu: " + computeMenuTrace(texts));
}
return menuItem;
}
private static MenuItem getContextMenuImpl(
final SWTBotShell shell, final String... texts) {
traceMenu(texts);
// show
final MenuItem menuItem = UIThreadRunnable
.syncExec(new WidgetResult<MenuItem>() {
public MenuItem run() {
MenuItem menuItem = null;
Menu menu = shell.widget.getMenuBar();
for (String text : texts) {
@SuppressWarnings("unchecked")
Matcher<?> matcher = allOf(instanceOf(MenuItem.class),
withMnemonic(text));
menuItem = show(menu, matcher);
if (menuItem != null) {
menu = menuItem.getMenu();
} else {
hide(menu);
break;
}
}
return menuItem;
}
});
return menuItem;
}
--
Benjamin Ratiarisolo
IBM ODM Decision Server Rules - Software Developer
IBM Software - France Lab
|
|
|
|
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #722194 is a reply to message #720315] |
Mon, 05 September 2011 02:37 |
Joanna Messages: 12 Registered: May 2011 |
Junior Member |
|
|
Hi, Mladen:
Thanks,i tried bot.menu("Help").menu("&About Eclipse").click(); for Help->About Eclipse, it works fine.
Hi, Benjamin:
I tried your suggestion for Project->Clean... scenario, but it seems not work well for me, i am not sure whether there is something wrong when i use it like:
SWTBotShell shell = bot.shell("Clean");
String[] paths={"Project","Clean..."};
clickContextMenu(shell,paths);
Benjamin, could you show me how you use it?
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05184 seconds