Jump to: navigation, search

Difference between revisions of "SWTBot/Testing Custom Controls"

(Added Pascal's mail from the forums with some reformatting)
 
m (Add the swtbot furniture on the page)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
{{SWTBot}}
 +
 
Thomas Py wrote:
 
Thomas Py wrote:
 
> hI!
 
> hI!
Line 51: Line 53:
  
 
*Because performance matters.*
 
*Because performance matters.*
 +
 +
[[Category: SWTBot]]

Latest revision as of 17:15, 22 February 2011


SWTBot
Website
Update Sites
Community
Mailing List
Forums/Newsgroups
IRC
Contribute
Open Bugzilla tickets
Open Gerrit reviews
Browse Source
Continuous Integration


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.*