Compare two REST response and ignore some fields
to compare two json response i can use below function but in the current context response return some dynamic fields which will be unique every time, can some one please explain how we can handle this void compareResponse(def atcualresponse, def expectedREsponse){ def map1 = new JsonSlurper().parseText(atcualresponse) def map2 = new JsonSlurper().parseText(expectedREsponse) assert map1 == map2 }Solved4.4KViews0likes7CommentsHow 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.4KViews0likes1CommentJsonSlurplerGetting Error while Parsing the Json Response
I tried tocreate a groovy script to parse the JSON response to a variable using JsonSlurper. Though the response Json is in valid format, i am getting an error def responseContent = testRunner.testCase.testSteps["Neme fof the test step"].testRequest.response.contentAsString def Response = new JsonSlurper().parseText(responseContent) log.info Code Could some one please look into this issue provide me a workaround for this. Thanks in advance5KViews0likes20Comments