I want to write a code for Response assertion using groovy for one of the Request Giving Response data like this
{
"value":"200"
"value_description":"pass"
"value_code":"pass"
"data_encode":"uyt-09-0nbv"
}
after google Search i am getting only with Response Assertion SOAP-UI tools and i also checked with Blaze meter blog i am not understating about what they are saying. simple way i want demonstrate that.write code for Response Data Assert value for 200 is this possible. please help me to this stuff
The relevant Groovy code to check whether value
attribute in the response equals 200
would be something like:
def json = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def value = json.value
if (value != '200') {
AssertionResult.setFailure(true)
AssertionResult.setFauilreMessage('Expected 200, but got ' + value)
}
Cache compiled script if available
box and choose groovy
from the "Language" dropdown) More information:
You can add 4 JSON Extractor s, each with different Path Expressions:
$.value
, $.value_description
, $.value_code
, $.data_encode
It will assert that JSON parameter returned.
You can add Regular Expression Extractor s to check each variable you got using Apply to JMeter Variable
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.