Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Getting the current widget
Getting the current widget [message #522978] Wed, 24 March 2010 12:36 Go to next message
Urtzi Odriozola is currently offline Urtzi Odriozola
Messages: 27
Registered: March 2010
Junior Member
Hi!

The problem I face is that I wanna get a current widget I'm using to then insert some asserts using those widget but I don't know how to do it. I wanna get AbstractSWTbot type widgets.

This is one of my tests:
@Test
public void changePreferences() throws Exception {
	bot.menu("Window").click();
	bot.menu("Preferences").click();
	bot.tree().expandNode("Ant").select("Editor");
	bot.tabItem("Syntax").activate();
	bot.tabItem("Problems").activate();
	bot.comboBoxWithLabel("Task configuration:").setSelection("Error");
	bot.tree().expandNode("Ant").expandNode("Editor").select("Templates");
	bot.tableWithLabel("Create, edit or remove templates:").getTableItem("comment").toggleCheck();
	bot.tree().expandNode("Java").expandNode("Editor").select("Syntax Coloring");
	bot.treeWithLabel("Element:").select("Java");
}

So, any idea of how can I get the different widgets, so I would be able to put, for example, assertNotVisible(AbstractSWTBot<? extends Widget>) ?
Re: Getting the current widget [message #523019 is a reply to message #522978] Wed, 24 March 2010 14:48 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Urtzi Odriozola wrote:
> Hi!
>
> The problem I face is that I wanna get a current widget I'm using to
> then insert some asserts using those widget but I don't know how to do
> it. I wanna get AbstractSWTbot type widgets.
>
> This is one of my tests:
>
> @Test
> public void changePreferences() throws Exception {
> bot.menu("Window").click();
> bot.menu("Preferences").click();
> bot.tree().expandNode("Ant").select("Editor");
> bot.tabItem("Syntax").activate();
> bot.tabItem("Problems").activate();
> bot.comboBoxWithLabel("Task configuration:").setSelection("Error");
> bot.tree().expandNode("Ant").expandNode("Editor").select( "Templates");
> bot.tableWithLabel("Create, edit or remove
> templates:").getTableItem("comment").toggleCheck();
> bot.tree().expandNode("Java").expandNode("Editor").select( "Syntax
> Coloring");
> bot.treeWithLabel("Element:").select("Java");
> }
>
> So, any idea of how can I get the different widgets, so I would be able
> to put, for example, assertNotVisible(AbstractSWTBot<? extends Widget>) ?

All the bot.something methods return a value (hell, that's why you can
chain those method calls...), which you can use in your assert. For example:

SWTBotTree tree = bot.tree();
assertVisible(tree);
tree.expandNode("Java").expandNode("Editor").select("Syntax Coloring");

Also, most of the methods in SWTBot return a value: often it's the
current widget, sometimes it's a child of the current widget. Refer to
the javadoc of the methods to be sure. You could do this if you wanted:

SWTBotTree tree = bot.tree();
assertVisible(tree);
SWTBotTreeItem item = tree.expandNode("Java"); // Child of tree
assertVisible(item);
SWTBotTreeItem item2 = item.expandNode("Editor"); // Child of item
assertVisible(item2);
item2.select("Syntax Coloring");

Hope this helps.

ps: not to be rude or anything, but your question is a trivial Java
matter. Please learn some Java beforehand, or using SWTBot will be like
driving blindfolded...
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Getting the current widget [message #523134 is a reply to message #522978] Thu, 25 March 2010 05:35 Go to previous messageGo to next message
Urtzi Odriozola is currently offline Urtzi Odriozola
Messages: 27
Registered: March 2010
Junior Member
Thank you for the replay!!

But that is not the response I'm finding. I know that those methods return a value which I can use later in asserts or whatever.

Maybe I didn't explain very clear my real problem (probably because my English isn't very enough...). But the point is that the example I put there, is a generated code and what I want to do is somehow keep the current widget (regardless of the type) for then use in just one statement.

Because if I have to create a variable, for each sentence I create (that surely they aren't going to use), the only thing I'm doing is waste the resources and mess the code...

I tried to do what you said, but sometimes, some generated sentences doesn't return anything (for example if I use setSelection() method at the end). So, for example, in my generic template (the template which creates statements) I can't put a rule to saved all the widgets in the same variable.

AbstractSWTBot current = bot.comboBoxWithLabel("Task configuration:").setSelection("Error");
assertVisible(current);

So, what I want to do is to find the best solution to keep clean the code and in the same time save resources. Maybe the solution is to change the workflow of the generator... but that's another question...

Thank you again for the response!!

[Updated on: Thu, 25 March 2010 05:40]

Report message to a moderator

Re: Getting the current widget [message #523182 is a reply to message #523134] Thu, 25 March 2010 09:02 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Urtzi Odriozola wrote:
> Thank you for the replay!!
>
> But that is not the response I'm finding. I know that those methods
> return a value which I can use later in asserts or whatever.
>
> Maybe I didn't explain very clear my real problem (probably because my
> English isn't very enough...). But the point is that the example I put
> there, is a generated code and what I want to do is somehow keep the
> current widget (regardless of the type) for then use in just one statement.
>
> Because if I have to create a variable, for each sentence I create (that
> surely they aren't going to use), the only thing I'm doing is waste the
> resources and mess the code...
>
> I tried to do what you said, but sometimes, some generated sentences
> doesn't return anything (for example if I use select() method at the
> end). So, for example, in my generic template (the template which
> creates statements) I can't put a rule to saved all the widgets in the
> same variable.
>
>
> AbstractSWTBot current =
> bot.tree().expandNode("Ant").expandNode("Editor").select( "Templates");
> assertVisible(current);
>
> So, what I want to do is to find the best solution to keep clean the
> code and in the same time save resources. Maybe the solution is to
> change the workflow of the generator... but that's another question...
>
> Thank you again for the response!!
>

Ok, that's a lot more clear! So if I understand well, you want to know
if SWTBot keeps somewhere a kind of "last accessed widget" or "last
found widget". Unfortunately, there is no such thing in SWTBot.

Also, if you are doing this through generated code, then why bother
about code dirtyness? In my experience, you shouldn't try to
understand/modify generated code, so I don't see why always storing in a
variable is a problem. But, once again, I may not have all the
information on how you do things... My best bet would be to save
everything in a variable, using some kind of reflection introspection to
make sure that the method returns an AbstractSWTBot class before trying
to store the returned value in a variable.

Bottom line is: I don't think that what you are trying to accomplish is
100% solvable by SWTBot. There is probably some code kung-fu you'll need
to do that is not SWTBot related...

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

*Because performance matters.*
Re: Getting the current widget [message #523204 is a reply to message #522978] Thu, 25 March 2010 10:24 Go to previous message
Urtzi Odriozola is currently offline Urtzi Odriozola
Messages: 27
Registered: March 2010
Junior Member
Thanks a lot!!

The information you've gave me it's very helpfull!!
Quote:

My best bet would be to save
everything in a variable, using some kind of reflection introspection to
make sure that the method returns an AbstractSWTBot class before trying
to store the returned value in a variable.


And this last idea is the same that I was thinking to implement. So, yes, you are right... I shouldn't worry about the code dirtiness and I should try to make it as easier I can...

Thank you again

Best regards,
Previous Topic:Please ignore ... wrong group
Next Topic:Re: Eclipse Modeling GMF Files
Goto Forum:
  


Current Time: Thu Aug 21 16:01:43 EDT 2014

Powered by FUDForum. Page generated in 0.01927 seconds