JMeter Beanshell assertion

This article is used to record the problems encountered in writing beanshell assertions.

Question 1: JSONObject not found in namespace

Process: Write the code under beanshell as follows:

1 String response_data = prev.getResponseDataAsString();

2 JSONObject data_obj = new JSONObject(response_data);
3
4 String current_page = data_obj.get("data").get("current_page").toString();
5 log.info("The current page:"+current_page)

Error: Typed variable declaration: Class: JSONObject not found in namespace

The content of the error report is very clear. No JSONObject was found in the namespace. But I am using it, and I must report an error.

Solution: Click to download the jar package and put it into the jmeter installation directory/lib/ext. Then write in beanshell: import org.json.*; Just quote it

1 String response_data = prev.getResponseDataAsString();

2 JSONObject data_obj = new JSONObject(response_data);
3
4 String current_page = data_obj.get("data").get("current_page").toString();
5 log.info("The current page:"+current_page)

Leave a Comment

Your email address will not be published.