2

I need to test rest api posting Json. I try to post Json Data by BeanShell PostProcessor using Jmeter. But BeanShell PostProcessor doesn't work or I couldn't write the right code.

My Json is : {"email":"[email protected]","password":"123"}

You can see in the pictures below what i did.

enter image description here

enter image description here

enter image description here

3 Answers 3

4

I think you wanted to make an http request on an api. Follow this steps.

  1. Open a new instance of JMeter
  2. Under Test Plan, add a HTTP Header Manager to set the content type by navigating to Test Plan > Add > Config Element > HTTP Header Manager. Add new value for Name = “Content-Type” and value = “application/json” (without quotes).
  3. Under Test Plan, add a thread group by navigating to Test Plan > Add > Threads (Users) > Thread Group
  4. Under Thread Group, add a sampler of type HTTP Request by navigating to Thread Group > Add > Sampler > HTTP Request
  5. You can add various listeners to the Thread Group. I prefer Results in Table/Tree by navigating to Thread Group > Add > Listener > View Results in Table

You can add JSON data manully like shown on the picture.

JMeter Http Request Parameters

There is a gist also

This gist includes BeanShell Post Processor Version

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much engincancan! It works for me! But I still need to use beanshell post processor. :)
I added the BeanShell version to the gist. Please check the second link. :)
Thank you engincancan!! It works! I am really happy! I couldn't think that would be very simple.
1

in.

There is a couple of problems with your Beanshell Sampler code:

  1. In Beanshell you need to escape quotation marks with slash like \"
  2. SampleResult.setResponseData method accepts byte array, not string.

So if you amend your Beanshell Sampler code as follows:

String dummyJson = "{\"email\":\"[email protected]\",\"password\":\"123\"}";
SampleResult.setResponseData(dummyJson.getBytes("UTF-8"));

everything should be fine from Beanshell perspective.

See How to use BeanShell: JMeter's favorite built-in component guide for more details on Beanshell scripting in Apache JMeter.

2 Comments

Thank you. I fixed BeanShell sampler code like you said. But i am still getting error, I think my BeanShell PostPocessor code has problem.
I don't know the specifics of what you need to send, but. 1. where getJSONObject method is defined? 2. Your "Dummy Post Request" server IP/Name section is empty. 3. Path should start from /
0

I have used Ralf Sternberg’s slim JSON parser for Java as it is described here.

This is maven dependency of it's current version:

<dependency>
     <groupId>com.eclipsesource.minimal-json</groupId>
     <artifactId>minimal-json</artifactId>
     <version>0.9.4</version>
</dependency>

Don't forget to add this library to Jemeter's lib directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.