0
votes

In my JMeter test plan, i have 3 transaction controllers. I want to extract the transaction controller name and pass it to the Jmeter script. I am unable to extract the transaction controller name, which is displayed into "Log viewer Panel".

To print transaction name , i have used BeanShell Listener, with following code :

String tname= sampleResult.toString();

if(tname.startsWith("T01_Login"))
{
log.info("*Transaction Name = " +sampleResult.toString() + " - Response time = " + sampleResult.getTime());
String temp = sampleResult.toString();
String temp2 = sampleResult.getTime().toString();
vars.put("Transaction_Name",temp);
vars.put("Response", temp2);
log.info(vars.get("Response"));
log.info(vars.get("Transaction_Name"));
}

I have used BSF post processor to store/extract the transaction name, by using following code:

Language selected in : Javascript

var transact = ${Transaction_Name};
vars.put ("TRANSACT",transact);
log.info(TRANSACT);

When checked into LogViewer panel, following text is displayed:

2017/03/27 17:06:13 INFO  - jmeter.util.BeanShellTestElement: *Transaction Name = T01_Login - Response time = 39829 
2017/03/27 17:06:13 INFO  - jmeter.util.BeanShellTestElement: 39829 
2017/03/27 17:06:13 INFO  - jmeter.util.BeanShellTestElement: T01_Login 

Kindly provide your valuable suggestion on this.

1

1 Answers

1
votes

To resolve the error which prevents post-processor from running, use vars.get, instead of var transact = ${Transaction_Name};, i.e.

var transact = vars.get("Transaction_Name");

And setting another variable (vars.put ("TRANSACT",transact);) is unnecessary: just use Transaction_Name. (And another small note: BSF set of objects is now deprecated, so switch them to either JSR322 or BeanShell)

But it will not work anyways, because the order of execution is

Sampler > Post-processor > Listener > Transaction Controller > Listener

So the value of Transaction_Name inside post-processor will either be empty (on first iteration), or will be coming from previous iteration, which I guess is not what you want.

You don't mention your use case, but some options you have are:

  1. Have a special sampler AFTER transaction controller to do what you wanted in that post-processor. For example:

    Transaction Controller
        Some Sampler 
        ...
    JSR223 / Beanshell sampler
    

    This second sampler can obtain proper transaction name, since it's running after the transaction

  2. Save transaction name into variable before calling a transaction. Set transaction controller name to that variable:

    JSR223 / Beanshell sampler 
      sets variable: vars.put("Transaction_Name", "T01_Login"); 
    ${Transaction_Name} <-- this is the name of the transaction controller
        Sampler
            Post-processor <-- here the Transaction_Name can be obtained.