简体   繁体   中英

Json request validation in Jmeter

As my json request contains all mandatory parameters in request body, I want to validate all parameters using Jmeter.

Do let me know if it is possible to validate all request parameters presents in json body using jmeter or jmeter plugins

Normally people are interested in validating responses , not the requests therefore I am not aware of any suitable Test Elements either bundled or available via Plugins. For responses validation you have JSON Path Assertion

If for some reason you need to validate the request and fail the sampler if the validation fails you can use JSR223 Post Processor . Example code:

def request = sampler.getArguments().getArgument(0).getValue()
def json = new groovy.json.JsonSlurper().parseText(request)

// do any checks you need, for example 

if (!json.keySet().contains("somekey")) {
    log.info("Key \"somekey\" was not found in the request")
    prev.setSuccessful(false)
} 

References:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM