Selecting Items From Dynamically Generated ComboBoxes

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

Selecting Items From Dynamically Generated ComboBoxes

Postby goksel » Mon Dec 20, 2010 2:42 am

Hello,
we have in one of our shells three "tables". To be more precise, they are implemented as a TableViewer (org.eclipse.jface.viewers.TableViewer). They use TableViewerColumns. Each cell of that table view uses "magic combo boxes". They are implemented with the method .setEditingSupport:

ComboLabelProvider comboLabelProvider = new ComboLabelProvider();
view.tvcFirstDay.setEditingSupport(new ComboBoxCellEditingSupport(view.tvSchedule, dbc, propFirstDayShift,//
comboLabelProvider, model.getAvailableShifts().toArray()));

With this I cannot name the combo boxes. Hence, the NamedWidgetLocator is useless in my situation. Currently I have my own methods which get respectively set the cell values directly. But to have a good test I'd prefer to use the comboboxes.

Is there any way to get this done?

Thanks in advance!
Göksel

P.S.: Some pieces of information about my own methods. As I mentioned we use three tables in that shell. So the TableCellLocator throws an exception that multiple widgets are found. Thus I use ui.findAll(new SWTWidgetLocator(Table.class) to get all three table references from which I take the one with the table name that was asked for. Then I get the row by table.getItem(row) followed by the column using item.getText(column). I do the same for the set method.
... so a "NamedTableCellLocator" would be fine for a next version! :-)
goksel
 
Posts: 17
Joined: Thu Nov 25, 2010 7:13 am

Re: Selecting Items From Dynamically Generated ComboBoxes

Postby keertip » Mon Dec 20, 2010 1:25 pm

Now in the table, when you click on the cell with the combo, does it get activated? Have you tried clicking on the column using a TableCellLocator, and then using a ComboItemLocator to do the selection? As in

Code: Select all
ui.click(new TableCellLocator(1,"Neighbor city")); // row 1, column Neighbor city
ui.click(new CComboItemLocator("Siegen"));
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am

Re: Selecting Items From Dynamically Generated ComboBoxes

Postby goksel » Thu Dec 23, 2010 7:06 am

keertip,
to your question
Now in the table, when you click on the cell with the combo, does it get activated?

You will find a screenshot of the table attached to this post. So, as soon as I click into the cell, the combobox appears and the cell is activated.

Have you tried clicking on the column using a TableCellLocator, and then using a ComboItemLocator to do the selection?

Here is the code that was generated by the recorder:
Code: Select all
   public void testTestTableCell01() throws Exception {
      IUIContext ui = getUI();
      ui.click(new NamedWidgetLocator("NAME_MAIN_VIEW_BTN_WORK_SCHEDULE"));
      ui.wait(new ShellShowingCondition(""));
      ui.click(new NamedWidgetLocator("NAME_SEARCH_CONTROL_BTN_SEARCH"));
      ui.click(new TableItemLocator("MunchenWorkgroup"));
      ui.click(new XYLocator(new CComboItemLocator("shift1"), 33, 9));
      ui.click(new CComboItemLocator("shift1"));
      ui.click(new CComboItemLocator("shift5"));
      ui.click(new XYLocator(new CComboItemLocator("shift2"), 48, 4));
      ui.click(new CComboItemLocator("shift2"));
      ui.click(new CComboItemLocator("Morning Shift"));
      ui.click(new CComboItemLocator(""));
      ui.click(new CComboItemLocator(""));
      ui.click(new CComboItemLocator("Evening Shift"));
      ui.click(new ButtonLocator("Speichern"));
      ui.ensureThat(new ShellLocator("Der Client...").isClosed());
   }


Here is the result a Widget NOT Found exception. I attached the junit output as well as the console output.

And now the code after I've modified it a little, also complying with your advice:

Code: Select all
   public void testTestTableCell02() throws Exception {
      IUIContext ui = getUI();
      ui.click(new NamedWidgetLocator("NAME_MAIN_VIEW_BTN_WORK_SCHEDULE"));
      ui.wait(new ShellShowingCondition(""));
      ui.click(new NamedWidgetLocator("NAME_SEARCH_CONTROL_BTN_SEARCH"));
      ui.click(new TableItemLocator("MunchenWorkgroup"));
      ui.click(new TableCellLocator(1,"09.12.2010")); // row 1, column "09.12.2010"
      ui.click(new CComboItemLocator("shift5"));
      ui.click(new TableCellLocator(2,"10.12.2010")); // row 2, column "10.12.2010"
      ui.click(new CComboItemLocator("shift5"));
      ui.click(new TableCellLocator(3,"11.12.2010")); // row 3, column "11.12.2010"
      ui.click(new CComboItemLocator("shift5"));
      ui.click(new ButtonLocator("Speichern"));
   }


In that case I get a Multiple Widgets Found exception. Again you'll find both the junit and the console output attached.

The table is a workschedule, so for each day and employee you can select the same shifts.

Please advise...

Thanks,
Göksel
Attachments
example2_output.txt
(55.42 KiB) Downloaded 5 times
example1_output.txt
(10.57 KiB) Downloaded 3 times
TableCell.png
TableCell.png (9.36 KiB) Viewed 85 times
goksel
 
Posts: 17
Joined: Thu Nov 25, 2010 7:13 am

Re: Selecting Items From Dynamically Generated ComboBoxes

Postby keertip » Thu Dec 23, 2010 1:30 pm

Unfortunately, the recorder does not generate code for the TableCellLocator, which is why you do not see it in the generated code.

You are getting a MultipleWidgetsFound Exception because the same (row,column) information can refer to the other tables in the view too. The row,column info is not unique. Can you specify the parent of the table, as in

Code: Select all
ui.click(new TableCellLocator(1,"09.12.2010").in(0, parentLocator); // 0 refers to index for the first table, 1- second table etc


If so, that will make it clear as to which table to click.
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am

Re: Selecting Items From Dynamically Generated ComboBoxes

Postby goksel » Mon Jan 03, 2011 5:49 am

keertip,
first of all I wish you and your collegues a happy new year! :-)

Then I would like to thank you for supporting me. The ".in" method in the last snipped gave me the hint I needed.

I tried about two dozen combinations until I found a way that works for me:
Code: Select all
ui.click(new TableCellLocator(1, 2).in(
      new NamedWidgetLocator(
            "NAME_WORK_SCHEDULE_VIEW_TBL_WORK_SCHEDULE")));
ui.click(new CComboItemLocator("Morning Shift"));

I also can use the column name (e.g. 09.12.2010 in my case) instead of the column number "2".

All widgets are named in our code because the generated test code looks much better and is more readable.

Thanks again!
Cheers,
Göksel
goksel
 
Posts: 17
Joined: Thu Nov 25, 2010 7:13 am

Re: Selecting Items From Dynamically Generated ComboBoxes

Postby keertip » Tue Jan 04, 2011 8:23 am

Thanks for the wishes and a Happy New Year to you too! Glad that you have found a solution to the problem!
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest

cron