Priyanka Soni
Priyanka Soni

Reputation: 11

Unable to add strings in JSR223 postprocessor

I am writing below code in JSR223 Post processor

def my_number = vars.get("Initial_file_count").toInteger(); //convert to int type
def new_number = 3;

def add = my_number + new_number;

vars.put("MY_NUMBER", add.toString());

log.info(my_number);

Upvotes: 0

Views: 560

Answers (1)

Dmitri T
Dmitri T

Reputation: 167992

Your code is more or less fine apart from the last line which needs to be changed to something like:

log.info('My Number: ' + add);

because log.info() function expects only Strings as arguments so you either need to use string concatenation or toString() method of the provided object.

Demo:

enter image description here

More information: Top 8 JMeter Java Classes You Should Be Using with Groovy

Upvotes: 1

Related Questions