Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to capture error messages thrown by an Eclipse application using SWTBot ?
How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1012552] Thu, 21 February 2013 19:30 Go to next message
ajay shedge is currently offline ajay shedgeFriend
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 #1012870 is a reply to message #1012552] Fri, 22 February 2013 11:06 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

I'm not sure I understand your use-case. Can you please post a screenshot?

--
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 #1013061 is a reply to message #1012870] Fri, 22 February 2013 17:36 Go to previous messageGo to next message
ajay shedge is currently offline ajay shedgeFriend
Messages: 5
Registered: February 2013
Junior Member
Hi Mickael,
I have attached the required screenshot.
I want to know how to handle the validations of fields seen in the screenshot.
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.

index.php/fa/13524/0/


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.

[Updated on: Fri, 22 February 2013 17:41]

Report message to a moderator

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 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

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 Go to previous messageGo to next message
Benjamin Ratiarisolo is currently offline Benjamin RatiarisoloFriend
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
Re: How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1014856 is a reply to message #1014350] Tue, 26 February 2013 15:46 Go to previous messageGo to next message
ajay shedge is currently offline ajay shedgeFriend
Messages: 5
Registered: February 2013
Junior Member
Thanks Benjamin. I will try this out and will reply on this thread with the outcome.
Re: How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1014858 is a reply to message #1014285] Tue, 26 February 2013 15:51 Go to previous messageGo to next message
ajay shedge is currently offline ajay shedgeFriend
Messages: 5
Registered: February 2013
Junior Member
Hi Mickael,

I was not able to locate the repository (http://download.eclipse.org/technology/swtbot/snapshots/) for installing the SWTbot Recorder and Test Generator.
The link is broken and I did not know from where to find the latest repository. Hence i had raised this question in this topic.
Re: How to capture error messages thrown by an Eclipse application using SWTBot ? [message #1014893 is a reply to message #1014858] Tue, 26 February 2013 16:58 Go to previous message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

This repo is not empty and is fully usable:
http://download.eclipse.org/technology/swtbot/snapshots/content.jar
If you can't access this file, it means that you have a problem on your
side.

HTH
--
Mickael Istria
JBoss, by Red Hat
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Previous Topic:How to find Toolbar and ToolItems with SWTBot
Next Topic:More on EclipseSpy
Goto Forum:
  


Current Time: Fri Apr 19 00:30:10 GMT 2024

Powered by FUDForum. Page generated in 0.02312 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top