aphex
aphex

Reputation: 3412

How can I navigate the view menu using SWTBot?

Is it possible to the view menu using SWTBot? An example of an view menu is the one of Problems view (see screenshot). For example how can I change the grouping to Type using SWTBot? I've tried:

for (final SWTBotViewMenu a : this.bot.viewById("org.eclipse.ui.views.ProblemView").menus()) {
        System.out.println(a.getText());
    }
this.bot.viewById("org.eclipse.ui.views.ProblemView").toolbarDropDownButton("View Menu").menuItem("Group By").menu("None").click();

The for loop doesn't give anything at all, and the second one gives an error, that the "View Menu" cannot be found. I have no idea how to navigate this menu ?

screenshot

Upvotes: 3

Views: 2046

Answers (4)

cbd
cbd

Reputation: 646

I think you can try with:

theView.viewMenu().menu("Group By").menu("Type").click();

I am able to do the same thing with SWTBot 2.8.0 for Project Explorer view

Upvotes: 0

selestor
selestor

Reputation: 11

try this:

SWTBotView view = bot.viewByTitle("MyView");
    view.show();
    view.viewMenu().menu("MyContextOption").click();

Upvotes: 1

The problem come from the fact that this menu is populated with dynamic entries. SWTBot doesn't handle this kind of entry. See ViewMenuFinder.getMenuItem(). Different kind of IContributionItem are handled but in the situation of the Problems View, the items are of type DynamicMenuContributionItem.

Upvotes: 0

Cpt. Senkfuss
Cpt. Senkfuss

Reputation: 1384

It's probably too late for the OP, but here goes:

For some reason, the straight-forward way to activate a view like "Problems" doesn't work. You can use this workaround:

this.bot.menu("Window").menu("Show View").menu("Problems").click();
SWTBotView problemsView = bot.activeView();

This will only help with the first part, though. You now have access to the toolbar buttons via:

List<SWTBotToolbarButton> toolbarButtons = problemsView.getToolbarButtons();

For the Problems view, this gives you access to the "Focus on active task" button, but the three buttons in the cornern, "view menu", "minimize" and "maximize" do not appear in this list. Unfortunately, I have no solution for this as of now.

[Edit]

You can bring up the view menu like that:

this.bot.menu("Window").menu("Navigation").menu("Show View Menu").click();

but I don't know how to select an item from it afterwards. Maybe someone else will know...

Upvotes: 2

Related Questions