0
votes

below are the steps i followed, 1) Added a BeanShell sampler and add a Bean Shell Preprocessor to the same sampler.

long c = 25478995L;
log.info(c + " - It is long");
vars.put("c",c)

2) I am trying to print the value c in Bean Shell sampler like below,

${c}

3) But when i see in view result tree i am getting the ${c} instead i am expecting to view 25478995.

Can any one help me please. Thanks in advance.

Regards, Hari

3

3 Answers

1
votes
  1. If you want to store a Long per se you need to use vars.putObject() function instead like:

    vars.putObject("c", c);
    

    and later on:

    log.info("My long value is: " + vars.getObject("c"));
    
  2. If you want to have String representation - you need to convert your Long to String first like:

    vars.put("c", Long.toString(c));
    
  3. Don't refer variables like ${c} in scripts, use vars.get("c"); or vars.getObject("c"); instead
  4. Since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language rather than Beanshell for performance reasons, see Apache Groovy - Why and How You Should Use It for more details.
0
votes

You need to convert long number to string in vars.put method . There are 2 approaches you can do this

You can use String.valueOf() method to do that

long c = 25478995L;
vars.put("c",String.valueOf(c));

Or simply you can append the long value to a string.

long c = 25478995L;
vars.put("c",c+"");

You can follow this blogs for such information

0
votes

You can use the below:-

BeanShell PreProcessor

long c = 25478995L;
log.info(c + " - It is long");
vars.put("x",c.toString());

BeanShell Sampler

log.info("Value of x==="+vars.get("x"));