Groovy script assertion to compare XML data
Thanks Rich,
Is it possible that one of you could help me with my issue? I'll post again:
NOTE: a Test step before this Test step(which I explain below) sets the polling interval (in this example to 10 sec).
1. Using an HTTP GET request call on a URL
2. The URL’s response is a list of events (<Event>) that have time stamps (<EventTime>)
3. These events, Event X, Event Y etc., are no more than polling events. So, if I send a polling interval for Event X to poll every 10 sec, then I want to verify that Event X is polling every 10 sec. Event Y could be polling at a different interval, no problem. I need to verify if I set the polling interval for Event X to be 10 sec, then when I send a GET on the URL, in the response I should see the time stamps for Event X to be 10 sec apart.
4. So, my Assertion should compare Event X with time stamp X and the next time that Event X polls the time stamp should be 10 sec from the previous Event X time stamp. Verifying polling interval was set correctly.
5. Example below shows there is a 10 sec diff between the Event X at 19:35:37.189 time and the same Event X at 19:35:47.24
<Response>
<e>
<Tplus>8201.19</Tplus>
<SinceLast>8.29</SinceLast>
<EventTime>2019-12-16T19:35:37.189</EventTime>
<Event>trapPATS-NE-MIB: patsConfigFileDownloadCompleteTrap"/test_lru_manifest.xml"XX.XX.XX.162</Event>
</e>
<e>
<Tplus>8211.24</Tplus>
<SinceLast>10.05</SinceLast>
<EventTime>2019-12-16T19:35:47.24</EventTime>
<Event>trapPATS-NE-MIB:patsConfigFileDownloadCompleteTrap"/test_lru_manifest.xml"XX.XX.XX.162</Event>
</e>
<Response>
6. Trying to verify the polling request was set correctly. If there is a better way than a groovyscript, please point me into that direction. But if the groovyscript is the way please provide code on how to do this and an explanation into what the code is doing, this way I can learn, until I can get more experience with groovy.
7. To start with, not sure if I should go to the end of the response file or parse through the entire response file?
Thanks, again, all help is greatly appreciated!
Hi TheEnd, please provide the details richie needs and the Community will see how to help you solve this!
Also, a lot of users are using the XPath Match assertion for XML validation, could this be something you are looking for?
And, there’s a code sample in our documentation for comparing XML’s. Maybe, you could try creating your own code based on that.