SOATest: Use of datasource column names in the XPath editor
I have the below JSON response where I need to assert the statusCode for a particular name and this name is getting fetched from the 'name' column in the excel sheet used as a datasource.
JSON response:
[
{
"clientTypeCode": "IP",
"statusCode": "PEND",
"statusName": "Pending Approval",
"id": 0,
"name": "test1"
},
{
"clientTypeCode": "IP",
"statusCode": "PEND",
"statusName": "Submitted",
"id": 0,
"name": "test2"
}
]
For this one when I used a JSON Assertor and added a Value Assertion for the statusCode element and using XPath changed the element to as below:
/root/item[name='test1']/statusCode/text()
Clicked on Evaluate XPath and it showed the right status in the Result section.
But my question is-Is there a way I can change the above XPath query to use the column name ('name') from the excelsheet(datasource) instead of using 'test1'.
For ex something like as below:
/root/item[name=${name}']/statusCode/text()
Any help is much appreciated!
Thanks!
Best Answers
-
The "Evaluate" button in the UI will not properly evaluate the data source column, but SOAtest should still evaluate it properly at runtime. Have you tried running the test to see if the Xpath works as you expect at runtime?
5 -
Yes, the Evaluate button doesn't show the expected result whenever variables are used. The main reason is that it's not always possible for SOAtest to know a correct value for the test variable when not running a test, since the variable value may need to get retrieved from an external system like a database or from a response payload by a data bank tool.
5
Answers
-
Some more information:
I've tried parameterizing the Xpath using the data source column but when I evaluate Xpath it shows "No nodes found". I am using SOATEST 9.9.
/root/item[name=${name}']/statusCode/text()0 -
Additionally, the XPATH you are showing here in chat is malformed, as there is a singular ' after ${name} that might be causing your issue.
Can you try using:
/root/item[name=${name}]/statusCode/text()
?0 -
Thanks Thomas and jakubiak. Sorry for the missing single quote in my Xpath expression. I've used below Xpath and for all of them it says "No nodes found":
/root/item[name="${name}"]/statusCode/text()
/root/item[name='${name}']/statusCode/text()
So I ran this time and during runtime it did run fine. So looks like Evaluate button in Xpath editor doesn't show the right results always.0