-1

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.

giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
Kavinkumar Muthu
  • 99
  • 1
  • 5
  • 14

2 Answers2

1

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}

Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • Here is my request [Please check this link to view my request ] [1]: https://i.stack.imgur.com/aD43n.png We already use the ${__Random(1980,2016, MyVar)} function but now new requirement is minyear and maxyear should be 10 year difference.In this cases we cannot use the ${__Random(1980,2016, MyVar)} function right? – Kavinkumar Muthu Feb 28 '17 at 10:56
  • you can keep min year as `${__Random(1980,2006, MyVar)}` (10 years less) and `maxYear` value as `${myVar}+10` . updated the answer. pls check. – Naveen Kumar R B Feb 28 '17 at 11:10
  • It's Working fine, I just insert the Random command in **JSR223 Sampler** it is fine or i need to mention in different sampler? – Kavinkumar Muthu Feb 28 '17 at 11:45
  • you can use it in any sampler. added image in the answer, where I used them as part of Debug Sampler `Name` field. just replace the actual values in the `Request` with expressions mentioned in the answer – Naveen Kumar R B Feb 28 '17 at 11:46
  • We mention in Debug sampler but it unable to call the min Minyear to request and in **JSR223 Sampler** is working fine it view result tree it showing fail status. can you tell any other sampler for this. – Kavinkumar Muthu Feb 28 '17 at 11:59
  • seriously, I am not getting what you are trying. the expressions given in the answer for minYear & maxYear will work in any sampler (remember, first `minYear` expression must be defined in the TestPlan as `maxYear` is dependent on that). please add screenshots to the question on what you tried and what you got – Naveen Kumar R B Feb 28 '17 at 12:03
  • Yes, Now it is working fine. i mentioned the random variable into the user parameters, Now it able to pass the random variables into the request. – Kavinkumar Muthu Mar 01 '17 at 10:01
1
  1. First of all JavaScript != Java, they are totally different languages

  2. Second, given you place your class (or library) in JMeter Classpath you should be able to call its methods from JSR223 Test Elements

  3. Third, JMeter provides __Random() function which can return an integer from the given range so you can generate a random year as simple as ${__Random(1980,2016,)}

    JMeter Random Function

See How to Use JMeter Functions posts series for more information on what can be done using Functions in JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • This is good But this is my code so how to pass the function ' period v_auth.PUBLICATION_YEAR year range is ${minyear} ${maxyear} ' And new requirement is Min year and Max year should be 10 year interval of time. In this cases i think we cannot use the Random variable i think – Kavinkumar Muthu Feb 28 '17 at 10:59
  • Plug in your creativity. Get an initial minimum date in `1980 - 2006` year range and get the matching maximum date using [__intSum() function](https://www.blazemeter.com/blog/how-use-jmeter-functions-part-iii). – Dmitri T Feb 28 '17 at 11:49