Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » PROPERTIES OF COMPONENTS
PROPERTIES OF COMPONENTS [message #21521] Thu, 12 February 2009 15:38 Go to next message
Luis Miguel is currently offline Luis MiguelFriend
Messages: 31
Registered: July 2009
Member
Hello,
I want to know if there is some way to access any component properties.
For example:If I have got a Button and I want to know its 'Id'.

This is important because if you are testing an application the button
text may change, but the Id button will not change. If you use
bot.buttonWithLabel(label), itŽs possible that this action is outdated but
if we use bot.buttonWithId(Id), we will not have problems.

Thanks and regards.

Luis Miguel
Re: PROPERTIES OF COMPONENTS [message #21558 is a reply to message #21521] Thu, 12 February 2009 16:36 Go to previous messageGo to next message
Hans Schwaebli is currently offline Hans SchwaebliFriend
Messages: 70
Registered: July 2009
Member
I think because of usability it is usually not a good idea to dynamically
change a button text. Better use several buttons with constant labels.

But if you really want to change button text dynamical, then you can use
the Widget#setData(String,Object) method on that SWT Button in your
application to set an ID. Use SWTBotPreferences#DEFAULT_KEY for the key.
Access the button with SWTBot#buttonWithId(String) in your test. I wonder
why you ask, since you already know about the method.

You don't need it for your problem, but you can access the SWT Button
object from SWTBot with the public variable SWTBotButton#widget. And then
you have full access to the method of that object and get its ID by using
Widget#getData(String). I think you need to wrap it with
UIThreadRunnable.syncExec(...) because of protected thread access.
Re: PROPERTIES OF COMPONENTS [message #22713 is a reply to message #21558] Wed, 18 February 2009 09:46 Go to previous messageGo to next message
Luis Miguel is currently offline Luis MiguelFriend
Messages: 31
Registered: July 2009
Member
I do not want to change button text dynamical. I think that you do not
understand me.

For example:
An application has several stages of development. In the first phase you
have an input with label "Name:", but in the second phase developers have
changed the same label with "Name of project:".
If you use bot.TextWithLabel(label), itŽs possible that this action is
outdated but if we use bot.TextWithId(Id), we will not have problems.

I want to know if there is some way to access any component properties.For
example, I want to know the id Text. Is there any snnipet about this?

Thank again.

Luis Miguel
Re: PROPERTIES OF COMPONENTS [message #22756 is a reply to message #22713] Wed, 18 February 2009 10:16 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHEFriend
Messages: 129
Registered: July 2009
Senior Member
Luis Miguel a écrit :
> I do not want to change button text dynamical. I think that you do not
> understand me.
>
> For example:
> An application has several stages of development. In the first phase you
> have an input with label "Name:", but in the second phase developers
> have changed the same label with "Name of project:".

As a good practice, in my tests labels are parametrized in static final
strings (the GUI labels are deifned in a generic project called from any
other test project)

--
Cordialement

Vincent MAHÉ

Ingénieur Plate-forme OpenEmbeDD - http://openembedd.org
IRISA-INRIA, Campus de Beaulieu, 35042 Rennes cedex, France
Tél: +33 (0) 2 99 84 71 00, Fax: +33 (0) 2 99 84 71 71
Re: PROPERTIES OF COMPONENTS [message #22886 is a reply to message #22713] Thu, 19 February 2009 00:47 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan PatelFriend
Messages: 68
Registered: July 2009
Member
For such issues, each widget can be found using a key and id. SWTBot has
method for each widget it can find and they end with "WithId". For
example, to find a Button with its id, you have following two methods:

org.eclipse.swtbot.swt.finder.SWTBot.buttonWithId(String id)
org.eclipse.swtbot.swt.finder.SWTBot.buttonWithId(String key, String id)

The method with only id as argument uses the default key used by SWTBot:

org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences.DEFAUL T_KEY =
"org.eclipse.swtbot.widget.key";

You can set the key and id using the setData method provided to each SWT
Widget...this will need to be done by the dev when the ui is created:

org.eclipse.swt.widgets.Widget.setData(String key, Object value)
Re: PROPERTIES OF COMPONENTS [message #23059 is a reply to message #22886] Thu, 19 February 2009 16:30 Go to previous messageGo to next message
Luis Miguel is currently offline Luis MiguelFriend
Messages: 31
Registered: July 2009
Member
I can not use these methods:org.eclipse.swt.widgets.Widget.setData(String
key, Object value). What version of SWTBot have you got? Or this method is
used by developers when they create the component?

Can I set my own key with this method? For example, I have an application
with two inputtexts and a button... If I want to identify the second input
with a unique way, Can I use this method?

Is there any snnipet about this?

Thanks again.

Luis Miguel
Re: PROPERTIES OF COMPONENTS [message #23102 is a reply to message #23059] Thu, 19 February 2009 17:30 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Yes, developers need to setData on components when they create it.

If you need to set components as an swtbot user, then you already have
the component and setting IDs don't have much value.

One recommendation is to keep use of IDs to a minimum, because they do
get in the way of readability because there's no way to figure out what
widget the ID corresponds to.

SWTBot provides for a far richer API to access widgets and you can find
widgets using regexes, text, within groups, with labels, or a
combination of these.

Look at one of the methods with the SWTBot class to see how matchers are
used, I suspect that you can probably do away with matchers than IDs.

-- Ketan

Luis Miguel wrote:
> I can not use these
> methods:org.eclipse.swt.widgets.Widget.setData(String key, Object
> value). What version of SWTBot have you got? Or this method is used by
> developers when they create the component?
>
> Can I set my own key with this method? For example, I have an
> application with two inputtexts and a button... If I want to identify
> the second input with a unique way, Can I use this method?
>
> Is there any snnipet about this?
>
> Thanks again.
>
> Luis Miguel
>
Re: PROPERTIES OF COMPONENTS [message #23180 is a reply to message #23102] Thu, 19 February 2009 18:17 Go to previous message
Luis Miguel is currently offline Luis MiguelFriend
Messages: 31
Registered: July 2009
Member
And Can I find the component id without the help of developers? Is there
any method like SWTButton.id or similar?

Thank you very much.

Luis Miguel
Previous Topic:click on check-style button does not make it checked/unchecked
Next Topic:looking for suggesting to locate/interact with the context menu of a source editor
Goto Forum:
  


Current Time: Wed Dec 04 13:36:51 GMT 2024

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

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

Back to the top