How to clean a text field?

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

How to clean a text field?

Postby JLomin » Wed Mar 21, 2007 3:23 am

With the previous release I used this code, that doesnt work for the current release (2.5.0).

Could you please give me some hint?

Code: Select all
   public void eraseField(String fieldName, int x, int y) throws Exception {
      final Text fieldNameField = (Text)ui.click(fieldName, x, y);
                  
      ui.getDisplay().syncExec(new Runnable() {
         public void run() {
            totCars = fieldNameField.getText().length();
         }
      });

      eraseField(totCars);
   }


   public void eraseField(int totCars) throws Exception {
      for (int i = 0; i < totCars; i++) {
         ui.keyClick(SWT.DEL);
      }
   }
   

//EXAMPLE OF USE:
   
   protected void registerWidgetInfo() {      
      ui.register("Conexion", new LabeledLocator(Text.class, "Conexion :"));      
   }
   
   public void testMain() throws Exception {         
      particular.eraseField("Conexion", 2, 7);         
   }
JLomin
 
Posts: 11
Joined: Mon Feb 05, 2007 11:40 pm

Postby Phil Quitslund » Wed Mar 21, 2007 12:59 pm

Sorry, yes, there is a new trick. Widget finds return widgets wrapped in WidgetReference objects.

Try this to get a hold of the text field:

Code: Select all

import com.windowtester.runtime.locator.WidgetReference;
import com.windowtester.runtime.swt.locator.LabeledTextLocator;

...


   public void eraseField(String fieldName, int x, int y) throws Exception {

      WidgetReference ref = (WidgetReference)ui.click(new XYLocator(new LabeledTextLocator(fieldName), x, y));
      final Text fieldNameField = (Text) ref.getWidget();
                 
      ui.getDisplay().syncExec(new Runnable() {
         public void run() {
            totCars = fieldNameField.getText().length();
         }
      });

      eraseField(totCars);
   }

--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Postby JLomin » Thu Mar 22, 2007 12:10 am

It works great, with a little fix:

"Display.getDefault()" instead of "ui.getDisplay()"


Code: Select all
Display.getDefault().syncExec(new Runnable() {
public void run() {
totCars = fieldNameField.getText().length();
}
});


Thanks Phil
JLomin
 
Posts: 11
Joined: Mon Feb 05, 2007 11:40 pm

Postby Phil Quitslund » Thu Mar 22, 2007 7:47 am

Oh right (still thinking the old API!) Nice catch. Glad it worked!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest