Find String in a table

32 views
Skip to first unread message

Vincent Cueto

unread,
Jun 11, 2014, 8:54:35 AM6/11/14
to windowte...@googlegroups.com
Hi !
 
I am new with windowTester pro and i would like to know :
 
Is it possible to check if a table contains a particular string ?
 
For the moment i can only get a cell and his content ...
 

TableItemLocator myTableCell =

new TableItemLocator("out/cal", 4, new LabeledLocator(Table.class, "List of imported files:"));

 

If there is no functions to do that, is it possible to get the table size ? Then i will be able to get every cells and check the content.
 
Thanks a lot !!!
 
Best regards,
CUETO Vincent

Fred G

unread,
Jun 13, 2014, 2:26:30 PM6/13/14
to windowte...@googlegroups.com
Hi,

You could use something along the lines of:

    private boolean tableContainsCell(SWTWidgetLocator tableLocator, final String cellContent) throws WidgetSearchException {
        IWidgetReference ref = (IWidgetReference) getUI().find(tableLocator);
        final Table table = (Table) ref.getWidget();
        final AtomicReference<Boolean> result = new AtomicReference<Boolean>();
        result.set(false);
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                System.out.println("table.getItemCount():" + table.getItemCount());
                System.out.println("table.getColumnCount():" + table.getColumnCount());
                for(TableItem ti : table.getItems()){
                    for(int i = 0; i < table.getColumnCount(); i++){
                        if(ti.getText(i).equalsIgnoreCase(cellContent)){
                            result.set(true);
                            System.out.println("Item " + cellContent + " found.");
                        }
                    }
                }
            }
        });
        return result.get();
    }

And then call this method
   SWTWidgetLocator tableLocator = new SWTWidgetLocator(Table.class);
   boolean tableContainsCell = tableContainsCell(tableLocator, "<your search string>");
   System.out.println("tableContainsCell: " + tableContainsCell);

Instead of returning a boolean you could also return the table item itself.

Please note, that a TableItemLocator represents the complete row. If you want to check the text of a specific column, you need to use getText(int index).
If you want to access a table cell, WindowTester provides a TableCellLocator, where you can specify the row and column.

Regards,

Fred

Vincent Cueto

unread,
Jun 18, 2014, 9:16:19 AM6/18/14
to windowte...@googlegroups.com
Hi and thanks for your answer ;)
 
That was helpful but i have problems with ^^
 

IWidgetReference ref = (IWidgetReference) getUI().find(tableLocator)

That line leads to an error :

An exception occurred: com.windowtester.runtime.swt.internal.widgets.SWTUIException 

Thanks again for your help

Best regards,

CUETO Vincent

 


 

 

 
  

Fred G

unread,
Jun 24, 2014, 6:57:12 PM6/24/14
to windowte...@googlegroups.com
Hi,

Can you attach the complete stack trace?
Is the test working if you don't use the tableContainsCell() method?

Regards,

Fred
Reply all
Reply to author
Forward
0 new messages