Search code examples
loopscsvjmeter

Read csv value in loop controller Jmeter


I have a loop controller in thread groups to read one csv file and i want to read all line in this csv file. I config my thread group as below:

  • Loop Controller (4 times)
    • Read csv file (Recycle on EOF: False, Stop thread on EOF: True, Sharing mode: All threads)

I run this scenario with a number of threads: 2

  • With first thread, read the first line of CSV file

  • With second thread, read the second line of CSV file

After each loop, i got data from CSV file is not changed, so how can i read each line of csv (from 3rd line,...) after the loop?


Solution

  • You have to put CSV Data Set Config as a child of Loop Controller.
    It should work for you with CSV Data Set Config settings you specified. I create Test Plan:

    
        Thread Group
        Number of Threads = 2
            Loop Controller
            Loop Count = 4
                CSV Data Set Config
                Filename: ... (your csv-file here)
                Variable Names: number
                Delimiter: ,
                Recycle on EOF = False
                Stop Thread on EOF = True
                Sharing Mode = All threads
                JSR223 Sampler
                log.info(vars.get("number"));     // output ${number} variable values
    
    

    Each Loop my "CSV Data Set Config" reads line into a "number" variable.
    JSR223 Sampler print it's value to Log Viewer.

    My CSV file looks like

    1
    2
    3
    4
    5
    

    So, because of Recycle on EOF is FALSE, Stop thread on EOF is TRUE the first Thread read 4 lines in the loop and the second Thread read just one the 5th line and then stop.

    See the picture