Can't access main "Project" menu after selecting project in view [message #525521] |
Tue, 06 April 2010 14:10  |
Eclipse User |
|
|
|
I am trying to write a test case that selects a project in the C/C++ Project Explorer view, then selects the main "Project" pull-down menu so I can select "Properties..." for the selected project.
I tried using the following code which creates a C/C++ Autotools project and then tries to set some property fields for the project.
private static SWTWorkbenchBot bot;
@BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTWorkbenchBot();
bot.viewByTitle("Welcome").close();
bot.menu("Window").menu("Preferences").click();
SWTBotShell shell = bot.shell("Preferences");
shell.activate();
bot.tree().expandNode("General").select("Workspace");
SWTBotCheckBox buildAuto = bot.checkBox("Build automatically");
if (buildAuto != null && buildAuto.isChecked())
buildAuto.click();
bot.button("Apply").click();
bot.tree().expandNode("General").select("Perspectives");
SWTBotRadio radio = bot.radio("Always open");
if (radio != null && !radio.isSelected())
radio.click();
bot.button("OK").click();
}
@Test
public void canCreateANewAutotoolsProject() throws Exception {
bot.menu("File").menu("New").menu("Project...").click();
SWTBotShell shell = bot.shell("New Project");
shell.activate();
bot.tree().expandNode("C/C++").select("C Project");
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText("GnuProject0");
bot.tree().expandNode("GNU Autotools").select("Hello World ANSI C Autotools Project");
bot.button("Finish").click();
}
@Test
public void canSetConfigParm() throws Exception {
SWTBotView view = bot.viewByTitle("Project Explorer");
view.bot().tree().select("GnuProject0");
bot.menu("Project").menu("Properties...").click();
}
The test that creates the project works fine and the first two lines of the canSetConfigParm() test also work fine and do in fact select the project in question in the "Project Explorer".
The problem is that when I attempt to access the "Project" menu after selecting the project, I get an exception saying the widget is not found. If I access the "Project" menu from bot prior to selecting the project, that works fine. If I save that menu and try to later access the "Properties..." menu after the project selection, again I get the widget not found exception.
I even tried resetting the bot variable with a new SWTBotWorkbench, but that didn't work either.
Any ideas on why this is failing?
I am using junit4, eclipse 3.5.1, CDT 6.0.1, and SWTBot 2.0.0.512-dev-e35
|
|
|
|
|
|
|
|
|
Re: Can't access main "Project" menu after selecting project in view [message #525712 is a reply to message #525559] |
Wed, 07 April 2010 10:23   |
Eclipse User |
|
|
|
Jeff Johnston wrote:
> Pascal G wrote on Tue, 06 April 2010 12:24
>> Jeff Johnston wrote:
>> > Thanks for the tip Pascal.
>> > I tried changing the test to just get the menu for "Project" from
>> bot > and then try a menu.click(). When I run this (as opposed to
>> debug), I > get a dialog that pops up that says: "The chosen operation
>> is not enabled".
>> >
>> something like: bot.menu("Project").click(); ??? I think that's what
>> is causing your pop-up dialog, but I'm not sure. Menu management in
>> SWTBot is a bit messy, there were various bug report surrounding this
>> if I remember well. Or it was context menus? Anyways, from my
>> experience, you should only do action on leaf menu, such as the
>> Properties item, and not the Project one.
>>
>> Base line: you should really do
>> bot.menu("Project").menu("Properties").click();
>
>
> I tried this first. It gives me the WidgetNotFound exception yet
> again. :(
> I guess I should open a bug.
Hmmmmm.... ding! Found it! I tried finding this menu myself and here is
what I get: it finds the wrong "Project" menu item. It finds the one
that is located in Search -> Text . Clearly not the behavior I would
expect: it does a recursive search using a depth-first approach. I would
of done this without recursion, or if recursion is absolutely necessary
I would prefer a breadth-first approach... To get the one you're
after, do this instead:
bot.menu("Project", 1); // Get the second Project menu item...
On a side-note, you could also do bot.menu("Properties", 1) instead of
the chaining. Note that again I had to specify index 1, because the
first "Properties" MenuItem is located under the File menu.
I'm going to open a bug on this issue, probably to add a new API to
specify if the search should be recursive or not:
bot.menu("Text", recursive)
bot.menu("Text", index, recursive);
I would like it to not be recursive by default, but that would probably
break a lot of people's test since they may rely on this behavior...
We could also discuss to fact to use depth-first vs breadth-first.
Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/
*Because performance matters.*
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06024 seconds