I have a response in a test-step. The response is attached in the txt file.
As of now, I am not using any specific response map to query this output. However, I could find that the default "query" of iTest gives the following query map.
My question is the following:
I wanted to extract a part of the XPath of the "response".
For example:
The following is the line in the response.txt
MIB-2::ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.84 = OctetString: XYZ=2-A-1-L1-1
I wanted to extract "84" from the above line. The line from which "84" has to be extracted has to be queried using "XYZ=2-A-1-L1-1", (i.e) XYZ=2-A-1-L1-1 is known by me and I wanted to use it as a query to extract/parse "84" from the data response.
Is there a way to do this in iTest ??
Answer by Gokul R · Dec 14, 2010 at 11:41 AM
Attaching the screenshot to offer a better view.
Answer by PaulD · Dec 14, 2010 at 04:32 PM
Yes. You can use the following query to get what you're looking for:
//ifXTable/ifXEntry[ifName='XYZ=2-A-1-L1-1']/ifIndex
This says, "Find the ifXEntry row where the ifName column has value 'XYZ=2-A-a-L1-1' and then return the value of the ifIndex column."
Hi,
In an attempt to extract the value "37" in line 1 of the response.txt, I used the following syntax.
Command: eval --- set result [query snmp_issue //ifXTable/ifXEntry[ifName='DCHCTP=1-A-3-L1-1']/ifIndex]
Here, "snmp_issue" is the variable that holds the entire response and "result" is the variable that is supposed to hold the value "37".
But, I am seeing the following validation error. Can you please look into this ?
Unable to evaluate "set result [query snmp_issue //ifXTable/ifXEntry[ifName=DCHCTP=1-A-3-L1-1]/ifIndex]" : command ifName=DCHCTP=1-A-3-L1-1 is not registered
MIB-2::ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.37 = OctetString: DTPCTP=1-A-3-L1-1
I believe you would need to escape the inner [ ] brackets. Resulting in:
set result [query snmp_issue //ifXTable/ifXEntry\[ifName='DCHCTP=1-A-3-L1-1'\]/ifIndex]
The reason is that command substitution is happening so the interpreter is trying to evaluate query as a command (which is correct) and then is also trying to interpret ifName=... as a command (which is not correct.)
Still, there seems to be an issue with the query.
I used the following lines of code and got no response for the "puts" command.
Variables: snmp_issue (response.txt attached)
Command1: set result [query snmp_issue //ifXTable/ifXEntry\[ifName='TRIBPTP=1-A-3-L1-1'\]/ifIndex]
Response1: NIL
Command2: puts $result
Response2: NIL
I am attaching the test case herewith.
NOTE: I have queried the line 4 of the response.txt, so as to extract the value "40" and put it in the variable "result".
It's hard to tell from this what is going wrong. Please do the following:
Open the Structure view and select the appropriate step in your test case. Just as you are showing the Queries view in your screenshot, the Structure view will show all of the raw data available for analysis on that step. There is a button in the Structure view's toolbar that will toggle it between table view and XML view. In XML view, select all of the XML text there and post it here on the forum -- either as text or in an attachment, whichever is easier.
With this it will be easier to see what is going wrong with the query.
One question: when you saved the "snmp_issue" response in a variable, are you sure you are saving the full response and not just the response text? (There is a checkbox to control this.
I have contacted the customer and solved this issue.
Thanks Paul.
Copyright 2008- Spirent Communications, all rights reserved. Terms and Conditions.