Hi, I'm new to iTest. I have the following output:
CARD TYPE FSM STATE VISIBILITY LP INSTANCE
---- ---------- ----------------- ---------- -- --------
0 CPeE RunningAsActive OnLine 0 Active
1 CPeE RunningAsStandby OnLine 0 Standby
2 6mPktServSP RunningAsActive OnLine 2 Active
3 6mPktServSP RunningAsActive OnLine 3 Active
4 6mPktServSP RunningAsActive OnLine 4 Active
5 6mPktServSP RunningAsActive OnLine 5 Active
8 16pOC3SmIrAtm RunningAsActive OnLine 8 Active
9 16pOC3SmIrAtm RunningAsActive OnLine 9 Active
And I'm attempting to determine which Card has Type CPeE and FSM_State as RunningAsActive. I suspect it's some use of "foreach" but I can't wrap my head around it. Any help would be appreciated.
Thanks.
Answer by KumarS · Sep 17, 2009 at 08:42 PM
Here is an example on how to do it. You will see that there are other examples very similar to yours on this forum.
Basic concept is the following:
1. You have a table or some other unstructured data.
2. You use a response map to transform this data into XML. You can see this XML data in Structure view of iTest.
3. You use XPATH queries to extract data from the XML.
Typically to make it easy for #3, response map writer creates these aliases called Queries which are shown in Queries view so that user of the response map does not have to craft an XPATH query all the time. iTest itself generates some of the commonly used ones by default. But for anything like yours where you want the value of one column based on two or more columns, you have to write your own XPATH.
Let me know if you need further help. Save the files in any project directory and you can simply run the testcase to see the results.
Another example of using table map. In this one, we store the result of the query and loop over it. You can add arguments to your custom query so that the "TYPE" and "FSM" state can be passed in rather than hardcoded in the response map.
-Amish
Hey, I'm back.
I had it working with the following query:
//row[TYPE="CPeE" and FSM_STATE="RunningAsActive"]/CARD
but now I need to use a global parameter defined in the testbed for the TYPE. I've tried the following to no avail:
//row[TYPE="[param CPe_Type]" and FSM_STATE="RunningAsActive"]/CARD
//row[TYPE=[param Cpe_Type] and FSM_STATE="RunningAsActive"]/CARD
//row[TYPE="$CPe_Type" and FSM_STATE="RunningAsActive"]/CARD
//row[TYPE=$CPe_Type and FSM_STATE="RunningAsActive"]/CARD
It's got to be something simple...what am I missing?? I'm spending WAY too long on this...
Thanks,
Nim
The problem here is that XPATH (the language used for querying information) and substitutions (like Tcl) use overlapping symbols -- like square brackets.
Because of this, by default, the query does not support substitution so that, for example, there is no problem using [ ] in the middle of the xpath query. But if you need to use substitution (like [param foo]), then you need to turn on substitution for the query and then you need to "escape" any special characters in the xpath query that are not intended for substitution. So you'll end up with something like this:
//row\[TYPE="[param CPe_Type]" and FSM_STATE="RunningAsActive"\]/CARD
The square brackets in the query now have backslashes in front of them.
Copyright 2008- Spirent Communications, all rights reserved. Terms and Conditions.