Getting Text from a StyledText?

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

Getting Text from a StyledText?

Postby rcraddock » Fri Jul 31, 2009 6:08 am

I have a StyledText Control in an editor, but I can't seem to get the Text when I am testing :

LabeledLocator l = new LabeledLocator(StyledText.class,"Syslog Example:");
Assert.assertEquals("Example not as expected in Editor", SYSLOG, l.getText(ui));

This throws an exception that the Locator does not support HasText.

How can I access the text for this type of Control?

Thanks
Richard C
rcraddock
 
Posts: 3
Joined: Wed Apr 02, 2008 8:22 am

Re: Getting Text from a StyledText?

Postby Phil Quitslund » Fri Jul 31, 2009 9:04 am

Hi Richard,

We're working on making this smoother but in the meantime, you might try this:

Code: Select all
      LabeledLocator l = new LabeledLocator(StyledText.class,"Syslog Example:");
      IWidgetReference ref = (IWidgetReference) ui.find(l);
      final StyledText widget = (StyledText) ref.getWidget();
      final String[] text = new String[1];
      widget.getDisplay().syncExec(new Runnable() {
         public void run() {
            text[0] = widget.getText();
         }
      });
      Assert.assertEquals("Example not as expected in Editor", SYSLOG, text[0]);


A bit cumbersome but serviceable? Let us know what you think!

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

Re: Getting Text from a StyledText?

Postby dubovskoy » Wed Dec 01, 2010 5:20 pm

Has there been an improvement in this area - a less cumbersome solution?

As part of our GUI JUnit test we need to inspect the text that was entered by a user in a multi-tabbed editor. The editor is expected to handle multiple files (with one file being the main one) and has a dedicated tab for each physical file. Each editor tab which we need to examine is implemented as a subclass of org.eclipse.ui.editors.text.TextEditor. Deep down the TextEditor class uses StyledWidget control to display contained text.

We select the desired editor's tab by using:
Code: Select all
ui.click(new CTabItemLocator("<filename1>", new EditorLocator("<main_filename>")));


To get to the text contained by the editor I'm using the solution given by Phil on Jul 31, 2009 which is

Code: Select all
wref = (IWidgetReference)ui.click(new SWTWidgetLocator(StyledText.class));      
final StyledText widget = (StyledText) wref.getWidget();
final String[] text = new String[1];
widget.getDisplay().syncExec(new Runnable() {
         public void run() {
            text[0] = widget.getText();
         }
});
Assert.assertEquals("Unexpected text in the editor", text[0]);


I'd really like to know if there a better way to get to the text contained by an eclipse text editor.

Thank you in advance,
-Boris
dubovskoy
 
Posts: 1
Joined: Wed Dec 01, 2010 5:03 pm

Re: Getting Text from a StyledText?

Postby keertip » Thu Dec 02, 2010 8:50 am

Sorry to say that there has been no improvement in this area. We never did get around to implementing a better story. At the moment this workaround is the best way to go about getting text from a StyledText !
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest