Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Can't access main "Project" menu after selecting project in view
Can't access main "Project" menu after selecting project in view [message #525521] Tue, 06 April 2010 18:10 Go to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
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 #525524 is a reply to message #525521] Tue, 06 April 2010 18:40 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Jeff Johnston wrote:
> @Test
> public void canSetConfigParm() throws Exception {
> SWTBotView view = bot.viewByTitle("Project Explorer");
> view.bot().tree().select("GnuProject0");
> bot.menu("Project").menu("Properties...").click();
> }
>

<snip>

> 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
>

should be bot.menu("Project").menu("Properties").click(); There is no
.... on my version of eclipse (3.5.1, Linux).

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Can't access main "Project" menu after selecting project in view [message #525535 is a reply to message #525524] Tue, 06 April 2010 19:26 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Well, that will at least help me with the next step; however, it is not able to find the "Project" menu before I reference "Properties". When I debug and step into the last line, I get a WidgetNotFound exception on the first menu reference to "Project".
Re: Can't access main "Project" menu after selecting project in view [message #525539 is a reply to message #525535] Tue, 06 April 2010 19:43 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Jeff Johnston wrote:
> When I debug and step into the last line, I get a WidgetNotFound exception on
> the first menu reference to "Project".

Watch out, it's very tricky to debug a test under SWTBot. You probably
get the WNF because it's your running Eclipse that has focus, and not
your application, thus SWTBot can't find the item. See this FAQ entry
[1] for "more" details.

Hope this helps

[1]
http://wiki.eclipse.org/SWTBot/Troubleshooting#WidgetNotFoun dException_when_stepping_through_SWTBot_test_in_Eclipse_debu gger
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Can't access main "Project" menu after selecting project in view [message #525546 is a reply to message #525539] Tue, 06 April 2010 20:14 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
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".

I notice that the main Eclipse window is disabled (i.e. the top window titled: C/C++ - Eclipse Platform is grey instead of blue. If I click on the title bar I am able to click on the Project menu item manually.

Is there some way I need to reactivate the main window after delving into a view?
Re: Can't access main "Project" menu after selecting project in view [message #525554 is a reply to message #525546] Tue, 06 April 2010 16:24 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
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 notice that the main Eclipse window is disabled (i.e. the top window
> titled: C/C++ - Eclipse Platform is grey instead of blue. If I click on
> the title bar I am able to click on the Project menu item manually.
>
> Is there some way I need to reactivate the main window after delving
> into a view?

bot.shell("Shell name").activate(); ? I don't recommend doing this
though, you probably have a problem elsewhere. Probably that the pop-up
dialog caused this. You don't need to reactivate the main window (shell)
after doing some action in it...

Hope this helps
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Can't access main "Project" menu after selecting project in view [message #525559 is a reply to message #525554] Tue, 06 April 2010 21:27 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
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. Sad

I guess I should open a bug.
Re: Can't access main "Project" menu after selecting project in view [message #525712 is a reply to message #525559] Wed, 07 April 2010 14:23 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
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.*
Re: Can't access main "Project" menu after selecting project in view [message #525738 is a reply to message #525712] Wed, 07 April 2010 16:03 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Thanks Pascal. I agree with you. It is not intuitive to recursively search down for a menu though you may want to do this in some instances..

As an end-user, you click "Projects", then "Properties". There should be some way of specifying this in the API. Otherwise, tests will start to fail when new menu items are added to submenus which can easily happen when optional plug-ins are installed/uninstalled.
Re: Can't access main "Project" menu after selecting project in view [message #759529 is a reply to message #525712] Tue, 29 November 2011 00:50 Go to previous message
Jan Arciuchiewicz is currently offline Jan ArciuchiewiczFriend
Messages: 11
Registered: November 2009
Junior Member
Thanks for this comment. I had the same problem with "Project" menu. Tried to debug and saw that its menu child is null.
So at the end had to switch on/off "Build Automatically" from API. Took me the half day to investigate, and finally found this comment, and everything is clear now. Thanks Smile
Previous Topic:Need consolidated test output (logger message+screenshots+exceptions)
Next Topic:SWTBot shells number grow after each test
Goto Forum:
  


Current Time: Wed Apr 24 19:45:35 GMT 2024

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

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

Back to the top