|
|
Re: accessing SwtWidgets [message #511450 is a reply to message #511387] |
Mon, 01 February 2010 11:06 |
Ketan Padegaonkar 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03809 seconds