0
votes

I'm trying to do a POST request test loop and set a particular variable in the request that is based on results of previous responses (specifically the last 200). For instance, if X appears 5 times in the last 200 responses, the variable = 2. If X appears 10 times in the last 200 responses, the variable = 6, and so on. I've already extracted the X value with RegEx extractor and have it exported to a CSV data file, if that helps.

Thank you.

1

1 Answers

0
votes

If you have a CSV file with 5 or 10 (or whatever number) lines of X and want to conditionally set another variable value I would suggest going for the JSR223 Sampler with the code like:

def entries = 0

new File("/path/to/your/file.csv").eachLine {
    entries++
}

switch (entries) {
    case 5:
        vars.put("myVar", "2")
        break;
    case 10:
        vars.put("myVar", "6")
        break;
    //etc.
    default:
        vars.put("myVar", "0")
}

It will count the number of lines in the csv file and set ${myVar} variable value based on it.

  • vars stand for JMeterVariables class instance, it provides programmatic read/write access to the JMeter Variables
  • File.eachLine() is a Groovy enhancement over normal JDK File class
  • switch statement should be self-explanatory

See Groovy Is the New Black guile for more information on Groovy scripting in JMeter.