Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Selecting "Help -> About Eclipse" gives WidgetNotFoundException
Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #651033] Thu, 27 January 2011 14:22 Go to next message
Aivar Annamaa is currently offline Aivar AnnamaaFriend
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 #651063 is a reply to message #651033] Thu, 27 January 2011 15:43 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hi

Are you sureyour application window is on the top-level of your Window System and hasthe focus? It is mandatory for SWTBot tests to run,
--
Mickael Istria -- BonitaSoft S.A.
http://www.bonitasoft.com/products/BPM_download.php
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #651087 is a reply to message #651063] Thu, 27 January 2011 17:25 Go to previous messageGo to next message
Aivar Annamaa is currently offline Aivar AnnamaaFriend
Messages: 33
Registered: July 2009
Member
I tried again and checked that window is in focus. I still get always same result -- some menu items are always "clickable" and some give always error. Seems that error never comes from accessing the topmost menu.

SWTBotMenu m1 = bot.menu("Help");
SWTBotMenu m2 = m1.menu("About Eclipse"); /// this line gives error


Aivar
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #671846 is a reply to message #651033] Thu, 19 May 2011 07:26 Go to previous messageGo to next message
Joanna  is currently offline Joanna Friend
Messages: 12
Registered: May 2011
Junior Member
I got the same problem, does anyone know why it doesn't work to lanuch clean project scenario?

[Updated on: Thu, 19 May 2011 07:26]

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 Go to previous messageGo to next message
Benjamin Ratiarisolo is currently offline Benjamin RatiarisoloFriend
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 #720315 is a reply to message #687941] Tue, 30 August 2011 11:18 Go to previous messageGo to next message
Mladen Mijatovic is currently offline Mladen MijatovicFriend
Messages: 7
Registered: August 2011
Junior Member
Try this
bot.menu("Help").menu("&About Eclipse").click();

It worked for my eclipse helios and it is because mnemonic "A" in that menu item. Hope this will help.

[Updated on: Tue, 30 August 2011 11:18]

Report message to a moderator

Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #722194 is a reply to message #720315] Mon, 05 September 2011 02:37 Go to previous messageGo to next message
Joanna  is currently offline Joanna Friend
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?
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #722343 is a reply to message #722194] Mon, 05 September 2011 12:56 Go to previous messageGo to next message
Benjamin Ratiarisolo is currently offline Benjamin RatiarisoloFriend
Messages: 16
Registered: January 2010
Location: Paris, France
Junior Member
Joanna,

The below code seems to work fine for me:
    SWTBot bot = ...;
    SWTBotShell shell = bot .shells()[0].activate();
    SWTBotMenu menu = new SWTBotMenu(WorkbenchMenuHelper.getContextMenu(shell,
        "Project", "Clean..."));
    menu.click();
    swtBot.shell("Clean").activate();
    swtBot.button().click();
  }


Cheers,


--
Benjamin Ratiarisolo
IBM ODM Decision Server Rules - Software Developer
IBM Software - France Lab
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #722511 is a reply to message #722343] Tue, 06 September 2011 02:28 Go to previous messageGo to next message
Joanna  is currently offline Joanna Friend
Messages: 12
Registered: May 2011
Junior Member
Hi, Benjamin
Thank you so much for your kindly help, it works well with your way, and for my previous code, it can work after referring to your method like this:
SWTBotShell shell = bot .shells()[0].activate();
ContextMenuHelper.clickContextMenu(shell,"Project", "Clean...");
bot.shell("Clean").activate();
bot.button().click();

SWTBotShell shell = bot .shells()[0].activate(); this means activate current shell?
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #722558 is a reply to message #722511] Tue, 06 September 2011 07:47 Go to previous messageGo to next message
Benjamin Ratiarisolo is currently offline Benjamin RatiarisoloFriend
Messages: 16
Registered: January 2010
Location: Paris, France
Junior Member
Hi Joanna,
SWTBotShell shell = bot .shells()[0].activate();

This code actually make sure that the eclipse workbench shell is activated. It may not be the current shell: for instance if you have multiple dialog/wizard panels open you can have something like that:

  • bot .shells()[0]: the eclipse workbench shell
  • bot .shells()[1]: your wizard shell
  • bot .shells()[2]: your error message dialog

Note that some of the shells returned by
bot .shells();
may not actually be visible, thus the returned array may have more elements than you expect.



--
Benjamin Ratiarisolo
IBM ODM Decision Server Rules - Software Developer
IBM Software - France Lab
Re: Selecting "Help -> About Eclipse" gives WidgetNotFoundException [message #723219 is a reply to message #722558] Thu, 08 September 2011 05:07 Go to previous message
Joanna  is currently offline Joanna Friend
Messages: 12
Registered: May 2011
Junior Member
Thanks Benjamin~ Smile
Previous Topic:Problem with RadioGroupFieldEditor
Next Topic:performing doubleclick on a tree item
Goto Forum:
  


Current Time: Fri Apr 19 02:53:45 GMT 2024

Powered by FUDForum. Page generated in 0.03354 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top