Reputation: 2045
How to get the description text of an eclipse wizard using SWTBot? The wizard.shell.gettext()
method gives the title, but I could not find any method for getting the description.I need it to verify the description and the error messages displayed on the wizard page.
Upvotes: 1
Views: 886
Reputation: 822
In case of WizardNewProjectCreationPage I use:
bot.textWithLabel("Create Project"); // This title set by page.setTitle("Create Project");
bot.text("Description."); // this is description set by page.setDescription("Description.");
Upvotes: 0
Reputation: 325
In order to test our eclipse plug-ins, the team I worked with developped a custom DSL on top of SWTBot to represent wizards, dialogs and so-on. Here is a code snippet that is working well in our case (beware that this might be eclipse version dependent, seems OK with eclipse 3.6 and 4.2)
class Foo {
/**
* The shell of your dialog/wizard
*/
private SWTBotShell shell;
protected SWTBotShell getShell() {
return shell;
}
protected <T extends Widget> T getTopLevelCompositeChild(final Class<T> clazz, final int index) {
return UIThreadRunnable.syncExec(shell.display, new Result<T>() {
@SuppressWarnings("unchecked")
public T run() {
Shell widget = getShell().widget;
if (!widget.isDisposed()) {
for (Control control : widget.getChildren()) {
if (control instanceof Composite) {
Composite composite = (Composite) control;
int counter = 0;
for (Control child : composite.getChildren()) {
if (clazz.isInstance(child)) {
if (counter == index) {
return (T) child;
}
++counter;
}
}
}
}
}
return null;
}
});
}
/**
* Returns the wizard's description or message displayed in its title dialog
* area.
*
* A wizard's description or message is stored in the very first Text widget
* (cf. <tt>TitleAreaDialog.messageLabel</tt> initialization in
* <tt>org.eclipse.jface.dialogs.TitleAreaDialog.createTitleArea(Composite)</tt>
* ).
*
*/
public String getDescription() {
final Text text = getTopLevelCompositeChild(Text.class, 0);
return UIThreadRunnable.syncExec(getShell().display, new Result<String>() {
public String run() {
if (text != null && !text.isDisposed()) {
return text.getText();
}
return null;
}
});
}
}
Upvotes: 1
Reputation: 2045
as a workaround , I used this code
public void verifyWizardMessage(String message) throws AssertionError{
try{
bot.text(" "+message);
}catch(WidgetNotFoundException e){
throw (new AssertionError("no matching message found"));
}
}
here bot is a SWTBot instance available to method.The wizard messages automatically prepends a space to the description field,so I m using " "+message
. Hope it helps
Upvotes: 2