question

CRaman avatar image
CRaman Suspended asked CRaman Suspended posted

Mapping Tables Without Unique Keys

I am trying to create a response map for the attached table.  I would like to perform an analysis on the role and return the Lp/Ap pair if the role is not equal to a specific value.  I have tried a simple table map; however, without a unique key, I am having troubles gaining the correct pair for the role in question.

 

Here is the analysis I would like to preform:

 

Foreach line in the table If the role is not equal to 'aMaster' Print a message which include the (Lp,Ap) pair Pass the test Else Print an error message with the (Lp,Ap) pair Fail the test

 

I know how to do this in the test case; however, I would prefer to do this in an analysis rule.  Is there a way to build a response map to facilitate such a rule?

iTestresponse map
test_table.txt (450 B)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

PaulD avatar image
PaulD answered PaulD posted

Actually, you can take advantage of the fact that when iTest analyzes a query that returns multiple items, it provides $value containing the value of the extracted data, but it also provides $index, providing you the index of the item on each iteration through the processing of the matches.   In this case, since you want to process every row in the table, this turns out to be easy, because you can use $index in a query command inside the message to fetch the information you want.  (Note that $index is zero-based, while xpath is one-based, and so you need to add 1 to the index to get the xpath row number.)

 

I'm attaching a test case and response map that shows this working.

 

A good example of where you can do some impressive magic with analysis rules if you know what you're doing and know how to take advantage of xpath.  But there is something to be said for a more pedestrian approach, where you store the response and then run a for loop over it as Kumar suggested.


2 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

CRaman avatar image CRaman commented ·

PaulD, your suggestion worked with one exception.  Since //role is a list and not a parameterized query, I needed to use [lindex list index] to find the value of Lp() and Ap().

 

Thanks for the pointer to $index.  This will come in handy in many other places!!

0 Likes 0 ·
PaulD avatar image PaulD CRaman commented ·
Note that a query extractor has a checkbox that controls the case where it finds multiple matches.  You can either pass the list along (once) to a processor.  Or you can call the processor once for each match.  The latter is the default, and that is what I'm using there.  In that case, you shouldn't need to use [lindex].  Nevertheless, if you have what you want, I'm satisfied!
0 Likes 0 ·
dclaar avatar image
dclaar Suspended answered dclaar Suspended posted
The problem I see with the analysis rule is that you can easily find the lines that match, but I don't think that you can convince XPath to give up the row number.
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KumarS avatar image
KumarS answered KumarS posted

A table map for this is very easy. You can add a query to it to return all the "roles". Then you can add analysis rule which uses "query" to extract data. By default, iTest will analyze each value of the query - so you will get the effect you want. But you will not be able to access "Lp" and "Ap" for that column without incrementing a variable to keep track of which row you are on.

 

So I think you should use a foreach for this. If you removed your restriction for printing "Lp" and "Ap", you can do that in an analysis rule using a query which matched every  "role".

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.