Forum Discussion
Actually there was a bit of confusion for me from below statements of yours.
[Statement 1]
So if attribute1 = valueX, assert attribute2 = valueY, if attribute1 = valueZ, assert attribute2 = valueA - so I think the basic if/then/else isn't a problem - but it's getting it to work on repeating attributes.
[Statement 2]
I want to assert that every instance of 'RegistrationFromDate' is 29th March when 'GeographyIndicationStatusId_Name' is 'Registered' and 'RegistrationFromDate' is null for all other scenarios
So, I thought date can be possible to change between responses and that's why I gave that "equals to one". But, that holds still true (irrespective of expected value i.e., null or a date)
If you still want to verify along with values as well, then use below snippet of code and pass the values.
Here there another advantage is that you change sibling property names / attributes or keys and their values i.e., works generic.
//assumes json object is defined already def areAllSiblingValuesMatching = { key, value, condition -> def actalValues = json.data.findAll(condition).collect {it."$key"}.unique() (1 == actalValues.size() && value == actalValues.first() ) ? true : false } //verify date value and status name is Registered assert areAllSiblingValuesMatching('RegistrationFromDate', '2019-03-29 00:00:00.000'){ it.GeographicalIndicationStatusId_Name == 'Registered'} //verify date value and status name is not Registered assert areAllSiblingValuesMatching('RegistrationFromDate', null){ it.GeographicalIndicationStatusId_Name != 'Registered'}
Hey nmrao
again my attempt at the code looked completely different to yours!
Thanks man - it works great - but I have a question - regarding the second assertion below
//Code courtesy of Rao
//assumes json object is defined already def areAllSiblingValuesMatching = { key, value, condition -> def actalValues = json.data.findAll(condition).collect {it."$key"}.unique() (1 == actalValues.size() && value == actalValues.first() ) ? true : false } //verify date value and status name is Registered assert areAllSiblingValuesMatching('RegistrationFromDate', '2019-03-29 00:00:00.000'){ it.GeographicalIndicationStatusId_Name == 'Registered'} //verify date value and status name is not Registered - THIS IS THE SECOND ASSERTION assert areAllSiblingValuesMatching('RegistrationFromDate', null){ it.GeographicalIndicationStatusId_Name != 'Registered'}
If there are no records in the dataset where GeographicalIndicationStatusId_Name != 'Registered - I get an assertion failure on this.
When I execute the step when the resultset DOES have >=1 row where GeographicalIndicationStatusId_Name != 'Registered' - the step PASSES
Is there something I can do to tweak this for scenarios where the resultset does NOT contain records where GeographicalIndicationStatusId_Name != 'Registered' ???
Thanks man - do you fancy a job? I need some help at my place! :)
cheers,
richie
- nmrao6 years agoChampion Level 3
What is expected in below case? Is the response expected to meet that condition?
If there are no records in the dataset where GeographicalIndicationStatusId_Name != 'Registered - I get an assertion failure on this.
Otherwise, it is ok not to have additional assertions which are not expected.
Related Content
- 2 years agoMarcusBengtsson
- 6 years agoJakemorley
- 6 years agoDainiusA
- 6 years agotrajmo
Recent Discussions
- 4 days agominhng