0

I have a csv file which has the input in the below format (It has no headers as first row):

India,QA,1200,
India,QA1,1201,
India,QA2,1202,
USA,Dev1,5580,
USA,Dev2,5580,
AUS,Dev3,3300,
AUS,Dev4,3301,

I have configured the CSV Data Set Config component and have given the respective path and variable name details. Snapshot below:

enter image description here

from the command line argument, i will be invoking the Jmeter jmeter.bat -t C:\Users\Dev\Desktop\JI\testscript.jmx -JCountry=Indiawhich also has a parameter called JCountry=India.

Now, I have to use this value (India) and then search the csv file's first column and if it matches, I need to send only those particular rows matching to the country name given from the cmd to the script.

I thought of using If Controller but how can I check the csv files first row and when there is a match, send those details to the script.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
sdgd
  • 723
  • 1
  • 17
  • 38

2 Answers2

2

The easiest option would be dynamically generating a CSV file with only India lines

  1. Add setUp Thread Group to your Test Plan
  2. Add Test Action sampler to the setUp Thread Group (this way you won't have an extra result in .jtl file)
  3. Add JSR223 PreProcessor as a child of the Test Action Sampler
  4. Put the following code into "Script" area:

    String country = props.get('Country')
    
    def originalCsvFile = new File('C:/Users/Dev/Desktop/JI/JVMDetails/Details.txt')
    def countryCsvFile = new File('C:/Users/Dev/Desktop/JI/JVMDetails/Country.txt')
    
    countryCsvFile.delete()
    
    originalCsvFile.eachLine {line ->
        if (line.startsWith(country)) {
            countryCsvFile << line
            countryCsvFile << System.getProperty('line.separator')
        }
    }
    
  5. Configure your CSV Data Set Config to use C:\Users\Dev\Desktop\JI\JVMDetails\Country.txt as this file will have only those lines which start with what you have defined as Country property

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
1

You need to loop through CSV, see example or other examples. As the second example use in while condition the variable from CSV: ${Country} .

Inside loop you need to add If Controller with condition to compare country variable against country property:

 ${__jexl3("${__P{Country}" == "${Country}")}

Checking this and using __jexl3 or __groovy function in Condition is advised for performances

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I am using a While Controller having the condition set as `${__P{Country}` , next have the CSV file clubbed to it and then to that using an IF Controller having the condition as `${__jexl3("${__P{Country}" == "${Country}")}`. how will only those particular lines of the csv files go further. will this be sufficient ? – sdgd Nov 22 '17 at 04:37
  • As the second example use in while condition the variable from CSV: `${Country}` . Using property will return always true and will loop forever – Ori Marko Nov 22 '17 at 05:24