Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » java .setData
java .setData [message #662953] Fri, 01 April 2011 14:34 Go to next message
Eclipse UserFriend
Originally posted by: david.landry.gmail.com

Some questions regarding how best to go about training the developers to
create their widgets in a manner that best accommodates SWTBot testing.

I'm not a java developer so I may be on the totally wrong track, so
advice or "redirection" to a better path is welcomed.

Anyway, the problem I have as I see it is that the developers are
writing their code with no real consideration to testing, so I get cases
where they are creating things like text fields and the only thing I
have (that I am aware of) to hook onto with SWTBot is the actual text in
the text field. Of course, this text can change. so if I want to do some
action, or perform an assert on that widget, if the text has changed,
instead of giving me some nice "assert failed" message and continuing on
with the test, the test will abort with an exception (unless I take
steps to handle the exception or ignore it of course, but that makes for
a lot of unnecessary exception processing programming.)

If I understand correctly the developers can use the .setData property
on their widgets to create a "key/value" pair that I may be able to use
in SWTBot to make finding and referring to the widget a consistent process.

My questions are:

1) do I have the "theory" correct?
2) Is this (having the developers add key/values to widgets) the proper
way to present the issues and solution?
3) How would the .setData property be used to do this? Can they create
any key, or does it have to be a SWTBot type property (I saw one example
where they used "text.setData("org.eclipse.swtbot.widget.key",
"text1");" and were able to use bot.textWithId("text1") to find the
widget during testing... does this mean the developers have to load and
compile their apps with a SWTBot library, or is this just an object that
the application itself doesn't really care about, and SWTBot will
recognize and use .. does the key have to be
org.eclipse.swtbot.widget.key, or can it be something else, and if so
how do I tell SWTBot what key is to be used?

Thanks.
Re: java .setData [message #662982 is a reply to message #662953] Fri, 01 April 2011 17:25 Go to previous messageGo to next message
Mariot Chauvin is currently offline Mariot ChauvinFriend
Messages: 174
Registered: July 2009
Senior Member
Hi David,

Some comments below.

Le 01/04/2011 16:34, David Landry a écrit :
> Some questions regarding how best to go about training the developers to
> create their widgets in a manner that best accommodates SWTBot testing.
>
> I'm not a java developer so I may be on the totally wrong track, so
> advice or "redirection" to a better path is welcomed.
>
> Anyway, the problem I have as I see it is that the developers are
> writing their code with no real consideration to testing, so I get cases
> where they are creating things like text fields and the only thing I
> have (that I am aware of) to hook onto with SWTBot is the actual text in
> the text field. Of course, this text can change. so if I want to do some
> action, or perform an assert on that widget, if the text has changed,
> instead of giving me some nice "assert failed" message and continuing on
> with the test, the test will abort with an exception (unless I take
> steps to handle the exception or ignore it of course, but that makes for
> a lot of unnecessary exception processing programming.)

My opinion (based on my experience) is that you should rely on the
displayed text to write your functional tests :

- Label do not change so often. I think you will have more often
complete UI refactoring than a label change.
- When a label is updated, correcting the test is really easy. If one of
your test suddently fail, you may simply ask the dev team, if they have
changed any label recently (or on last commit depending on how often you
launch your test)


>
> If I understand correctly the developers can use the .setData property
> on their widgets to create a "key/value" pair that I may be able to use
> in SWTBot to make finding and referring to the widget a consistent process.
>
> My questions are:
>
> 1) do I have the "theory" correct?
> 2) Is this (having the developers add key/values to widgets) the proper
> way to present the issues and solution?
> 3) How would the .setData property be used to do this? Can they create
> any key, or does it have to be a SWTBot type property (I saw one example
> where they used "text.setData("org.eclipse.swtbot.widget.key",
> "text1");" and were able to use bot.textWithId("text1") to find the
> widget during testing... does this mean the developers have to load and
> compile their apps with a SWTBot library, or is this just an object that
> the application itself doesn't really care about, and SWTBot will
> recognize and use .. does the key have to be
> org.eclipse.swtbot.widget.key, or can it be something else, and if so
> how do I tell SWTBot what key is to be used?
>
> Thanks.

I think that's a bad idea to use the set data for this.


Mariot
--
Mariot Chauvin @ Obeo

Blog : http://mariot-thoughts.blogspot.com
Twitter :http://twitter.com/mchv
Professional support : http://obeo.fr/pages/maintenance-and-support/
Re: java .setData [message #663098 is a reply to message #662953] Sun, 03 April 2011 15:19 Go to previous message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 4/1/11 7:34 AM, David Landry wrote:

> If I understand correctly the developers can use the .setData property
> on their widgets to create a "key/value" pair that I may be able to use
> in SWTBot to make finding and referring to the widget a consistent process.
>
> My questions are:
>
> 1) do I have the "theory" correct?

No and Yes. I believe you might have had this idea from the web testing
frameworks (selenium and the like). While having unique IDs on elements
in a webpage is a good idea for various reasons(primarily CSS and JS),
using the IDs to identify something is trivial; it does have the
downside of making the test unreadable, unless you open up a combination
of the HTML source and an inspector like firebug.

While setData lets you accurately identify widgets, IMHO they are a bit
of a drag to work with. They make the code a bit more unreadable.
Reusing a bit of code might mean that you get dup IDs on the screen.
They also make tests hard to read, unless the IDs are named very clearly
to what it represents(as a matter of discipline).

The idea of calling setData came up because some widgets are indeed hard
(but not impossible) to identify using SWTBot APIs. In my two years of
doing SWTBot tests, I find IDs generally have a sweet spot for use and I
prefer to use them in extreme circumstances.

Tests are a safety net to ensure that the app works, and the UI does not
change very often and having tests that break once in a while is IMHO
actually a nice thing because they remind everyone that there is value
in writing them :)

> 2) Is this (having the developers add key/values to widgets) the proper
> way to present the issues and solution?

Tough question, putting on my consultant hat would involve convincing
devs to run the tests before making modifications, which means that
tests must be easy for devs to find and understand :)

> 3) How would the .setData property be used to do this? Can they create
> any key, or does it have to be a SWTBot type property (I saw one example
> where they used "text.setData("org.eclipse.swtbot.widget.key",
> "text1");" and were able to use bot.textWithId("text1") to find the
> widget during testing... does this mean the developers have to load and
> compile their apps with a SWTBot library, or is this just an object that
> the application itself doesn't really care about, and SWTBot will
> recognize and use .. does the key have to be
> org.eclipse.swtbot.widget.key, or can it be something else, and if so
> how do I tell SWTBot what key is to be used?

Using the SWTBot predefined key that you mention
helps(http://goo.gl/lxl9z), because SWTBot is easier to work with when
using that key. SWTBot will work with any other key, but that becomes a
bit awkward esp if the key keeps changing

The the devs can hardcode that string as a constant somewhere just as
you explain in the example above and not have to worry about liking with
swtbot.

> Thanks.


--
Ketan
http://ketan.padegaonkar.name | http://eclipse.org/swtbot | @ketanpkr
Previous Topic:Entering text in a input box in a wizard
Next Topic:Unable to access a button that is located in the header of a SharedHeaderFormEditor.
Goto Forum:
  


Current Time: Tue Dec 23 01:01:18 GMT 2014

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

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