Hi _elgato,

The foreach controller looks for the specified variables with a number
appended (with an optional '_').
The idea is to name your data columns the same. I would recommend
doing this in the file rather that on the CSV config item as it means
you don't need to update the variable names, it reads them from the
column names.
Each iteration of the loop the current value is mapped to the variable
name specified in the foreach controller.

I've just run a quick test and it seems to work as you described you require.
The below execute 5 iterations of the foreach loop. Reducing the
number of entries in the file reduces the number of loops without any
changes to the script.

CSV file:

user,data_1,data_2,data_3,data_4,data_5
user1,user1-1,user1-2,user1-3,user1-4,user1-5

ForEach Controller:
Input Variable Prefix: data (from the column name above, could be anything)
Output Variable Name: testData (this is where the output is mapped to,
updated on each iteration)
Add "_" before number: checked (in this case as we have an underscore
before the number)

then use ${testData} (or vars.get('testData') ) where ever you need the value.

Hope that clears things up for you.


Cheers,
Owen

On Sat, 25 Apr 2020 at 21:03, _elgato <[email protected]> wrote:
>
> Hi Owen,
>
> I couldn't find information about this. Do you mean setting the Input
> variable prefix as "COLUMN" or "COLUMN1, COLUMN2,..., COLUMNN". Or
> maybe setting the CSV file with column names "COLUMN_1, COLUMN_2,
> COLUMN_3," etc
>
> By the way, I recognize I did not explain that part very well. The CSV
> file will always have the same number of column, but I want to be able
> to run the testplan with a CSV file with 4 columns, later changing the
> CSV file to another one that would have 8 columns, etc.
>
> Could you explain how to set the input fields part?
>
> Thanks a lot for your help.
>
> On Sat, Apr 25, 2020 at 3:11 AM Owen Pahl <[email protected]> wrote:
> >
> > Hi _elgato,
> >
> > Why not name your data columns as per the input fields for the foreach loop?
> > https://jmeter.apache.org/usermanual/component_reference.html#ForEach_Controller
> >
> > Although you would need to see how well the CSV Data Set Config
> > handles variable number of rows, I would think (hope?) that it sets
> > the empty ones as null.
> >
> >
> > Cheers,
> > Owen
> >
> > On Sat, 25 Apr 2020 at 06:32, _elgato <[email protected]> wrote:
> > >
> > > Hi Antonio,
> > >
> > > the csv consists of 20 lines with some columns and I need to send an
> > > HTTP request with the same user for each column, that's why I cannot
> > > use a csv file with only one column.
> > >
> > > Regards.
> > >
> > > On Fri, Apr 24, 2020 at 5:30 PM Antonio Gomes Rodrigues
> > > <[email protected]> wrote:
> > > >
> > > > Hi,
> > > >
> > > > Why you don't compute your csv file to generate a new csv file with one
> > > > variable by line?
> > > >
> > > > After you can use the new csv file in a "CSV Data Set Config" with "Stop
> > > > thread on EOF?" parameter to true
> > > >
> > > >
> > > >
> > > > Le ven. 24 avr. 2020 à 17:25, _elgato <[email protected]> a 
> > > > écrit :
> > > >
> > > > > Hi again,
> > > > >
> > > > > I was finally able to do this using a JSR233 Sampler with the
> > > > > following parameters:
> > > > >
> > > > > ${__split(${__StringFromFile(C:\test.csv)},LIC)};
> > > > >
> > > > > Which will read a line from C:\test.csv, split it each comma and save
> > > > > a list in the LIC variable. However I don't think this is a good
> > > > > practice and would like some input if possible.
> > > > >
> > > > > I would like to create a script that will read a line from the csv,
> > > > > split it each comma and save an array in a variable which will be used
> > > > > later in a ForEach controller.
> > > > >
> > > > > This is the JSR233 sampler: https://i.stack.imgur.com/OwBDq.png
> > > > > Here is the ForEach controller: https://i.stack.imgur.com/mDyzy.png
> > > > > And here the current value of the list is being used in an HTTP
> > > > > sampler: https://i.stack.imgur.com/dp5ql.png
> > > > >
> > > > > If anybody could at least tell me where to start, it would be much
> > > > > appreciated.
> > > > >
> > > > > Thank you.
> > > > >
> > > > > On Wed, Apr 22, 2020 at 5:25 PM _elgato <[email protected]> 
> > > > > wrote:
> > > > > >
> > > > > > Hi everyone,
> > > > > >
> > > > > > I have to create a test which will send some HTTP requests. The 
> > > > > > number
> > > > > > of requests will depend on the number of columns in a CSV file so 
> > > > > > that
> > > > > > a request will be sent for each cell in a row. The purpose here is 
> > > > > > to
> > > > > > be able to use different CSV files with a variable number of 
> > > > > > columns .
> > > > > >
> > > > > > I am trying to set the test using ForEach controller, however I am
> > > > > > having trouble setting the loop.
> > > > > >
> > > > > > The hierarchy on the test is:
> > > > > > TestPlan
> > > > > >     Thread Group (one CSV row per thread)
> > > > > >         CSV Data Set Config
> > > > > >         ForEach controller (for each row in CSV file)
> > > > > >             HTTP request (send one per cell in row, making use of 
> > > > > > cell
> > > > > > value as variable)
> > > > > >
> > > > > > What is the best approach to do this?
> > > > > >
> > > > > > Thank you.
> > > > > > Regards.
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [email protected]
> > > > > For additional commands, e-mail: [email protected]
> > > > >
> > > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to