Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Would like to have relative searching based on Composite parent
Would like to have relative searching based on Composite parent [message #525796] Wed, 07 April 2010 19:56 Go to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
In creating my SWTBot tests, I find that a number of widgets do not have labels so I am forced to use an index. This makes my tests very fragile.

In many cases, there is in fact a label close by. For example, a StringFieldEditor takes a label argument, but actually creates a Label beside a Text widget. If one could say: "find me the Text widget that is after label "X" or find me the Nth Text widget for the Composite which is the direct parent of label "Y", this would make the tests better able to withstand UI changes elsewhere on a Window which may be out of my control (e.g. the Properties dialog).

Seem reasonable?
Re: Would like to have relative searching based on Composite parent [message #525807 is a reply to message #525796] Wed, 07 April 2010 20:30 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Jeff Johnston wrote:
> In creating my SWTBot tests, I find that a number of widgets do not have
> labels so I am forced to use an index. This makes my tests very fragile.
>
> In many cases, there is in fact a label close by. For example, a
> StringFieldEditor takes a label argument, but actually creates a Label
> beside a Text widget. If one could say: "find me the Text widget that
> is after label "X" or find me the Nth Text widget for the Composite
> which is the direct parent of label "Y", this would make the tests
> better able to withstand UI changes elsewhere on a Window which may be
> out of my control (e.g. the Properties dialog).
>
> Seem reasonable?

Actually, there is some utilities that you can use to do that:

SWTBotLabel label = bot.label("Text");
Widget widget = SWTUtils.nextWidget(label.widget);
SWTBotText text = new SWTBotText((Text)widget, null);

I've never used them myself, but I think this is how you are supposed to
use them.

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Would like to have relative searching based on Composite parent [message #525818 is a reply to message #525807] Wed, 07 April 2010 21:11 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Great information, thanks. Worked for finding the StringFieldEditor Text widget.

Is there any on-going work to create a more detailed user's manual which could have such a cool tip?
Re: Would like to have relative searching based on Composite parent [message #525826 is a reply to message #525796] Wed, 07 April 2010 21:12 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
There are quite a few things that swtbot provides:

<widget>WithLabel:
bot.textWithLabel('your label')

This one looks for the *first* textbox after a label, not necessarily
the one immediately next to it, possibly even from a different
composite. It basically does a depth first traversal of the UI, adds
each widget into a list as it traverses. It then matches a label and
finds any text box after after the label.

<widget>InGroup:
bot.textWithLabelInGroup(label, group)

This one does something similar, but does a depth first traversal of the
group and not the entire shell, so I'd recommend using inGroup for
improving readability and reduce the number of places where you use indexes.

If you could provide a screenshot of the app and the control you can
access, we could help better.


– Ketan
eclipse.org/swtbot | twitter.com/ketanpkr


On 4/7/10 12:56 PM, Jeff Johnston wrote:
> In creating my SWTBot tests, I find that a number of widgets do not have
> labels so I am forced to use an index. This makes my tests very fragile.
>
> In many cases, there is in fact a label close by. For example, a
> StringFieldEditor takes a label argument, but actually creates a Label
> beside a Text widget. If one could say: "find me the Text widget that is
> after label "X" or find me the Nth Text widget for the Composite which
> is the direct parent of label "Y", this would make the tests better able
> to withstand UI changes elsewhere on a Window which may be out of my
> control (e.g. the Properties dialog).
>
> Seem reasonable?
Re: Would like to have relative searching based on Composite parent [message #525831 is a reply to message #525826] Wed, 07 April 2010 22:04 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
That information was very helpful. It would be nice to put it in the javadoc for the SWTWorkbenchBot interfaces if not also in an online help manual. It would have been slightly more intuitive if the APIs were AfterLabel as opposed to WithLabel.

I replaced the SWTUtils logic with the SWTTextWithLabel and that worked as I wanted it to.

I also was able to find the tree structure of mine using the SWTTreeWithLabel. So, now, I have no indexes anymore except to access the top-level Project menu. This is needed because using bot.men("Project") finds a lower-level menu and not the top-level one that I expect to use from the main Eclipse window.

I use SWTTree() for the left-hand tree found in the Project->Properties dialog. If you think there is a better way to get that tree structure, feel free to let me know..

I ran into a problem with setText() which is used in the example in the current SWTBot Wiki User's Guide. The setText() method works to set the StringFieldEditor Text box I am interested in, but when I click OK for the Properties dialog, my logic didn't register the value. If I instead use the typeText() method, it works exactly as expected. I looked into it and the StringFieldEditor Text widget adds a key listener (addKeyListener) that is set up to with a keyReleased() method before it performs the valueChanged() method.
Re: Would like to have relative searching based on Composite parent [message #525853 is a reply to message #525831] Thu, 08 April 2010 00:48 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
swtbot's #setText() just does a widget#setText followed by a modify
listener, which is why the StringFieldEditor may not work with
#setText(). It's designed for cases where you're setting a lot of text
and #typeText() takes a long time!

#typeText() does exactly that - type it in which is why it works with
keylisteners.

– Ketan

On 4/7/10 3:04 PM, Jeff Johnston wrote:
> That information was very helpful. It would be nice to put it in the
> javadoc for the SWTWorkbenchBot interfaces if not also in an online help
> manual. It would have been slightly more intuitive if the APIs were
> AfterLabel as opposed to WithLabel.
>
> I replaced the SWTUtils logic with the SWTTextWithLabel and that worked
> as I wanted it to.
>
> I also was able to find the tree structure of mine using the
> SWTTreeWithLabel. So, now, I have no indexes anymore except to access
> the top-level Project menu. This is needed because using
> bot.men("Project") finds a lower-level menu and not the top-level one
> that I expect to use from the main Eclipse window.
>
> I use SWTTree() for the left-hand tree found in the Project->Properties
> dialog. If you think there is a better way to get that tree structure,
> feel free to let me know..
>
> I ran into a problem with setText() which is used in the example in the
> current SWTBot Wiki User's Guide. The setText() method works to set the
> StringFieldEditor Text box I am interested in, but when I click OK for
> the Properties dialog, my logic didn't register the value. If I instead
> use the typeText() method, it works exactly as expected. I looked into
> it and the StringFieldEditor Text widget adds a key listener
> (addKeyListener) that is set up to with a keyReleased() method before it
> performs the valueChanged() method.
Re: Would like to have relative searching based on Composite parent [message #526129 is a reply to message #525796] Thu, 08 April 2010 19:16 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Any ideas why I can't find the Configuration configSelector combo box in the Properties dialog http://sourceware.org/newlib/properties.png? I tried to access it using:

String config = bot.comboBoxWithLabel("Configuration:").getText();

but keep getting WidgetNotFound.

The CDT code that creates it is within an AbstractPage which has the following code::

		if (showsConfig()) {
			// Add a config selection area
			Group configGroup = ControlFactory.createGroup(composite, EMPTY_STR, 1);
			gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
			gd.grabExcessHorizontalSpace = true;
			gd.widthHint= 150;
			configGroup.setLayoutData(gd);
			configGroup.setLayout(new GridLayout(3, false));

			Label configLabel = new Label(configGroup, SWT.NONE);
			configLabel.setText(UIMessages.getString("AbstractPage.6")); //$NON-NLS-1$
			configLabel.setLayoutData(new GridData(GridData.BEGINNING));

			configSelector = new Combo(configGroup, SWT.READ_ONLY | SWT.DROP_DOWN);
			configSelector.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event e) {
					handleConfigSelection();
				}
			});
			gd = new GridData(GridData.FILL_BOTH);
			configSelector.setLayoutData(gd);



Am I doing something wrong to access it?
Re: Would like to have relative searching based on Composite parent [message #526132 is a reply to message #526129] Thu, 08 April 2010 19:45 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Could you paste us a screenshot at an image upload site:
http://imageshack.us/

– Ketan

On 4/8/10 12:16 PM, Jeff Johnston wrote:
> Any ideas why I can't find the Configuration configSelector combo box in
> the Properties dialog ? I tried to access it using:
>
> String config = bot.comboBoxWithLabel("Configuration:").getText();
>
> but keep getting WidgetNotFound.
>
> The CDT code that creates it is within an AbstractPage which has the
> following code::
>
>
> if (showsConfig()) {
> // Add a config selection area
> Group configGroup = ControlFactory.createGroup(composite, EMPTY_STR, 1);
> gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
> gd.grabExcessHorizontalSpace = true;
> gd.widthHint= 150;
> configGroup.setLayoutData(gd);
> configGroup.setLayout(new GridLayout(3, false));
>
> Label configLabel = new Label(configGroup, SWT.NONE);
> configLabel.setText(UIMessages.getString("AbstractPage.6")); //$NON-NLS-1$
> configLabel.setLayoutData(new GridData(GridData.BEGINNING));
>
> configSelector = new Combo(configGroup, SWT.READ_ONLY | SWT.DROP_DOWN);
> configSelector.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event e) {
> handleConfigSelection();
> }
> });
> gd = new GridData(GridData.FILL_BOTH);
> configSelector.setLayoutData(gd);
>
>
>
> Am I doing something wrong to access it?
>
Re: Would like to have relative searching based on Composite parent [message #526133 is a reply to message #526129] Thu, 08 April 2010 20:03 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Jeff Johnston wrote:
> Any ideas why I can't find the Configuration configSelector combo box in
> the Properties dialog ? I tried to access it using:
>
> String config = bot.comboBoxWithLabel("Configuration:").getText();

<snip>

> configLabel.setText(UIMessages.getString("AbstractPage.6"));
> //$NON-NLS-1$

Are 100% sure that the string "AbstractPage.6" is "Configuration:"? Is
there a possibility that it might be "Configuration: " or "
Configuration:". I stumbled on this a couple of times, it's rather hard
to find out only by looking at the UI...

What I'm doing now most of the time would be:
bot.comboBoxWithLabel(UIMessages.getString("AbstractPage.6")).getText();

this avoid this kind of quirks. I also find that my tests are more
stable since the strings are in sync.

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Would like to have relative searching based on Composite parent [message #526137 is a reply to message #526133] Thu, 08 April 2010 20:27 Go to previous message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Thanks again. That was it. The message has an additional space at the end. It would be nice if the function could do a trim() of strings before comparing the label text so as to make this thing a little harder to stumble upon. It is nicer to read the actual string text in the test rather than have to go look up the actual magic string. As well, the string class may not be exposed.
Previous Topic:How to access TestData from headless build
Next Topic:Can SWTBot be used to scrape the Console view?
Goto Forum:
  


Current Time: Fri Mar 29 09:27:34 GMT 2024

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

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

Back to the top