Ar2r
Ar2r

Reputation: 55

JMeter Problem with the variable in JSR223 PreProcessor

I send POST request with the following JSON in body data

enter image description here

The problem is that the unixTimeValue variable is not setting

This is how my JSR223 PreProcessor looks like enter image description here \

Upvotes: 0

Views: 1071

Answers (2)

Dmitri T
Dmitri T

Reputation: 168072

  1. You can change your lines 1-14 to:

    vars.put("RANDOM_STRING", org.apache.commons.lang.RandomStringUtils.randomAscii(12))
    

    See RandomStringUtils class JavaDoc for more potentially useful functions

  2. Change your line 20 to:

    vars.putObject("unixTimeValue", sin);
    

    as vars.put() function accepts only Strings while vars.putObject() accepts pretty much everything, see JMeterVariables class JavaDoc for more details

  3. Since JMeter 3.1 you should be using Groovy language for scripting mainly because Groovy has much better performance comparing to Beanshell, see Apache Groovy - Why and How You Should Use It article for comprehensive explanation with examples

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58772

vars hold String values, you can convert your double when putting value:

vars.put("unixTimeValue", String.valueOf(a));

Upvotes: 1

Related Questions