Forum Discussion

TheEnd's avatar
TheEnd
Occasional Contributor
5 years ago
Solved

Groovy script Assertion

Below is a sample from an XML file from my Response window of my project. I need to create a groovy assertion that will parse through the XML response file and compare the "Event" (looking for the sa...
  • richie's avatar
    richie
    5 years ago

    Hey TheEnd 

     

    Ok - firstly - I need to point out - I'm not the best person to comment on this - my groovy is nowhere near as good as the other peoples on here (like avidCodernmrao etc. - they'll be able to do this far quicker than I can. 

    I think I can probably work it out - I've already found a groovy time method that you might need - but the coders I mentioned above would probably do this in pure groovy - whereas what I'd do is extract the values from the response, save them to a properties step and use some groovy (that Rao gave me actually!) to compare the 2 values against each other - the complication with this is that time isn't decimal (I think the phrase is sexagesimal - but dont quote me) - so during the comparison I still need to treat the extracted values saved in the property files as time values and not strings (property values are stored as strings).

     

    I'll start working on this tomorrow - but by the time I've worked out an answer avidCoder or nmrao  will have likely worked out the answer between coffee breaks - for me it'll probably be a days work.

     

    Actually I've changed my mind - I think pure groovy is probably easier

     

    Couple more questions to help guide:

    Q1.  The response - are you saying for Event=x (where polling interval = 10secs) - the response will have numerous records contained - 1 record for each 10second interval since the initial call was made? - cos this makes it more awkward - you'll need to assert that EVERY record is 10 seconds greater than previous - I haven't got any bright ideas on how to do this at this point - maybe extract the lot into an array and parse that - but even then - this is gonna be a problem - every day has 8640 10second intervals - does this mean if you don't run your test for a day - you're gonna have a response with 8640 individual records (considring there's 86400 seconds in a day)?

    OR - are you content considering typical extrapolation rules (number of extrapolates to determine a pattern) maybe only 4 data points is enough to assert against?

     

    WOW! - you really didn't start with an easy one - did you? ;)

     

    As I mention above - I can probably work out how to assert that one eventtime is 10seconds greater than previous but depending on your answer to Q1 - this might exclude me from helping out - leaving it to the other fellas/ladies on here

     

    nice one,

     

    rich