Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
Getting below error when i run the jmeter script having Beanshell Post Processor as a child to a sampler.
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method:
eval Sourced file: inline evaluation of:
``try { newuser=
vars.get("prevUsrResponse"); org.json.JSONObject userJSON= new o . . .
'' : Typed variable declaration : Class: org.json.JSONObject not found
in namespace
Below is the code written and run in jMeter 2.9.
newuser= vars.get("prevUsrResponse");
org.json.JSONObject userJSON= new org.json.JSONObject(newuser);
if(prevUsrJSON.has("User") && custJSON.get("User")!= null) {
org.json.JSONObject contactJSON = userJSON.getJSONObject("User");
contactJSON.put("UserType","Private");
vars.put("updatedUser", userJSON.toString());
${updatedUser}
variable doesn't return the json(or any value) when used in the next sampler request.
Download the jar i.e. from the Maven central repo
Copy it to JMeter's "lib" folder
Restart JMeter to pick the .jar up
You dont have the relevant import line. Add it to the beginning of your script:
import org.json.JSONObject;
You can also consider upgrading to JMeter 3.0 which comes with built-in JSON support and provides JSON Path PostProcessor to extract data from JSON responses. If you still want Beanshell - it is also possible, just use json-smart classes
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.