Easy way to get to the Figure referenced by IWidgetLocator?

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

Easy way to get to the Figure referenced by IWidgetLocator?

Postby 3061 » Wed Mar 25, 2009 1:55 am

I'm almost sorry to ask, but I couldn't figure (no pun intended) this one out.

I have this method that clicks to a position relative to the center of a NamedFigure:

Code: Select all
   
protected IWidgetLocator clickOnFigureCenterInDiagramWithOffset(String prefix, String figureName, int xOffset, int yOffset) throws Exception
{
   System.out.println("clickOnFigureCenterInDiagramWithOffset" + figureName + xOffset + yOffset);
   moveMouseToDiagramOrigin();
   boolean isClickable = true;
   NamedFigureLocator locator = new NamedFigureLocator(prefix + figureName);
   int figureCenterX = getFigureCenterXOffset(prefix + figureName);
   int figureCenterY = getFigureCenterYOffset(prefix + figureName);
   ILocator clickLocation = new XYLocator(locator, figureCenterX + xOffset, figureCenterY + yOffset);
   IWidgetLocator widgetThatWasClickedOn = null;

   try
   {
      widgetThatWasClickedOn = ui.click(clickLocation);
   }
   catch (Exception e)
   {
      isClickable = false;
   }

   assertTrue("Can't click on the Figure: \"" + prefix + figureName + "\" with offset x = " + xOffset + ", y = " + yOffset, isClickable);

   /*
    * TODO Right now, this always returns a
    * "com.windowtester.runtime.gef.internal.FigureReference". Find a way
    * to return the Class Type or getFigureId() of the clicked location.
    */

   return widgetThatWasClickedOn;
}


Is there a way to resolve that FigureReference (widgetThatWasClickedOn) so I can get the type of the Figure that was clicked on?

I wanna do something like:

Code: Select all
if (clickedOnFigure.getFigureId().contains "Foobar")
   System.out.println("A Foobar-Figure was clicked");


Thanks in advance.
3061
 
Posts: 42
Joined: Mon Feb 23, 2009 12:43 am

Re: Easy way to get to the Figure referenced by IWidgetLocator?

Postby Phil Quitslund » Mon Mar 30, 2009 11:53 am

Since the reference returned is am implementer of com.windowtester.runtime.gef.IFigureReference. You should be able to do something like this:

Code: Select all
IFigureReference widgetThatWasClickedOn = null;

try
   {
      widgetThatWasClickedOn = (IFigureReference)ui.click(clickLocation);
   }
...

if (widgetThatWasClickedOn != null)
{
   IFigure clickedOnFigure = widgetThatWasClickedOn.getFigure();
   Class cls = clickedOnFigure.getClass();
   ...
}


Does this get you there?


-phil
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Re: Easy way to get to the Figure referenced by IWidgetLocator?

Postby 3061 » Tue Mar 31, 2009 6:33 am

Yea, that works, thanks a lot!

My GUI Tests needs to blindly click (XYLocator) in a GEF diagram and do different things, depending on the Figure that was clicked.
Code: Select all
   /**
    * Tries to call getFigureId() of the given IWidgetLocator and returns the
    * value of getFigureId(). 
    *
    * @param widgetLocator
    * @return Output of <code>getFigureId()</code>. If the widgetLocator has no
    * such method, the class name (including package) is returned.
    */
   public String getFigureIdOfWidgetLocator(IWidgetLocator widgetLocator)
   {
      IFigureReference widgetThatWasClickedOn = null;
      String out = "";

      try
      {
         widgetThatWasClickedOn = (IFigureReference) widgetLocator;
      }
      catch (Exception e)
      {
      }

      if (widgetThatWasClickedOn != null)
      {
         IFigure clickedOnFigure = widgetThatWasClickedOn.getFigure();
         try
         {
            out = (String)clickedOnFigure.getClass().getMethod("getFigureId", (Class[])null).invoke(clickedOnFigure, (Object[])null);
         }
         catch (Exception e)
         {
            System.err.println("Couldn't invoke getFigureId() in " + clickedOnFigure.getClass().toString());
            out = clickedOnFigure.getClass().toString();
         }
      }
      
      return out;
   }


It's not pretty but it works. :-)
3061
 
Posts: 42
Joined: Mon Feb 23, 2009 12:43 am

Re: Easy way to get to the Figure referenced by IWidgetLocator?

Postby Phil Quitslund » Thu Apr 02, 2009 9:01 am

I'll take works over pretty any day... ;) Thanks for the follow-up!
--
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