question

AdeelM avatar image
AdeelM asked AdeelM posted

Querying on parent node

Team,

 

My customer asked a question which I’m not sure if there is an answer.

 

Basically, the question is whether it is possible to specify a parent node as query and it returns a list of child nodes as name-value pair.

 

In the response map above, the user would like to query on buffers (Small, Big, etc.).

 

parent-node.jpg

 

When I created this xpath as custom query, iTest flattens out the data as:

 

parent-node-data.jpg

 

 

iTestresponse map
show_buffers.ffrm (75.4 KiB)
parent-node.jpg (192.3 KiB)
10 |950

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

1 Answer

·
PaulD avatar image
PaulD answered PaulD posted

The best way that I can think of doing this is to take advantage of XPATH's ability to get the child nodes of a specified parent node.  Then you can iterate through them to get the values. 

 

So, in your example, you can get a count of the number of children under buffers by using

 

count(//buffers/*)

 

And you can get the name of a node under buffers and index 3, for example,  using

 

name(//buffers/*[3])

 

and you can get the value of the 3rd item using

 

//buffers/*[3]

 

The trouble, of course, is that you don't have procedural logic to work within in a response map.  It can only give you queries.  But it turns out that you can use this same approach using the response map's custom queries mechanisms.

 

You can generate a custom query that will return you all of the names of the child nodes of "buffers".  And you can generate a custom query that will return you all of the values of those -- keyed by name.

 

Unfortunately, the file you posted has been truncated, so is invalid.  If you want to see an example, repost the proper file.

1 comment
10 |950

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

AdeelM avatar image AdeelM commented ·

Yep, that is how I ended up making this work.

 

Basically I created three custom queries:

 

  • numOfItems(buffer_name)
  • nameOfItem(buffer_name, index)
  • itemValues(buffer_name, index)

In the test case, I can create a "for" loop to iterate through each node and find its name and value.

 

See the solution in the attached zip file.

 

Since I output to Execution view, here is how it looks like:

 

screenshot.jpg

0 Likes 0 ·
show_buffers.zip (8.1 KiB)
screenshot.jpg (140.7 KiB)

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.