jmeterscripting-languagejsr223

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 ?


Solution

  • 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")