Printer FriendlyEmail Article Link

iTest: How to use query command to fetch value from the response?

Environment/Versions
  • iTest
Answer

In any test case, the fastest way to insert a query is by using Query command :
               [query ?-alwayslist? variable_name mapper_query]

  • Store the responses in the variable(variable_Name) using Store response property for a step. Ensure that the response is mapped by a response map or an analysis rule.
  • In a test case, Create a step that will use a value from the response.
  • Insert the Query:

    1. In the Description cell or the Command field, place the cursor where the query should appear (you can select text that will be replaced), and then right-click and select  Insert > Query on Stored Response. Select query from "Insert Query on Stored Response" dialog box and Click on Insert. This adds query in the standard format [query varName mapperQuery].

                                                 

                                                                                      OR      

        2. Click down arrow in the Description cell and Select a query command format. Right-click an element in the structure view and Select "Copy Xpath" or "Copy Query" option to copy the mapper_query into the query command. We can get this While working in the Test Case editor on a step for which a response map is specified (for the Expected Response).

                                          

Note: mapper_Query is a mapping query that will be applied to the structured data in that response object (either Xpath query or Query from the response map). If query includes whitespace,it must be surrounded by double-quotes.

  • The -alwaysList is optional and used to store the single extracted value in a list with a single element, rather than a scalar string. It is important when we are using the response as the argument to a foreach statement and a single extracted value can contain whitespace. When we use this option, a foreach statement that iterates over the stored variable will loop once for the match.
  • Mapper queries support field substitutions and some queries may also contain special interpreter characters(" [ ] $ or the space character). So we may need to “escape” these special characters by using \ character. The result is a properly-formatted field replacement.

    Eg: set new_var [query var mapped/Xml/testCase/execution/parameters/name[1]]

 


Product : Velocity Portfolio,Velocity iTest