Robert Strauch
Robert Strauch

Reputation: 12906

Parsing CSV by column in JMeter

Given a CSV file with some data arranged in columns instead of rows:

Parameters;Data Set 1;Data Set 2
param_1;A;1
param_2;B;2
param_3;C;3
param_4;D;4
param_5;E;5

Is it possible to use this as a "CSV config element" in JMeter? For sure it won't work with the standard config elements but maybe there is another way?

Upvotes: 0

Views: 1676

Answers (3)

kcsurapaneni
kcsurapaneni

Reputation: 812

In CSV Data Set Config write the names of the parameters in Variable Names(comma-delimited) with , separation. (like Parameters,DataSet1,DataSet2).

Set the Loop Count for the Thread Group as the number of lines you have to read.

Now you will get the values by accessing the variables ${Parameters}, ${DataSet1}, ${DataSet2}.

Upvotes: 2

sara
sara

Reputation: 1170

CSV config element cannot do this. You should use a BeanShell Sampler or JSR223 Sampler to read the file and process each line. Here is a simple Java code for BeanShell sampler:

BufferedReader br = new BufferedReader(new FileReader("filename"));
String line = br.readLine();
while (!line.isEmpty()) { 
    String parts = line.split(";");
    String paramName = parts[0];
    String dataSet1 = parts[1];
    String dataSet2 = parts[2];
    // save them in jmeter props or vars and use later
    line = br.readLine();
}

Upvotes: 2

Madhu Cheepati
Madhu Cheepati

Reputation: 879

Instead of "CSV config element", use "User Parameters" pre-processor, it will work as you expected. But you need to add values manually.

Upvotes: 0

Related Questions