Selecting context menu and sub-menu items [message #17521] |
Thu, 22 January 2009 16:42  |
Eclipse User |
|
|
|
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 #17548 is a reply to message #17521] |
Thu, 22 January 2009 21:39   |
Eclipse User |
|
|
|
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 #17599 is a reply to message #17548] |
Fri, 23 January 2009 00:21  |
Eclipse User |
|
|
|
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);
|
|
|
Powered by
FUDForum. Page generated in 0.04140 seconds