StringComparator and EditorLocator

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

StringComparator and EditorLocator

Postby dif » Thu Oct 16, 2008 6:38 am

Hi,

in the javadoc I found that the constructor of the EditorLocator() accepts the partName also as a regular expression.
Can you give me a short example? The String (partName) must respect the following regular expr: "1_*.(in|out)"
I spent an hour to get it work..but unfortunately..it doesn't.

Regards,
Diana.
dif
 
Posts: 6
Joined: Wed Oct 15, 2008 5:58 am

Re: StringComparator and EditorLocator

Postby Phil Quitslund » Fri Oct 17, 2008 8:33 am

WT regular expressions use the Java java.util.regex.Pattern matching rules. For more on those, see the Sun javadocs:

http://java.sun.com/j2se/1.5.0/docs/api ... ttern.html

We have a few examples in our docs as well:

http://downloads.instantiations.com/Win ... rator.html

For testing, the easiest thing might be to just play around with a simple test case like this:

Code: Select all
import com.windowtester.runtime.util.StringComparator;
import junit.framework.TestCase;

public class PatternTest extends TestCase {
   public void testRegexp() throws Exception {
      String regex = "1_.*\\.(in|out)";
      assertTrue(StringComparator.matches("1_thing.in", regex));
      assertTrue(StringComparator.matches("1_thing.out", regex));
      assertTrue(StringComparator.matches("1_thang.in", regex));
      assertFalse(StringComparator.matches("2_thang.in", regex));
      //etc...
   }
}


(Not sure I got the pattern right but you get the idea.)

Let us know how it goes!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Re: StringComparator and EditorLocator

Postby dif » Mon Oct 20, 2008 12:34 am

Hi,

I checked your example. StringComparator matches the regular expressions BUT EditorLocator class doesn't.
Today I've also recorded the following actions (below, the code).

Code: Select all
ui.click(new TreeItemLocator("Eq_Maps_open_both/1", new ViewLocator(
            "de.inframe.ise.navigator.views.NavigatorView")));
      ui.assertThat(new SWTWidgetLocator(CLabel.class).isVisible());


Now, I want to get the LABEL from the wrapper (CLabel.class), but it returns NULL. I thought that is happening becouse of the ambigous identification of this CLabel.class and I"ve tried to be more specific, by giving the SWTWidgetLocator an extra argument, that is: a regular expresion that defines the label names that appear (regex = "*.(in|out)")

Code: Select all
ui.click(new TreeItemLocator("Eq_Maps_open_both/1", new ViewLocator(
            "de.inframe.ise.navigator.views.NavigatorView")));
      ui.assertThat(new SWTWidgetLocator(CLabel.class, "*.(in|out)").isVisible());


After that modification, the windowtester runtime, timed-out (expected=true, actual=false)

Pls Help,

Diana.
dif
 
Posts: 6
Joined: Wed Oct 15, 2008 5:58 am

Re: StringComparator and EditorLocator

Postby Phil Quitslund » Mon Oct 20, 2008 10:28 am

Does this variation work any better?:

Code: Select all
ui.assertThat(new SWTWidgetLocator(CLabel.class, ".*\\.(in|out)").isVisible());


What's the exact text of the label?
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Re: StringComparator and EditorLocator

Postby dif » Mon Oct 20, 2008 11:26 am

Yes,

many 10x. All this time I had given the regexp in a wrong mode.

Rg,
Diana.
dif
 
Posts: 6
Joined: Wed Oct 15, 2008 5:58 am

Re: StringComparator and EditorLocator

Postby Phil Quitslund » Tue Oct 21, 2008 12:14 pm

Good deal. Glad you got it working!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest