Bean shell post processor in jmeter

In that bean shell prost processor we can check what is the response code we got from the http request .

We can also get the response header from the request and response data as well.

System.out.println(ctx.getPreviousResult().getResponseCode());
System.out.println(ctx.getPreviousResult().getResponseHeaders());
System.out.println(ctx.getPreviousResult().getResponseDataAsString());

We can even print all the above 3 things i.e code ,header and body in logs by using the below commands

log.info(ctx.getPreviousResult().getResponseCode());
log.info(ctx.getPreviousResult().getResponseHeaders());
log.info(ctx.getPreviousResult().getResponseDataAsString());

We can open log viewer by going to options and then clicking log viewer .

We can even add if else statement to pass or fail a test in bean shell post processor like this

String message = prev.getResponseMessage();
int num = ctx.getThreadNum();//get thread number

// In the if statement we can check if Response Message is ok then print pass else print fail.
if(message.equals("OK")){
log.info("The thread number " + num + " has passed");
}
else{
log.info("The thread number " + num + " has failed");
}