|
|
|
Re: How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1014285 is a reply to message #1013061] |
Mon, 25 February 2013 14:16 |
|
On 02/22/2013 06:36 PM, ajay shedge wrote:
> Hi Mickael,
> I have attached the required snapshot.
> I want to know how to handle the validations of fields seen in the snapshot.
> I have certain cases where I intentionally insert such values in these fields which should generate error. I need to capture this error message using SWTBot.
I don't know of anything in SWTBot that allows you to check the message
of a Wizard. I guess you'll need to use underlying SWT widgets and API
to check what you want here.
> I also tried to search for the repository of SWTGenerator (http://download.eclipse.org/technology/swtbot/snapshots/) but somehow its not working.
> Will you also direct me to appropriate link from where i can download and start using it.
What do you mean by "it is not working"? In this world of ours "not
working" doesn't mean much.
Can you go into details: what did you try? What worked? What did you
expect? What did you got?
--
Mickael Istria
JBoss, by Red Hat
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
|
|
|
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 16:33 |
Benjamin Ratiarisolo Messages: 16 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,
--
Benjamin Ratiarisolo
IBM ODM Decision Server Rules - Software Developer
IBM Software - France Lab
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02312 seconds