Check previous test step for the existence of a value
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Check previous test step for the existence of a value
Hopefully this is something that is covered off in the existing functionality of Ready API.
I have a value in the results of Test Step B which is the Amount 742.50
<ns2:Rates>
<ns2:RateTotals>
<ns2:BuyTotal>
<ns2:Currency>AUD</ns2:Currency>
<ns2:Amount>742.50</ns2:Amount>
</ns2:BuyTotal>
I simply want to check - or 'Assert' - if the value 742.50 appears in a previous Test Step (i.e. it 'exists' in the previous test step results). I know how to do Existence check (true or false) out of the box but the previous step contains a list of all kinds of amounts like 800.00 and 200.00 and 595.00 etc.
- Labels:
-
Assertions
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@thatsthat, you can use XPath assertion, see
https://support.smartbear.com/readyapi/docs/testing/assertions/reference/property/xpath-match.html
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The issue is @KarelHusa the value can appear in a variety of positions .. there is not just 1 amount returned .. there are many .. so i am looking to match the current result 'anywhere' in the previous step's result.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
XPath assertions work exactly for such purpose.
An XPath expression like //ns2:BuyTotal/ns2:Amount = 742.50 should work for you.
ReadyAPI will help you declare namespaces and set up the XPath expression; please look at XPath Match docs for more detail.
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your suggestion @KarelHusa but here is an example of just one of the elements I want to inspect. You can see the [1] in the response .. but there are (in this example I am looking at) 7 entries I need to check to see if a match exists. Xpath (without writing a script) can only point to 1 value .. unless I am mistaken?
${AddService#Response#declare namespace ns2='http://xyz.com/schema'; //ns2:AddServiceResponse[1]/ns2:Response[1]/ns2:ServiceDetail[1]/ns2:TotalCost[1]}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you can use XPath predicates in your assertion, such as:
//ns2:BuyTotal/ns2:Amount[text() = 742.50]
will select the XML element amount with a value of 742.50.
You can also check the count of nodes:
count(//ns2:BuyTotal/ns2:Amount[text() = 742.50]) > 0
.
XPath gives you multiple options to select the node, see e.g. https://www.w3schools.com/xml/xpath_syntax.asp .
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your patience @KarelHusa .. I will need to do some more reading it appears (thanks for the URL you sent) .. I attempted to implement your graceful solution with the count .. but no luck:
count(//ns2:BuyTotal/ns2:Amount[text() = 742.50]) > 0
But to no avail .. the below is what I am using to match a 'single' amount record that is being returned .. but I can't get it to 'count' up all the records and find if > 0 of them = 742.50
${FastSearchPackage#Response#declare namespace ns2='http://www.xyz.com/gateway/fire/schema'; //ns2:SearchResponse[1]/ns2:Response[1]/ns2:Suppliers[1]/ns2:Supplier[1]/ns2:Products[1]/ns2:Product[1]/ns2:Rates[1]/ns2:RateTotals[1]/ns2:BuyTotal[1]/ns2:Amount[1]}
I get a 1 for 1 match .. i tried adding count blah blah but could not land the correct answer!!
I did also try with an 'Count' xpatj expression
declare namespace ns2='http://www.xyz.com/gateway/fire/schema';
${FastSearchPackage#Response#declare namespace ns2='http://www.xyz.com/gateway/fire/schema'; //ns2:SearchResponse[1]/ns2:Response[1]/ns2:Suppliers[1]/ns2:Supplier[1]/ns2:Products[1]/ns2:Product[1]/ns2:Rates[1]/ns2:RateTotals[1]/count(ns2:BuyTotal[1]/ns2:Amount[text()=742.50])>0}
But no joy.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
relying on a fixed position (using indexes in your XPath) in XML may be fragile. Next time you may get additional elements, and your XPath will no longer work.
That's where a query helps.
What kind of response do you get if you test the following expressions:
//ns2:BuyTotal/ns2:Amount[text() = 742.50]
count(//ns2:BuyTotal/ns2:Amount[text() = 742.50]) > 0
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The thing is .. this does not point to the test step I need to collect the information from .. so I believe I am not constructing the message correctly ..
count(//ns2:BuyTotal/ns2:Amount[text() = 742.50]) > 0
So i get:
The XPath Match assertion failed for the following path: [declare namespace ns2='http://www.xyz.com/gateway/fire/schema'; declare namespace env='http://www.w3.org/2003/05/soap-envelope'; //ns2:BuyTotal/ns2:Amount[text() = 742.50]]. Expected value: [394.50]; Actual value: [].
