java - How can we validate json based on key value pair in Jmeter -
i haved worked around jmeter load testing. focusing on api automation.
reading file csv endpoints , response expected, challenge facing whether how validate json based on key value pair, can validate data in interested , not whole json body.
in java using eclipse can using below method:
jsonobject obj1=null,obj2=null; obj1=new jsonobject(actual); obj2=new jsonobject(required); iterator<?> keys = obj2.keys(); while( keys.hasnext() ) { string key = (string)keys.next(); if(obj2.get(key) instanceof jsonarray) { if(!comparejsonarray(obj2.getstring(key),obj1.getstring(key))) {return false;} status=true; }else if(obj2.get(key) instanceof jsonobject) { if(!comparejson(obj2.getstring(key),obj1.getstring(key))) {return false;} status=true; }else{ if(obj2.getstring(key).equalsignorecase(obj1.getstring(key))) { status=true; } else{ return false; } }
how can following in jmeter. please help
you can use json path assertion validate json responses using json path language expressions.
json path assertion can installed using jmeter plugins manager
another option using jsr223 assertion , groovy language. groovy java-compatible should able re-use existing java code. alternatively aware groovy has built-in json support can re-implement json comparison logic using groovy style scripting.
Comments
Post a Comment