question

gtrotter avatar image
gtrotter asked gtrotter posted

query list of values for analysis from table response map

==============================================================================
I am attempting to replace the following table response map analysis query
==============================================================================
command    cmd more Table_Rtsp.csv.
 analyze  
  query    (mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[1]
 
 analyze  
  query    (mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[2]

 analyze  
  query    (mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[3]

 ....
 analyze  
  query    (mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[36]
  
=========================================================================
with the following tcl {statement}
========================================================================= 
command    cmd more Table_Rtsp.csv.
 analyze
  query   [tcl {for {set i 0}  {$i < 36} {incr i} {(mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[$i]}}]

==========================================================================================================
I have attempted a few syntax substitutions, however not sure if I am going in the right direction or am I totally lost and wasting time?  Is there an easier way to query values for analysis from a CSV?  Can you help?
==============================================================================================================

iTestresponse map
10 |950

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

gtrotter avatar image
gtrotter answered gtrotter posted
Thanks, this was very helpful.  Still some clean-up required but I was able to get my test to run on first try after reviewing documents for XPATH syntax.
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

If your query matches multiple elements, e.g. in this case:

 

(mapped/Tabular/diversIfEye_RTSP_stats/table/row/Entity_Name)

 

then iTest will automatically analyze this for all the matching items. You can control this on the "assert" property page. (Select assert row in the testcase and expand the property page in the bottom section of the testcase editor).

 

In this case,  (mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name) will match multiple elements where as  (mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[21]  will match 21st element only.

 

Another quick and easy wat do this is to use query command. You can write your testcase like this:

 

command cmd   more Table_Rtsp.csv   <--- store response in a variable called "foo".

 

for {i=0} {i<[query foo count(mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)]} {incr i}

      if   "[query foo  mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name\[$i\]]" == "yourcondition"

         then

             do something

         else

             do something

 

 

3 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.

PaulD avatar image PaulD commented ·

To reiterate Kumar's first point, you can take advantage of the fact that iTest can handle multiple matches during analysis by processing each item in turn -- saving you a lot of work.  This is clearly the much cleaner solution.  In fact, if you only want to pick up the values from one column in a table where the value of another column in the table has a certain value, then your query might look something like this:

 

mapped/Tabular/diversifEye_RTSP_stats/table/row[Entity_Name='yourcondition']/PktCounter

 

This would find all of the rows whose "Entity_Name" column has the value "yourcondition" and will extract the values of the PktCounter column.  If this matches multiple values, then the associated processor (assert, etc.) will process all of those matches.

 

If you are using response maps and this kind of thing might be used in many places, you might want to add a custom query to your response map for something like this, so that the query becomes something like:

 

PktCounter_For_Condition("yourcondition")

 

This makes the test case more readable, and also means that you don't have to figure out the appropriate XPATH each time.  If you need to help creating a custom query, let us know.

0 Likes 0 ·
gtrotter avatar image gtrotter PaulD commented ·

Paul,

Thanks, Kumar's first suggestion worked and is much simpler than what I was attempting.

you anticipated my second question.  I am attempting to qurey a list of values in table coulmn "Mean_QmVideo_Mos_by_Entity_Name(Entity_Name)"

I am attempting to perform analysis on each of the Mean_QmVideo_Mos column of table and if "$value >= [param Min_HD_MOS]" true then pass test case.  I am able to do this with multiple query and anslysis of the following format:  "Mean_QmVideo_Mos_by_Entity_Name((mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)[1])"

 

However I have attempted the following queries with no success.  Not sure what iTest is looking for in the 'yourcondition' .  Ideally, would like 'yourcondition'  to be search for '*HD*' in entity name.  (then would be able to do '*SD*'  for other entity names.  any help is appreciated.

 

(mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)/Mean_QmVideo_Mos_by_Entity_Name(Entity_Name)
(mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)/Mean_QmVideo_Mos_by_Entity_Name
(mapped/Tabular/diversifEye_RTSP_stats/table/row/[Entity_Name='*'])/Mean_QmVideo_Mos_by_Entity_Name
(mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)/Mean_QmVideo_Mos_by_Entity_Name
(mapped/Tabular/diversifEye_RTSP_stats/table/row/Entity_Name)/Mean_QmVideo_Mos

 

 

Didn't get to second part of your suggestion, however seems like this may be good option.  Expect that we will eventually be needing something of the format of

PktCounter_For_Condition("yourcondition")

Mean_QmVideo_Mos_For_Condition("yourcondition")

etc.

 

Thanks again.

0 Likes 0 ·
PaulD avatar image PaulD gtrotter commented ·

I'm not positive as to exactly what you are hoping to do.  But I suggest spending a few minutes studying up on XPATH.  Once you have that model in your head, I think you'll find that what you are trying to do is pretty easy.  The whole notion of response mapping and analysis in iTest is deeply dependent on XPATH, so knowing this language will definitely help you.  You can find a good tutorial here.

 

Here are a few things you should know:

 

1)  You use parentheses in XPATH for two different reasons.  First, you can surround any query fragment in parentheses to be able to refer to the results of that query as a nodeset.  So /foo/bar[2] and (/foo/bar)[2] are different because the first one finds the second "bar" element in any "foo" element.  The second one finds all of the /foo/bar elements and then returns the second of these.

 

2)  You use parentheses to provide arguments to an XPATH function.  So myfunc("foo") invokes an XPATH function called "myfunc", passes it one string argument "foo", and results in whatever that function returns -- a nodeset, a value, or whatever.  Note that if you are passing a string argument to an XPATH function, it must be surrounded by quotes.  myfunc(foo) is invalid (because it will consider foo as a query in this case).

 

3)  You can't use wildcards directly in queries as you might hope -- like  //foo[name="*"].  Instead, you need to take advantage of some built-in xpath string functions for matching strings.  You can use functions like starts-with(), ends-with(), contains(), matches().  Look here for a list of the functions.  Be careful, though, because XPATH 1.0 and 2.0 have different functions, and iTest is compliant with 1.0.

 

By the way, queries in iTest are really just custom XPATH functions. So when you say Mean_QmVideo_Mos_by_Entity_Name("foo"), you are really use an XPATH function that has been defined on the fly for that specific step.  iTest uses all of the queries associated with a response map and defines matching xpath functions that are around only for the step using that response map.

 

 

0 Likes 0 ·

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.