How to Get and Set Properties during script assertions?
Hello all, I am looking for some help in order to get and set property values during a script assertion. I need to use them as part of a comparison during later steps to validate data is not changing throughout the test. The reason I am being forced to do this is that my JSON response seems to require the following import in order to parse the response: import groovy.json.JsonSlurper As I am sure many of you know, this is not supported during Groovy script steps so I am kind of stuck with where to go next. I will include an exampe of the JSON response below along with what I have been trying to use so far. The assertion passes, but data is not being saved as part of the ".setPropertyValue" line of code. You will also notice that I have two different possible ways of saving the data currently included. Neither of which seem to be working as expected. Thanks, Dave JSON Response { "items": [ { "price": 40, "total": 40, "consumerTotal": 40, "discounts": [], "productId": 1250, "addons": {"phonenumber": "6149995555"} }], "discountSum": 0, "grandTotal": 40, "consumerDiscountSum": 0, "consumerGrandTotal": 40, "orderType": "airtime" } Assertion Code import groovy.json.JsonSlurper def ResponseMessage = messageExchange.response.responseContent def jsonSlurper = new JsonSlurper().parseText(ResponseMessage) def price = jsonSlurper.items[0].price def total = jsonSlurper.items[0].total def consumerTotal = jsonSlurper.items[0].consumerTotal //def discount = jsonSlurper.items[0].discounts[0].amount def discountSum = jsonSlurper.discountSum def grandTotal = jsonSlurper.grandTotal def consumerDiscountSum = jsonSlurper.consumerDiscountSum def consumerGrandTotal = jsonSlurper.consumerGrandTotal messageExchange.modelItem.testStep.testCase.getTestStepByName("Estimate").setPropertyValue("EstimateItem1Price", "price") def EstimateItem1Price = price log.info (EstimateItem1Price) log.info (price) assert grandTotal == price assert consumerGrandTotal == price assert discountSum == 0 assert grandTotal == total assert consumerDiscountSum == 0 assert price - discountSum == total assert grandTotal == price - discountSum assert consumerGrandTotal == price - consumerDiscountSum assert consumerGrandTotal == grandTotal assert context.response, 'Response is empty or null' def json = new groovy.json.JsonSlurper().parseText(context.response) log.info (json.items.price) context.testCase.setPropertyValue('EstimateItem1Price', json.items.price.toString())3.4KViews0likes1Commentscript assertion
i need to validate many assertions in same script assertion. But when any one of assert fails, runner stops there itself and control passed to next step. Below is my case assert (1 ==1) log.info "1" assert (1 == 2) log.info "2" assert (1 ==3) log.info "3" When i execute the above, 2nd assertion fails and third assertion did not executed at all. Is there is any way to validate all assertions.1.4KViews0likes2Comments