Search code examples
javascriptjavajmeterbeanshell

How to pass the java script into Jmeter script?


My requirement needs to generate the Dynamic year value from 1980 to 2016.

We are written the random java command for this requirement. But unable to pass through the jmeter script.

May I know how to pass the value through the jmeter script for this we need to use any sampler or else how to convert the java script into beanshell?

Year should generate dynamically.


Solution

  • Min Year: (store value into minYear variable, to refer it later)

    ${__Random(1980,2006, minYear)} 
    

    Max Year: (using minYear, calculated maxYear value. you can refer it later using ${maxYear}

    ${__intSum(${minYear},10,maxYear)}
    

    Reference: enter image description here


    No need of JavaScript.

    Try using __Random function as follows:

    ${__Random(1980,2016)}
    

    will return a random number between 1980 and 2016

    Optionally, you can save the value into a variable and refer it later.

    ${__Random(1980,2016, MyVar)}
    

    will return a random number between 1980 and 2016 and store it in MyVar. access it later using ${MyVar}