- Processing and handling JSON responses using BSF post processors
- Using BSF Assertion to fail samples based on JSON response
- Changing sample label/name at runtime
NOTE: I successfuly used this technique for webservices exposed by the Jersey library as well as ASP.NET asmx webservices
It's quite simple. Assuming you need to send POST request to the /login URI passing two parameters: email and password encoded as JSON, like this:
{ email: '[email protected]', password: 'mypassword' }
Just follow two basic steps:
Step 1 - Setting the "ContentType" http header attribute to "application/json"
- Add an HTTP Header Manager to your test plan;
- Add a new attribute: set name to "Content-Type" and value to "application/json"
Step 2 - Setting the JSON object as an unnamed http request parameter
- Add a HttpRequest sampler
- Add a new parameter, leave the name blank and set the value to the JSON string: { 'email': '[email protected]', 'password': 'mypassword' }
And last but not least: you can use variables and properties as you wish in the JSON string. Suppose you have a CSV Data Set Config which defines to external variables: email e pwd. You could use them in your sampler like this:
{ email: '${email}', password: '${pwd}' }