How can I parameterize the FILENAME of 'CSV Data Config' element

6,464 views
Skip to first unread message

Manoj KS

unread,
May 2, 2014, 5:32:44 AM5/2/14
to jmeter-...@googlegroups.com
Hello,

Could anyone please let me know how can I parameterize the FILENAME of 'CSV Data Config' element

I am unable to use values extracted from 'Regular Expression Extractor' or values created by 'Random Variable' element if I put 'Filepath' in CSV Data Config as '${varRandomVariable}/Manoj.csv'

Thank you,
Manoj Kapuganti

gli...@gmail.com

unread,
May 7, 2014, 8:06:02 AM5/7/14
to jmeter-...@googlegroups.com
Hi Manoj,

CSV Data Set Config FILENAME cannot be parametrized using JMeter Variables. However you can play a trick and convert JMeter Variable to a JMeter Property which CAN be used as whole or part of CSV Data Set Config file path. There are at least 2 ways on how you can do this:

  1. Use __setProperty() JMeter Function
  2. Or use Beanshell Sampler/Pre-Processor/Post-Processor/Assertion/Timer - whatever is more applicable to your use case. 
Relevant Beanshell code which converts "test" variable to "test" property looks like:

props.put("test", vars.get("test"));


So you would be able to refer "test" property in CSV Data Set Config as follows:

${__property(test,,)}

or using a shorthand function of __P

${__P(test,)}

See How to use BeanShell: JMeter's favorite built-in component guide for more details on JMeter extension via scripting. 

Hope this helps.

liza....@gmail.com

unread,
Nov 26, 2014, 9:29:46 AM11/26/14
to jmeter-...@googlegroups.com, gli...@gmail.com
Hi.

Actually it would be nice to have opportunity to parameterize the FILENAME of 'CSV Data Config' element. 
I have a number of jmx tests and if I'll give them to somebody else - this person should come all jmx through and change paths used in test.
So I've created properties.csv and stored there all paths, and now only link to this  properties.csv file should be replaced in jmx. 
But unfortunately I use "Variables From CSV File element" twice in my tests - and filename to other "Variables From CSV File element" couldn't be parameterized.

Liza Leo

Vincent Daburon

unread,
Nov 26, 2014, 10:57:25 AM11/26/14
to jmeter-...@googlegroups.com, gli...@gmail.com, liza....@gmail.com
Hi,
I use a "setUp Thread Group" with a "Bean Shell sampler"
The Bean Shell have a parameter : ${__machineName()}  => computer name
In the Bean Shell i write a small code to test the computer name and set a directory corresponding to the machine like :
String computerName = Parameters ;
log.info("computerName = " + computerName);
if (computerName.contains("mycomputer1")) {
props.setProperty("K_DIR_DATA", "D:/usr/formation/JMeter/data");
}
if (computerName.contains("mycomputer2")) {
props.setProperty("K_DIR_DATA", "D:/projets_load_test/data");
}

The data directory depends on machine name.
I use this property in my CSV Data Set Config, the file name is ${__P(K_DIR_DATA)}/login.csv for example.

Regards.
Vincent D.

liza....@gmail.com

unread,
Nov 26, 2014, 11:25:19 AM11/26/14
to jmeter-...@googlegroups.com, gli...@gmail.com, liza....@gmail.com
Thank you, Vincent.

Very good idea!
But as long as "Variables From CSV File element" filename can't be set as parameter -
I'm still facing the problem that some of paths should be manually changed in ALL tests in case of other dir or environment :(

But I'm afraid I'm in wrong topic and we do not discuss "Variables From CSV File element" plugin :-\

Sorry,
Liza.L

srlte...@gmail.com

unread,
Jun 14, 2016, 8:39:12 AM6/14/16
to jmeter-plugins
Hi All,

This solution works for one csv per one thread when you have multiple csv files needs to be picked up by each thread.

1. you need set a counter, reference name : finalcount
2. you need to define a variable DATA and value as 0
3. Add Beanshell sampler to make sure you are getting the correct data. add below 2 statements.
4. Convert the variable to setproperty

props.setProperty("DATA", vars.get("finalcount"));
print(${__P(DATA)});

5. your csv files should be in the order like file1.csv,file2.csv....file20.csv
6. Add CSV DAta config and Add filename as below

file${__P(DATA)}.csv


Please find the attached script for reference.

Thank you,
Tejaswini
  __________________________________________________________________________________________________
ParameterizedCSVFileName.jmx
Reply all
Reply to author
Forward
0 new messages