Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Selecting context menu and sub-menu items
Selecting context menu and sub-menu items [message #17521] Thu, 22 January 2009 21:42 Go to next message
stephanl is currently offline stephanl
Messages: 13
Registered: July 2009
Junior Member
Greetings,

First off, I'd like to prefix my post with a big compliment to this
toolkit. I'm really excited about using it to automate my group's
Eclipse/WID plugins. We're currently at a PoC stage, after which - if
successful - I'm planning to adopt SWTBot for all Eclipse/WID test
automation efforts in my group.

In that context ... I'm attempting to select the 'New -> Class' context
(sub) menu item in the Package Explorer. Tried various approaches after
reading through any related posts on this group and the old group archive
on nabble.com. None of them work. The API suggests I should be able to
do this ... am I looking at a defect, or am I missing something? Any and
all thoughts would be highly appreciated.

Approach 1: fails with Could not find menu: Class

bot.view("Package Explorer").setFocus();
SWTBotTree tree = bot.tree(2);
tree.expandNode("jp-1");
SWTBotTreeItem treeNode = treeItem.getNode("src");
treeNode.setFocus();
treeNode.select().contextMenu("New").contextMenu("Class").click();


Approach 2: using modified sample code from EventContextMenuFinder in the
API doc. Fails with Could not find widget with text Class

bot.view("Package Explorer").setFocus();
SWTBotTree tree = bot.tree(2);
tree.expandNode("jp-1");
SWTBotTreeItem treeNode = treeItem.getNode("src");
treeNode.setFocus();
SWTBotMenu ctxMenu1 = treeNode.select().contextMenu("New");
ctxMenu1.click();
// curiously, isVisible is set to true after the next line executes,
whereas the context menu is not actually visible
boolean isVisible = ctxMenu1.isVisible();
EventContextMenuFinder eventContextMenuFinder = new
EventContextMenuFinder();
try {
eventContextMenuFinder.register();
ctxMenu1.setFocus(); // a popup menu appears below the button
SWTBotMenu menu = new SWTBotMenu(new Finder(new ControlFinder(),
eventContextMenuFinder), "Class");
menu.click();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
finally {
eventContextMenuFinder.unregister();
}
}
Re: Selecting context menu and sub-menu items [message #17536 is a reply to message #17521] Fri, 23 January 2009 02:34 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan Patel
Messages: 68
Registered: July 2009
Member
problem 1:
Notice that after "New" menu item is found, it calls contextMenu to find
"Class"...this does not exist since "New" menu item does not have
contextMenu.

Can you try below to see if it works...I can't get the env setup to run
eclipse
UI tests:

treeNode.select().contextMenu("New").menu("Class").click();

Also there are cases when context menu might be disposed so you might have
to find and click in on ui thread.



stephanl wrote:


> Approach 1: fails with Could not find menu: Class

> bot.view("Package Explorer").setFocus();
> SWTBotTree tree = bot.tree(2);
> tree.expandNode("jp-1");
> SWTBotTreeItem treeNode = treeItem.getNode("src");
> treeNode.setFocus();
> treeNode.select().contextMenu("New").contextMenu("Class").click();
Re: Selecting context menu and sub-menu items [message #17548 is a reply to message #17521] Fri, 23 January 2009 02:39 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
Hi Stephen,

The context menu not cascading was introduced as part of
https://bugs.eclipse.org/260010.

This bug is being tracked at https://bugs.eclipse.org/261360. Please add
yourself to CC to track this bug.

I'll be reverting the changes done as part of 260010, that'll fix
261360. There's a few comments on bug 261360 that talk about fixing this
the right way, which is the approach that I'll be taking.

On another note, you might find the PackageExplorer widget at
http://dev.eclipse.org/svnroot/technology/org.eclipse.swtbot /trunk/org.eclipse.swtbot.eclipse.finder.test/src/org/eclips e/swtbot/eclipse/finder/widgets/helpers/PackageExplorerView. java
useful, and any feedback on making this API would be welcome :)

-- Ketan

On 23/1/09 03:12, stephanl wrote:
> Greetings,
>
> First off, I'd like to prefix my post with a big compliment to this
> toolkit. I'm really excited about using it to automate my group's
> Eclipse/WID plugins. We're currently at a PoC stage, after which - if
> successful - I'm planning to adopt SWTBot for all Eclipse/WID test
> automation efforts in my group.
> In that context ... I'm attempting to select the 'New -> Class' context
> (sub) menu item in the Package Explorer. Tried various approaches after
> reading through any related posts on this group and the old group
> archive on nabble.com. None of them work. The API suggests I should be
> able to do this ... am I looking at a defect, or am I missing something?
> Any and all thoughts would be highly appreciated.
>
> Approach 1: fails with Could not find menu: Class
>
> bot.view("Package Explorer").setFocus();
> SWTBotTree tree = bot.tree(2);
> tree.expandNode("jp-1");
> SWTBotTreeItem treeNode = treeItem.getNode("src");
> treeNode.setFocus();
> treeNode.select().contextMenu("New").contextMenu("Class").click();
>
>
> Approach 2: using modified sample code from EventContextMenuFinder in
> the API doc. Fails with Could not find widget with text Class
>
> bot.view("Package Explorer").setFocus();
> SWTBotTree tree = bot.tree(2);
> tree.expandNode("jp-1");
> SWTBotTreeItem treeNode = treeItem.getNode("src");
> treeNode.setFocus();
> SWTBotMenu ctxMenu1 = treeNode.select().contextMenu("New");
> ctxMenu1.click();
> // curiously, isVisible is set to true after the next line executes,
> whereas the context menu is not actually visible boolean isVisible =
> ctxMenu1.isVisible();
> EventContextMenuFinder eventContextMenuFinder = new
> EventContextMenuFinder();
> try {
> eventContextMenuFinder.register();
> ctxMenu1.setFocus(); // a popup menu appears below the button
> SWTBotMenu menu = new SWTBotMenu(new Finder(new ControlFinder(),
> eventContextMenuFinder), "Class");
> menu.click();
> } catch (Exception e) {
> System.out.println(e.getMessage());
> }
> finally {
> eventContextMenuFinder.unregister();
> }
> }
>
Re: Selecting context menu and sub-menu items [message #17587 is a reply to message #17536] Fri, 23 January 2009 05:15 Go to previous messageGo to next message
stephanl is currently offline stephanl
Messages: 13
Registered: July 2009
Junior Member
Thanks for the suggestion. Changing the second call to contextMenu() to
be menu() results in
net.sf.swtbot.widgets.WidgetNotFoundException: The widget was null.

When watching the test execute, should I be seeing the 'New' context menu
become visible when executing the suggested line of code
treeNode.select().contextMenu("New").menu("Class").click();
?

Thanks,

- Stephan
Re: Selecting context menu and sub-menu items [message #17599 is a reply to message #17548] Fri, 23 January 2009 05:21 Go to previous message
stephanl is currently offline stephanl
Messages: 13
Registered: July 2009
Junior Member
Thanks Ketan. The view I'm really concerned with is actually not the
Package Explorer but a custom view on my product. I just chose the
Package Explorer for this posting as it exhibits similar behavior when
attempting to bring up sub-context menus. FWIW, the code we are using to
populate the context menus is below. Does that yield any suggestions on
how to use the existing SWTBot API to access the sub-menu item? I haven't
dug into the Eclipse src to see how the Package Explorer tree view's
context menu is populated, but I'd expect it to be along the same lines,
as that's pretty standard stuff.

Thanks much!

- Stephan

MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager menuManager) {
menuManager.add(new
GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

_projectActions.fillProjectMenu(CSNamespaceAwareViewPart.thi s,
menuManager);
}
});

Menu m = menuManager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(m);

getSite().registerContextMenu(menuManager, viewer);
Previous Topic:press enter in a table
Next Topic:Finding n-th widget of any type
Goto Forum:
  


Current Time: Fri Oct 24 18:06:11 GMT 2014

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

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