Aritro Sen
Aritro Sen

Reputation: 357

Problem in JSR223 script, JSR223 PostProcessor : javax.script.ScriptException

I am using Jmeter 5.0 where i have piece of java code written inside a JSR223 PostProcessor. The code is as follows -

import java.util.Map;
import java.util.HashMap;


Map gamePlayHistoryMap = new HashMap();
gamePlayHistoryMap.put(${playerId}, ${GameplayHistoryId});
props.put("GamePlayHistoryMap", gamePlayHistoryMap);

Map payLevelDetailsMap = new HashMap();
payLevelDetailsMap.put(${playerId}, ${PayLevelDetails});
props.put("PayLevelDetailsMap", payLevelDetailsMap);

However when i execute the test plan, in the console i get the following error -

javax.script.ScriptException: In file: inline evaluation of: import java.util.Map; import java.util.HashMap; Map gamePlayHistoryMap = new H . . . '' Encountered "( 107 , )" at line 6, column 23. in inline evaluation of:import java.util.Map; import java.util.HashMap; Map gamePlayHistoryMap = new H . . . '' at line number 6

Can someone help me in pointing where i might have gone wrong ?

Upvotes: 3

Views: 11064

Answers (3)

Leon Proskurov
Leon Proskurov

Reputation: 134

You are missing the Map key/value definition.

Map <String, String> gamePlayHistoryMap = new HashMap<>();
gamePlayHistoryMap.put(${playerId}, ${GameplayHistoryId});

Not sure about the answer of:

Don't use ${} in JSR223 scripts, use instead vars.get("")

not sure it has anything to do with it.

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 167992

  1. Since JMeter 3.1 you should be using groovy language for scripting, looking into your exception details it appears you're using java which is not real Java, it's Beanshell interpreter which has worse performance comparing to Groovy and you have to stick to Java 5 syntax.
  2. Don't inline JMeter Functions and/or Variables into scripts as they might be resolved into something causing script failures and in case of Groovy they conflict with GString templates and compilation caching feature. Use vars shorthand for JMeterVariables class to read existing variables values and create new ones, i.e. replace this line:

    gamePlayHistoryMap.put(${playerId}, ${GameplayHistoryId});
    

    with this one:

    gamePlayHistoryMap.put(vars.get('playerId'), vars.get('GameplayHistoryId'));
    

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58774

Don't use ${} in JSR223 scripts, use instead vars.get("") to get varibles

gamePlayHistoryMap.put(vars.get("playerId"), vars.get("GameplayHistoryId"));

It seems that GameplayHistoryId is empty, in such case add default value in JSONExtractor or fail test

See JMeter's best practices for JSR223 scripting:

In this case, ensure the script does not use any variable using ${varName} as caching would take only first value of ${varName}. Instead use : vars.get("varName")

Upvotes: 5

Related Questions