Reputation: 177
I have a Soap request which response returns a set of values under the same tag let's say
<PricelistDetails>
<ServicePricelistDetailInfo>
<cost>20</cost>
</ServicePricelistDetailInfo>
<ServicePricelistDetailInfo>
<cost>25</cost>
</ServicePricelistDetailInfo>
<ServicePricelistDetailInfo>
<cost>30</cost>
</ServicePricelistDetailInfo>
<PricelistDetails>
I'v created an Xpath assertion to assert the cost tag to a user defined variable:
/Envelope/Body/GetServicePricelistResponse/GetServicePricelistResult/ServicePricelistInfoList/ServicePricelistInfo/PricelistDetails/ServicePricelistDetailInfoList/ServicePricelistDetailInfo/cost ='${COST1}'
whilst COST1 is defined as below :
name : COST1
Value :[20,25,30]
but when running the test plan it is showing an assertion error
Note:
I 've created an Xpath extractor to test the assertion query and it returned all of the cost values from the response correctly
Upvotes: 0
Views: 517
Reputation: 167992
I would suggest putting your XPath query into XPath Extractor, adding Debug Sampler afterwards and checking the generated variables via View Results Tree listener, my expectation is that you will get something like:
cost=20
cost_1=20
cost_2=25
cost_3=30
cost_matchNr=3
So you will be able to use "normal" Response Assertion against these ${cost_1}
, ${cost_2}
and ${cost3}
variables.
If for some reason you need to go the "XPath way" - use the following XPath Expression in the assertion:
concat("[", //PricelistDetails/ServicePricelistDetailInfo[1]/cost, ",", //PricelistDetails/ServicePricelistDetailInfo[2]/cost, ",", //PricelistDetails/ServicePricelistDetailInfo[3]/cost, "]")="${COST1}"
Demo:
References:
Upvotes: 1
Reputation: 52665
Your expression will just compare each of values from returned array (20
, 25
, 30
) with [20,25,30]
like:
20 = [20,25,30] # false
25 = [20,25,30] # false
30 = [20,25,30] # false
and return false
as all comparissons failed, while you need to compare all of them at once:
[20,25,30] = [20,25,30] # true
I'm not sure that it's the best solution, but as last resort you can try
concat('[', string-join(//PricelistDetails/ServicePricelistDetailInfo/cost, ','), ']') = '${COST1}'
Upvotes: 0