Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Jubula » Select table row - row has to fulfill multiple conditions
Select table row - row has to fulfill multiple conditions [message #1314255] Fri, 25 April 2014 08:57 Go to next message
Stefan Miller is currently offline Stefan MillerFriend
Messages: 12
Registered: March 2014
Junior Member
Hi,

so far I could get along with selecting rows/columns by value using ub_tbl_selectValueFromColumn or ub_tbl_selectValueFromRow. However, I have a new case and I don't know how to solve it with the existing jubula mechanisms.

First of all, I want to test a RCP application. This app has tables with multiple columns. Such a table could look like this:

A B C
---------
A1 B1 C1
A2 B1 C2
A1 B2 C1

Hence, a certain value can be contained in a column multiple times. Now lets say I want to select the row which has A == A1, B == B1 and C == C1. Just searching for a row containing e.g. A1 would not be enough as multiple rows can have this value in A and I want to select a specific one. The only thing I know is that the cominbation in the table is unique, so there is no other row with A == A1, B == B1 and C == C1.

Is it possible to select a row/column which has to fulfill multiple conditions?
Re: Select table row - row has to fulfill multiple conditions [message #1314800 is a reply to message #1314255] Fri, 25 April 2014 16:07 Go to previous messageGo to next message
David Hickernell is currently offline David HickernellFriend
Messages: 85
Registered: October 2012
Member
I believe that there is a way to do this, although it might be somewhat complicated. I would have to do some testing to make sure it works, but the solution that I am thinking of would involve a loop variable, and a small dataset correlating column numbers to the expected values in those columns.

I assume that it is okay for the test to fail if there is no row that fulfills all of the conditions?
Re: Select table row - row has to fulfill multiple conditions [message #1316694 is a reply to message #1314800] Sat, 26 April 2014 17:38 Go to previous messageGo to next message
David Hickernell is currently offline David HickernellFriend
Messages: 85
Registered: October 2012
Member
The solution I was thinking of doesn't work, because of the way event handlers behave. I believe it can still be done, but the solution is trickier and involves nested event handlers.

You need to define a number of test cases equal to the number of conditions plus two. The following assumes that the values you are looking for have been stored in variables A1, B1, and C1. It also assumes that you have fewer than 1000 rows in your table; you can adjust that number to whatever makes sense for your situation. Note that all of the "Check" steps must be Test Steps, and not Test Cases.

TC_Base: 
  1: Set ROWNUM = 1
  2: Check $ROWNUM > 1000
  Event Handler (Action Error): Empty Case, RETURN
  Event Handler (Check Failed): TC_A, RETRY, 1000 times
TC_A: 
  1: Store text from Table Cell at Row $ROWNUM, column (A's column) in variable A
  2: Store text from Table Cell at Row $ROWNUM, column (B's column) in variable B
  3: Store text from Table Cell at Row $ROWNUM, column (C's column) in variable C
  4: Check $A != $A1
  5: Set ROWNUM = ?trunc(?add($ROWNUM,1),0)
  Event Handler (Check Failed): TC_B, RETRY, 1 time
TC_B: 
  1: Check $B != $B1
  2: Set A = ''
  Event Handler (Check Failed): TC_C, RETRY, 1 time
TC_C: 
  1: Check $C != $C1
  2: Set B = ''
  Event Handler (Check Failed): TC_Match, RETRY, 1 time
TC_Match:
  1: Select Cell in Row $ROWNUM, column (any column) in table
  2: Set C = ''
  3: Set ROWNUM = 1001

Please let me know if this works, or doesn't make enough sense!

[Updated on: Sat, 26 April 2014 18:15]

Report message to a moderator

Re: Select table row - row has to fulfill multiple conditions [message #1316810 is a reply to message #1316694] Sat, 26 April 2014 19:13 Go to previous messageGo to next message
David Hickernell is currently offline David HickernellFriend
Messages: 85
Registered: October 2012
Member
I just figured out another solution, along the lines of my original idea, that uses five test cases (not counting the empty event handler, which I forgot to count last time) regardless of the number of conditions, and allows you to use a dataset containing any number of column/value pairs. It is even less intuitive than the other solution, but can be extended without increasing the number of test cases or degree of nesting. All that needs to be done to increase the number of conditions is to add rows to the dataset.

TC_Multi:
  1: Set NC = (number of conditions, e.g. 3 in the example you gave)
  2: Set ROWNUM = 1
  3: Set MATCHES = 0
  4: Check $MATCHES greater or equal than $NC
  Event Handler (Check Failed): TC_TestRow, RETRY, (1000 or some number higher than the number of rows) times
  Event Handler (Action Error): Empty Test Case, RETURN
TC_TestRow:
  1: Set MATCHES = 0
  2: TC_TestCondition
  3: Set ROWNUM = ?trunc(?add($ROWNUM,1),0)
TC_TestCondition (This is the one that will reference the dataset, with columns COLUMN and VALUE)
  1: Store text from Table Cell at Row $ROWNUM, Column =COLUMN in variable COLVAL
  2: Check $COLVAL not equals =VALUE
  Event Handler (Check Failed): TC_Match, RETRY, 1 time
TC_Match:
  1: Set MATCHES = ?add($MATCHES,1)
  2: Set COLVAL = ''
  3: Set MATCH_COPY = $MATCHES
  4: Check $MATCH_COPY < $NC
  Event Handler (Check Failed): TC_Select, RETRY, 1 time
TC_Select:
  1: Select Table Cell at Row $ROWNUM, Column (any)
  2: Set MATCH_COPY = 0

I hope this helps!

[Updated on: Sat, 26 April 2014 19:19]

Report message to a moderator

Re: Select table row - row has to fulfill multiple conditions [message #1319461 is a reply to message #1316810] Mon, 28 April 2014 07:19 Go to previous messageGo to next message
Stefan Miller is currently offline Stefan MillerFriend
Messages: 12
Registered: March 2014
Junior Member
Thanks for your different proposals! I tried the second variant and it actually worked. I will also take a look at your third variant later.

Thank you very much again.
Re: Select table row - row has to fulfill multiple conditions [message #1320120 is a reply to message #1319461] Mon, 28 April 2014 15:50 Go to previous messageGo to next message
David Hickernell is currently offline David HickernellFriend
Messages: 85
Registered: October 2012
Member
You're very welcome, I'm glad to be able to help.

If you do try the last solution as well, I will be curious to know the outcome, especially if the number of conditions might be increased to more than three.
Re: Select table row - row has to fulfill multiple conditions [message #1415738 is a reply to message #1320120] Wed, 03 September 2014 13:49 Go to previous messageGo to next message
Antoine VINCENT is currently offline Antoine VINCENTFriend
Messages: 8
Registered: July 2014
Junior Member
I used the first solution for a 4 columns SWT TreeTable in a RCP application.
It works fine, except that in order to store a variable, you have to define your own "Test Step" instead of using the one in the unbound_module (see https://www.eclipse.org/forums/index.php/mv/msg/487882/1060003/#msg_1060003 for more information).

I tried the second solution, but it has a small drawback : the full dataset (all columns) is always tested, even if the first column doesn't match.

Thanks.
Re: Select table row - row has to fulfill multiple conditions [message #1415750 is a reply to message #1415738] Wed, 03 September 2014 14:08 Go to previous message
Alexandra Schladebeck is currently offline Alexandra SchladebeckFriend
Messages: 1613
Registered: July 2009
Senior Member
Hi Antoine,

if you want to just use specific cells from a dataset then you can use the function ?getCentralTestDataSetValue, which is documented in the chapter on functions. Maybe this can help in this case.

Best regards,
Alex
Previous Topic:EventHandler to loop on data until correct line is found
Next Topic:Can not see unbound modules when testing RCP AUT
Goto Forum:
  


Current Time: Fri Apr 19 21:15:33 GMT 2024

Powered by FUDForum. Page generated in 0.03408 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top