Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SWTBot/Testing Custom Controls"

(Added Pascal's mail from the forums with some reformatting)
 
m (add a category)
Line 51: Line 51:
  
 
*Because performance matters.*
 
*Because performance matters.*
 +
 +
[[Category: SWTBot]]

Revision as of 17:12, 22 February 2011

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

Back to the top