| How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1012552] |
Thu, 21 February 2013 14:30  |
ajay shedge Messages: 5 Registered: February 2013 |
Junior Member |
|
|
How to capture error messages thrown by an Eclipse application using SWTBot ?
The application that i am testing has certain text fields where validations are set.
for eg : There is textWithLabel("UserId *") which cannot have length more that 15 characters.
My tests run fine for all positive values but when i try negative scenarios it fails.
Is there any way where I can capture the error message in some SWTBot object whenever it fails.
The error message is a Text in Red Color displayed on the application panel.
|
|
|
|
|
|
| Re: How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1014350 is a reply to message #1014285] |
Mon, 25 February 2013 11:33   |
Benjamin Ratiarisolo Messages: 13 Registered: January 2010 Location: Paris, France |
Junior Member |
|
|
Ajay,
Indeed getting the (error/warning) Label and message Text displayed in a wizard is not as easy as it would seem at first.
I did encapsulate the corresponding code in my own API built on top of SWTBot.
It seems to be working OK (so far). You could try adapting it your specific case.
public abstract class WizardPage extends Dialog {
// ...
public String getMessage() {
return getDescription();
}
/**
* Returns the <tt>Image</tt> instance associated to the description or
* message displayed the wizard's title dialog area.
*
* This image is stored in the third Label widget (cf.
* <tt>TitleAreaDialog.messageImageLabel</tt> initialization in
* <tt>org.eclipse.jface.dialogs.TitleAreaDialog.createTitleArea(Composite)</tt>
* ).
*
*/
protected Image getMessageImage() {
final Label label = getTopLevelCompositeChild(Label.class, 2);
return UIThreadRunnable.syncExec(getShell().display, new Result<Image>() {
public Image run() {
return label.getImage();
}
});
}
/**
* 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() {
return text.getText();
}
});
}
private <T extends Widget> T getTopLevelCompositeChild(final Class<T> clazz, final int index) {
final SWTBotShell shell = getShell();
return UIThreadRunnable.syncExec(shell.display, new Result<T>() {
@SuppressWarnings("unchecked")
public T run() {
for (Control control : shell.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;
}
});
}
protected SWTBotShell getShell() {
// This member is initialized within my WizardPage constructor by the below code
// shell = getWorkbench().activateShell(title);
// Where 'title' is the title of the wizard.
return shell;
}
// ...
}
Hope this helps,
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01917 seconds