How can i get items and item count from the table

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

How can i get items and item count from the table

Postby karthik.intels12 » Tue Apr 06, 2010 3:02 am

Hello sir,

I'm writing windows test cases for my application. I have one table which has number of columns. When i add elements to that table using button click, corresponding data will get fill in that table. I want to check whether data is added to that table or not when i click on that button using windows tester. similarly delete function is also there. So if i could take the count of elements present in that table, is more than enough. So pls give me some suggestions that will solve this issue.

I'm waiting for your valuable suggestions 8)
Thanks and Regards,
Karthik.M.S
karthik.intels12
 
Posts: 35
Joined: Wed Mar 31, 2010 4:37 am

Re: How can i get items and item count from the table

Postby Phil Quitslund » Tue Apr 06, 2010 1:33 pm

In the future we will provide a more direct way to do this (e.g., by providing accessors to this state on a special TableLocator). In the meantime, here's a snippet that should get you most of the way there:

Code: Select all
   public void testSomething() throws Exception {
                ...
      //Your locator may need to be more complex; this one assumes there is only one table visible
      IWidgetReference tableRef = (IWidgetReference) ui.find(new SWTWidgetLocator(Table.class));
      Table table = (Table) tableRef.getWidget();
      int count = getItemCount(table);
      assertEquals(/*expected*/, count);
   }

   private int getItemCount(final Table table) {
      final int count[] = new int[1];
      Display.getDefault().syncExec(new Runnable() {
         public void run() {
            count[0] = table.getItemCount();
         }
      });
      return count[0];
   }

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

Re: How can i get items and item count from the table

Postby karthik.intels12 » Wed Apr 07, 2010 5:06 am

wow... its working.. Thank you very much sir:)
Thanks and Regards,
Karthik.M.S
karthik.intels12
 
Posts: 35
Joined: Wed Mar 31, 2010 4:37 am

Re: How can i get items and item count from the table

Postby Phil Quitslund » Wed Apr 07, 2010 5:30 am

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

Re: How can i get items and item count from the table

Postby karthik.intels12 » Thu Apr 15, 2010 5:44 am

Hello,

Still table count is not enough to meet my requirement. How can i get data from particular cell in table without using XYLocator. Please help me out of this.
Thanks and Regards,
Karthik.M.S
karthik.intels12
 
Posts: 35
Joined: Wed Mar 31, 2010 4:37 am

Re: How can i get items and item count from the table

Postby Phil Quitslund » Thu Apr 15, 2010 9:06 am

First you want to find the specific cell. Something like:

Code: Select all
IWidgetReference ref = (IWidgetReference)ui.find(new TreeCellLocator(...));

(See the javadocs for details on the TreeCellLocator: http://downloads.instantiations.com/WindowTesterDoc/integration/latest/docs/html/reference/javadoc/com/windowtester/runtime/swt/locator/TreeCellLocator.html.)

Having done that, get the TreeItem:

Code: Select all
TreeItem item = (TreeItem)ref.getWidget();

and then, query it for data. For an example of doing this in a thread-safe way, see the previous snippet for getItemCount(...).
--
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