How to do a getText()?

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 do a getText()?

Postby EclipseDev » Tue Aug 12, 2008 7:02 am

How to retrieve the Text of a StyledText widget? The generated code does something like this:

ui.click(new XYLocator(new SWTWidgetLocator(StyledText.class),280, 25));

I need to edit the text in that styledtext. If I could retrieve it, I could subsitute the string I need and then do ui.enterText(). The problem is I have no access to the contents of StyledText...

Thanks!
EclipseDev
 
Posts: 6
Joined: Tue Jul 22, 2008 3:28 am

Re: How to do a getText()?

Postby Phil Quitslund » Wed Aug 13, 2008 8:56 am

Ideally we should have a StyledTextLocator (and have opened a feature request).

In the meantime, you could try something like this:

Code: Select all
   public void sampleGetText() throws Exception {
      IUIContext ui = getUI();
      IWidgetReference ref = (IWidgetReference) ui.find(new SWTWidgetLocator(StyledText.class));
      StyledText text = (StyledText) ref.getWidget();
      String contents = getText(text);
      //...
   }


   private String getText(final StyledText text) {
      final String [] contents = new String[1];
      Display.getDefault().syncExec(new Runnable() {
         public void run() {
            contents[0] = text.getText();
         }
      });
      return contents[0];
   }


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

Re: How to do a getText()?

Postby EclipseDev » Wed Aug 13, 2008 11:44 pm

Thanks, I have implemented my own StyledTextLocator to retrieve and select the text (which was also not possible with CTRL SHIFT END...).

As part of the enhancement, it would be nice to have access to the text cursor and string, in order to edit the text like a user would do.
EclipseDev
 
Posts: 6
Joined: Tue Jul 22, 2008 3:28 am

Re: How to do a getText()?

Postby Phil Quitslund » Thu Aug 14, 2008 7:12 am

Good deal.

If you would like to share your implementation and annotate it with where you left off, I'd be happy to help fill it in.

Thanks!
--
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