Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » accessing SwtWidgets
accessing SwtWidgets [message #511372] Mon, 01 February 2010 13:16 Go to next message
Thomas Py is currently offline Thomas PyFriend
Messages: 6
Registered: January 2010
Junior Member
hI!

i´ve got a rcp-application with own swt-items.. for example there is a "QCombo extends Composite"
how can i access this combobox with the swtbot? it´s not a ccombobox and not a combobox so i dont know how can i change the selected item with the swtbot.
can swtbot list all widgets?

thnx for any help
Re: accessing SwtWidgets [message #511387 is a reply to message #511372] Mon, 01 February 2010 13:48 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Thomas Py wrote:
> hI!
> i´ve got a rcp-application with own swt-items.. for example there is a
> "QCombo extends Composite" how can i access this combobox with the
> swtbot? it´s not a ccombobox and not a combobox so i dont know how can
> i change the selected item with the swtbot. can swtbot list all widgets?
> thnx for any help

Finding the widget is quite easy. Using it is something else...

To find your QCombo widget, do this:
QCombo widget = bot.widget(widgetOfType(QCombo.class));

Now to use it, you can't just do QCombo.setSelectedItem() (or whatever
API it might have), you must ensure that the code that needs running in
the UI thread be run in the UI thread, using sync or async execution.
For some quick testing, you could do this:
asyncExec(new VoidResult()
{
void run()
{
widget.setSelectedItem();
}
}

but it quickly burdens your test code. What you should do instead is use
the page object pattern: make a wrapper for your widget. Ex:
public class SWTBotQCombo extends AbstractSWTBot<QCombo>
{
public SWTBotQCombo(QCombo w) throws WidgetNotFoundException
{
this(w, null);
}

public SWTBotQCombo(QCombo w, SelfDescribing description) throws
WidgetNotFoundException
{
super(w, description);
}

public void setSelectedItem()
{
asyncExec(new VoidResult()
{
void run()
{
widget.setSelectedItem();
}
}
}

...
}

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

*Because performance matters.*
Re: accessing SwtWidgets [message #511450 is a reply to message #511387] Mon, 01 February 2010 11:06 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Thanks for the great explanation Pascal!

I've copied the entire text to the FAQ :)

-- Ketan

On 2/1/10 5:48 AM, Pascal Gelinas wrote:
> Thomas Py wrote:
>> hI!
>> i´ve got a rcp-application with own swt-items.. for example there is a
>> "QCombo extends Composite" how can i access this combobox with the
>> swtbot? it´s not a ccombobox and not a combobox so i dont know how can
>> i change the selected item with the swtbot. can swtbot list all widgets?
>> thnx for any help
>
> Finding the widget is quite easy. Using it is something else...
>
> To find your QCombo widget, do this:
> QCombo widget = bot.widget(widgetOfType(QCombo.class));
>
> Now to use it, you can't just do QCombo.setSelectedItem() (or whatever
> API it might have), you must ensure that the code that needs running in
> the UI thread be run in the UI thread, using sync or async execution.
> For some quick testing, you could do this:
> asyncExec(new VoidResult()
> {
> void run()
> {
> widget.setSelectedItem();
> }
> }
>
> but it quickly burdens your test code. What you should do instead is use
> the page object pattern: make a wrapper for your widget. Ex:
> public class SWTBotQCombo extends AbstractSWTBot<QCombo>
> {
> public SWTBotQCombo(QCombo w) throws WidgetNotFoundException
> {
> this(w, null);
> }
>
> public SWTBotQCombo(QCombo w, SelfDescribing description) throws
> WidgetNotFoundException
> {
> super(w, description);
> }
>
> public void setSelectedItem()
> {
> asyncExec(new VoidResult()
> {
> void run()
> {
> widget.setSelectedItem();
> }
> }
> }
>
> ...
> }
>
> Hope this helps.
Re: accessing SwtWidgets [message #512151 is a reply to message #511450] Thu, 04 February 2010 08:17 Go to previous message
Thomas Py is currently offline Thomas PyFriend
Messages: 6
Registered: January 2010
Junior Member
ok yeah! thanks! it worked. now i can copypaste-rename it and access all the swt-items i find Smile

thank you!
Previous Topic:Archived SWTBot builds available.
Next Topic:perspective getLabel
Goto Forum:
  


Current Time: Thu Mar 28 09:09:25 GMT 2024

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

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

Back to the top