Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to access nested context menus?
How to access nested context menus? [message #34302] Sun, 03 May 2009 06:48 Go to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
The following context-menu code works:

SWTBotTreeItem myprojtree = getProjectTree();
myprojtree.contextMenu("Import...").click();

The following code does NOT work:
myprojtree.contextMenu("option1").contextMenu("option2").click();

I get the following exception when I try it:
org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion: The
widget {(an instance of org.eclipse.swt.widgets.MenuItem and with mnemonic
'option1')} was disposed.

I also tried:
myprojtree.contextMenu("option1").menu("option2").click();

and just:
myprojtree.contextMenu("option1").click();

Nested menus do work for regular menus, because this code works:

bot.menu("Option1").menu("Option2").menu("Option3").click();

...Am I overlooking anything? Anyone experience something similar?

Thanks in advance,
Steve
Re: How to access nested context menus? [message #34402 is a reply to message #34302] Mon, 04 May 2009 11:49 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe GrawFriend
Messages: 24
Registered: July 2009
Junior Member
I had the same problem, that second-level context-menu entries were not
found properly in the current SWTBot-Version. I wrote the following
helper function
for my extended version of the SWTEclipseBot-Class

/**
* return the sub menu with the specified item text from the parent menu
* @param parentMenu - the parent menue
* @param itemText - the text for the sub menu entry
* @return - the sub menu item corresponding to itemText
* @throws WidgetNotFoundException - if no sub menu item has been found
*/

public SWTBotMenu getSubMenuItem(final SWTBotMenu parentMenu, final String
itemText) throws WidgetNotFoundException
{
MenuItem menuItem = UIThreadRunnable.syncExec(new
WidgetResult<MenuItem>()
{
public MenuItem run()
{
Menu bar = parentMenu.widget.getMenu();

if (bar !=null)
{
for (MenuItem item : bar.getItems())
{
if (item.getText().equals(itemText))
{
return item;
}
}
}

return null;
}
});

if(menuItem==null)
{
throw new WidgetNotFoundException("MenuItem \"" + itemText +"\" not
found.");
}
else
{
return new SWTBotMenu(menuItem);
}
}

And than use the helper function in the following way

getSubMenuItem(myprojtree.contextMenu("option1"), "option2").click()

Kay
Re: How to access nested context menus? [message #34469 is a reply to message #34402] Mon, 04 May 2009 18:10 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
Kay,

Thanks very much for this code snippet. I tried it out and it compiled
okay, but it's still not recognizing option1. i.e.

The widget {(an instance of org.eclipse.swt.widgets.MenuItem and with
mnemonic 'option1')} was disposed.

so I tried breaking up your one-liner like this:

SWTBotTreeItem myprojtree = getProjectTree();
bot.sleep(1000);
---->SWTBotMenu firstcontextMenu = myprojtree.contextMenu("option1");
bot.sleep(1000);
getSubMenuItem(firstcontextMenu, "option2").click();

It's failing where I put the ---->. If I change the code there to try to
look for a contextMenu item with no subtree, then that line can pass
successfully.

Any ideas?

Thanks!

-- Steve
Re: How to access nested context menus? [message #34537 is a reply to message #34469] Mon, 04 May 2009 22:42 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan PatelFriend
Messages: 68
Registered: July 2009
Member
This is known issue with the way eclipse creates context menu and the way
swtbot finds them.

Being said that, SWTBot does a recursive search for menus so if you need
to find options2 which is inside sub menu option1, you can just directly
search for option2. This should get you the menu item you are looking
for. Not the best/most predictable way, but works for most things.

myprojtree.contextMenu("option2").click();
Re: How to access nested context menus? [message #34569 is a reply to message #34537] Tue, 05 May 2009 02:20 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
Thanks for the suggestion, I tried this,
i.e. just calling option2 first without referencing option1:

myprojtree.contextMenu("option2").click();

And I get the following exception:

org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after:
10000 ms.: Could not find context menu with text: option2
at
org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBot Factory.java:431)

...Still don't have a solution for this unfortunately

Any more ideas?

Thank you,

Steve
Re: How to access nested context menus? [message #34603 is a reply to message #34469] Tue, 05 May 2009 07:36 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe GrawFriend
Messages: 24
Registered: July 2009
Junior Member
As already said, it's an issue with the way context menus are
reconstructed in eclipse. I also had the widget disposed error. I solved
it somehow by always calling expand and select when possible, e.g.

SWTBotTreeItem parentItem =
bot.tree().getTreeItem("parent").select().expand();

SWTBotTreeItem childItem = parentItem.getNode("child").select();

Also no caching of the tree or treeitem alyways get it new from the bot.

The error indicates that SWTBot somehow finds the old and still disposed
version of the menu.

Also make sure that no processes are still running in the background of
your application which may prevent the tree from updating. Maybe an
appropriate wait condition before accessing the tree could be necessary as
well.

Kay
Re: How to access nested context menus? [message #34671 is a reply to message #34569] Wed, 06 May 2009 23:04 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan PatelFriend
Messages: 68
Registered: July 2009
Member
Which SWTBot version are you using?
Re: How to access nested context menus? [message #34903 is a reply to message #34302] Thu, 07 May 2009 22:21 Go to previous messageGo to next message
Derek  is currently offline Derek Friend
Messages: 30
Registered: July 2009
Member
So in the statement "SWTBotTreeItem myprojtree = getProjectTree();"

I see that getProjectTree() must be your own method you have created.

Slowly I'm getting the hang of how to get around with SWTBot, but I read
this post about context menu's, and got distracted trying to figure out
what I'm doing.

I understand a statement like "SWTBotTree pSelectionTree = bot.tree();"

I guess I'm a little confused what to put in place for "getProjectTree()"
like above.

Any help would be greatly appreciated.

Thanks :)

-
Derek



Steven Chamberlin wrote:

> The following context-menu code works:

> SWTBotTreeItem myprojtree = getProjectTree();
> myprojtree.contextMenu("Import...").click();

> The following code does NOT work:
> myprojtree.contextMenu("option1").contextMenu("option2").click();

> I get the following exception when I try it:
> org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion: The
> widget {(an instance of org.eclipse.swt.widgets.MenuItem and with mnemonic
> 'option1')} was disposed.

> I also tried:
> myprojtree.contextMenu("option1").menu("option2").click();

> and just:
> myprojtree.contextMenu("option1").click();

> Nested menus do work for regular menus, because this code works:

> bot.menu("Option1").menu("Option2").menu("Option3").click();

> ...Am I overlooking anything? Anyone experience something similar?

> Thanks in advance,
> Steve
Re: How to access nested context menus? [message #34928 is a reply to message #34903] Fri, 08 May 2009 02:53 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Derek wrote:
> I guess I'm a little confused what to put in place for "getProjectTree()"
> like above.

Replied here:
http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.swtbot /msg00564.html

-- Ketan
Re: How to access nested context menus? [message #35140 is a reply to message #34928] Fri, 08 May 2009 19:34 Go to previous messageGo to next message
Derek  is currently offline Derek Friend
Messages: 30
Registered: July 2009
Member
Ketan Padegaonkar wrote:

> Derek wrote:
>> I guess I'm a little confused what to put in place for "getProjectTree()"
>> like above.

> Replied here:
> http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.swtbot /msg00564.html

> -- Ketan


Thanks Ketan :)

I'm a tester with little java experience, so there's a lot to learn on my
end.

So far so good!


-Derek
Re: How to access nested context menus? [message #35245 is a reply to message #35140] Sat, 09 May 2009 07:45 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 9/5/09 01:04, Derek wrote:
> Thanks Ketan :)
>
> I'm a tester with little java experience, so there's a lot to learn on
> my end.

SWTBot was written in mind keeping the target audience and pairing with
a tester. So I understand what you mean there :)

-- Ketan
Re: How to access nested context menus? [message #36177 is a reply to message #34603] Fri, 22 May 2009 00:13 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
Hi Kay,

Sorry for the delay in responding; I'm revisiting the issue now ... I'm a
little confused -- In the code example that you just provided, why are you
not referencing a context menu? ... Original issue I had was accessing
nested context menus.

And what about your getSubMenuItem method?

Thanks,

Steve
Re: How to access nested context menus? [message #36211 is a reply to message #36177] Fri, 22 May 2009 12:47 Go to previous messageGo to next message
Kay-Uwe Graw is currently offline Kay-Uwe GrawFriend
Messages: 24
Registered: July 2009
Junior Member
"Before" accessing the context menu of a tree item you could try to
explicitely select and expand all tree items in your tree navigation path
as well. For accessing the 2ndlevel submenu you could try using the method
I provided.

Kay
Re: How to access nested context menus? [message #502066 is a reply to message #36211] Sat, 05 December 2009 02:12 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
I'm seeing this issue still. I've tried it on the latest version available of SWT-Bot (433). This time there is no tree involved. It's just a context menu of a context menu that I am trying to access by right-clicking from the java editor. Again I get the widget disposed error. Here's the code:

bot.activeEditor().toTextEditor().selectRange(8,25,0);
getSubMenuItem(bot.activeEditor().toTextEditor().contextMenu ( "firstmenu"), "second menu").click();

Here's the error:

org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion: The widget {(an instance of org.eclipse.swt.widgets.MenuItem and with mnemonic 'option1')} was disposed.

Is this a known issue and is there any workaround?

Thanks!


Re: How to access nested context menus? [message #502067 is a reply to message #502066] Sat, 05 December 2009 02:17 Go to previous messageGo to next message
Steven Chamberlin is currently offline Steven ChamberlinFriend
Messages: 30
Registered: July 2009
Member
Sorry, that was with Kay's code that doesn't work for me either...

Without Kay's code, it's:

bot.activeEditor().toTextEditor().contextMenu("option1").contextMenu( "option2").click()

Also tried:

bot.activeEditor().toTextEditor().contextMenu("option1").menu( "option2").click()

and:

bot.activeEditor().toTextEditor().contextMenu("option2").click()

each time, the same "widget disposed" exception ...

Thanks
Re: How to access nested context menus? [message #507203 is a reply to message #34302] Tue, 12 January 2010 13:43 Go to previous messageGo to next message
loother  is currently offline loother Friend
Messages: 3
Registered: January 2010
Junior Member
I would be really interested in a solution as well, as my RCP application uses cascading context menus to a great extend.
Is there a road map when there is a release fixing this issue once and for all?
Thanks
loother
Re: How to access nested context menus? [message #507241 is a reply to message #507203] Tue, 12 January 2010 15:24 Go to previous message
loother  is currently offline loother Friend
Messages: 3
Registered: January 2010
Junior Member
Finally found some work around which solved the problem for me.
Would be nice to be integrated in SWTBot any day Wink
http://www.eclipse.org/forums/index.php?t=msg&th=11863&a mp;start=0&
Previous Topic:releaseDate
Next Topic:How to get the TextHover control of bot.activeEditor().getSelection() in SWTBot
Goto Forum:
  


Current Time: Thu Mar 28 17:15:50 GMT 2024

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

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

Back to the top