Forum Discussion

jpalmiero's avatar
jpalmiero
New Contributor
11 years ago

Creating Assertions on RESTful url parameters

All,

We have a test step which is a RESTful request. the request looks something like this

GET https://somehost.somedomain.com/MarketD ... ata?req=Q&symbols=IBM%2CMSFT&qryOpts=

(NOTE, you can reqeust a comma seperatated list of stock quotes. in the example above, it is IBM,MSFT)

The result that we get back is XML with quote data:

<rjmktdata>
<quote rj_symbol="IBM" rj_typSpcl="Common Stock" .../>
<quote rj_symbol="MSFT" rj_typSpcl="Common Stock" .../>
</rjmktdata>


What we would like to do is ASSERT that we have as many quotes in the incoming response as we do in the outgoing request. If this was a SOAP reqeust, then it would be fairly straight forward to write the ASSERTION as xpath comparing the count of the ticker symbols in the request with the count of the response.

Does anyone know how do do this with a RESTful reqeust (ie count the URL parameters and compare them to the count of the elements in the response.)

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    What you can do is use a Groovy test step to assert that the number of stock quotes in the response is equal to the length of the quote list in the request. Counting the number of elements in the request list can be done using the split() method in Groovy's String class.

    Regarding how to easily parsing XML in groovy, I recommend this link - http://www.robert-nemet.com/2011/11/gro ... oapui.html

    I hope this is enough to get you started. Let me know if you have any further questions.

    Regards,

    Arian
    SmartBear sweden