Parse a CSV after a PreProcessor script on JMeter

Viewed 265

I'm trying to create a performance test on JMeter where I need to have a variable number of parameters.

This is the CSV file I'm using, so in this case I need 2 variables

inputParameter,var
7,v5
-2,v8

I found that it can be done by using JSR223 PreProcessor so I tried using this script

 {
   BufferedReader reader = new BufferedReader(new FileReader("path"));
    String row = reader.readLine();
    String[] header = row.split(",");
    row = reader.readLine();
    String[] values = row.split(",");
    for (int i = 0; i < header.length; i++) {
        String name = header[i];
        String value = value[i];
        sampler.addArgument(name, value);
    }
}

This script creates the variables as it should and puts the value of the first row on it. But the problem I have is that I can't find a way to parse a CSV file after the script to change the varibales value.

I tried this

String value = "${"+name+"}";

But it does not get the value of ${imputParameter} that I get from the CSV Data Set Config, it just adds the value %24%7inputParameter%24%7

Is there any way to parse the CSV file after the script runs to modify the value of the variables created by it?

Thanks in advance!

2 Answers

Use vars

 String value = vars.get(name);

vars - JMeterVariables - e.g.vars.get("VAR1");

Unfortunately your explanation doesn't make a lot of sense (at least for me), going forward consider:

  1. Providing first 3 rows of your CSV file
  2. Configuration of your CSV Data Set Config
  3. Actual output of the HTTP Request sampler (Request -> Request Body) tab of the View Results Tree listener
  4. Expected output of the HTTP Request sampler
  5. Output of the Debug Sampler (Response Data -> Response Body tab of the View Results Tree listener)
Related