Jmeter beanshell: get variable type

Examples:

if (vars.get(“price_matchNr”) instanceof Integer){
log.info(“integer”);
}
if (vars.get(“price_matchNr”) instanceof String){
log.info(“string”);
}
if (Integer.parseInt(vars.get(“price_matchNr”)) instanceof int){
log.info(“int”);
}
if (Integer.valueOf(vars.get(“price_matchNr”)) instanceof Integer){
log.info(“Integer ValueOf”);
}

Log integer in beanshell and get integer from variables

Issue:

log.info() returns the following error in JMeter beanshell:

 Error in method invocation: Method info( int ) not found in class'org.apache.logging.slf4j.Log4jLogger'

Solution:

The error message indicates you are trying to pass an integer in the log.info() method. To prevent this issue, convert the integer to the type String using:

String SomeString = new Integer.toString(somInteger);

Similarly, numerals are passed as strings in JMeter variables, to make arithmetic operation on them, you’ll need to convert them to integer using:

int someInteger = new Integer.parseInt(someString);

Example use:

vars.put("test", new Integer(i).toString());