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