2
votes

I am trying to use beanshell post processor so I have started with simple http request where I am hitting the google home page. "${url}"=="https://www.google.co.in". After http request page I am adding the BeanShellPostProcessor where in Script area I am using ctx variable and some other code which is like :

int threadNum = ctx.getThreadNum();
String code = prev.getResponseCode(); 
String message = prev.getResponseMessage();

log.info(threadNum);
log.info("This line has been written by Beanshell Post Processor");

so I have two concerns -

i.The way I am using beanshell is this right ?

ii.Where is the console for beanshell processor in jmeter? like sample request result can be viewed in listener. I tried with BeanShellListner, but it doesn't show any data. Also I have kept the "log viewer" on.

1

1 Answers

2
votes
  1. You are using it almost right, the only error is that you cannot write an integer to the log file, you need to cast it to String first like:

    log.info(String.valueOf(threadNum));
    
  2. You won't be able to see the result of pre and post processors anywhere apart from jmeter.log file. In case of PostProcessor you can modify parent sampler response data via prev.setResponseData() method where prev is a shorthand to SampleResult class instance

I would also recommend considering switching to JSR223 Elements and Groovy language as this way you will get better performance, out of box support of XML, JSON, etc., and other Groovy's "syntax sugar". See Groovy Is the New Black article for more detailed explanation.