Jmeter - CSV Data Config file name - Modify at RunTime - jmeter

How can I change the filename of the CSV DataConfig at run time in the jmx file.
We have a logic in a java class which would create a dynamic file name and this
needs to be configured as the filename in the CSV DataConfig.
I am using Jmeter 4.0
Regards

You could use a variable / property name in the CSV data set config
here filename could be the name of the file or complete path of the file itself could be used as a variable.
Remember that CSV Data set config element gets initialized first - so filename should be a User defined variable / could be a property passed to JMeter. I would prefer a property.
Do note that You can not keep on changing the CSV data set config element filename in a test once it started. That means one CSV Data set config element can be used for 1 CSV file only. We can not modify!!

You cannot as CSV Data Set Config is a Configuration Element therefore it's executed before anything else. If you need to read the data from different files as the test goes by consider using JMeter Functions instead, the most suitable ones would be:
__StringFromFile() - returns the next string from the given file each time it's called
__CSVRead() - reads a value from CSV file. The function not only supports using dynamic file names, moreover, you can provide even multiple input files as well.

Related

how to pass the dynamic filename in csv data set config in jmeter while the dynamic names are generated to save data of previous request?

I have one http request whose response comes in nested json and using groovy i am saving that data in different csv file on the basis of conditions.
the name of csv file is generated dynamically and saved in a variable
using vars.put() function
vars.put("_cFileName",cFileName.toString());
when try to use this variable in csv data set config
enter image description here
getting error message
2022-01-19 16:58:39,370 ERROR o.a.j.t.JMeterThread: Test failed!
java.lang.IllegalArgumentException: File ${_cFileName} must exist and be readable
it is not converting the name to actual file name
But in case if file name is not dynaamic and the variable is defined under user defined variable in test plan it will able to convert to actual file name?
is there any way we can use the dynamic name created in an previos request post processor?
You cannot, as per JMeter Test Elements Execution Order Configuration Elements are executed before everything else, CSV Data Set Config is a Configuration Element hence it's being initialized before any JMeter Variables are being set.
The solution would be moving to __CSVRead() function, JMeter Functions are evaluated at the time they're being called so it's possible to provide dynamic file name there, see How to Pick Different CSV Files at JMeter Runtime guide for more details if needed.

CSV Data config - avoid creating duplicate folder names

I have created CSV data config as attached and the purpose of this run is to create folder names in the application and should not try to create the duplicate folder names.
please advise if we need to add post processor with if condition? if yes please provide the condition to put in post processor?
I can only think of getting the existing folder names somehow and storing them into JMeter Variables
Once done you can use the If Controller and use the following __groovy() function as the condition:
${__groovy(!vars.entrySet().collect {entry -> entry.getValue()}.contains(vars.get('your variable from CSV Data Set Config')),)}
The If Controllers child(ren) will only be executed if there is no JMeter Variable with the value of the current variable from the CSV Data Set Config is present.

JMETER:- How to handle multiple CSV file if all files column name are same

In Jemter:- How to fetch the data from CSV file if we have multiple CSV files for all cases inside a thread(column name is same in all file only data is different), in my case , for all request data is getting from one file only (first case's CSV ) even though file name is different. and once i disable other request and run only single request it will take data from proper file.
If you have dependent CSV files, i.e. trying to use variable from 1st CSV file as an input to 2nd CSV - it will not work.
As per Execution Order chapter of JMeter User Manual:
0. Configuration elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null)
5. Assertions (unless SampleResult is null)
6. Listeners (unless SampleResult is null)
So being Configuration Elements all the CSV Data Set Config elements are initialized at the same time at the beginning of the test.
If your test configuration is highly dynamic and built on relationship of data from multiple CSV files you will have to go for __CSVRead() function instead.
Check out How to Pick Different CSV Files at JMeter Runtime for more information on the concept and example solution.

How to hit parameterized url in Apache Jmeter?

This is my test URL " http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id={Email} "
I want to hit the url 1500 times per second , and want to change the "{Email}" with real value in each iteration.
How it's possible please give me a step by step guide.
Considering that you need to pass the emails from the external file, the most efficient way that we are using in software testing companies is to pass the variable from .csv or .txt files using 'CSV Data Set Config' element of the JMeter.
Please find the steps that you need to follow:
Add a 'CSV Data Set Config' element from 'Config Element' by right-clicking the thread group
Set Filename field with complete path to your .csv or .txt file that contains your emails
Set Variable field as 'Email' [This variable name should be same as you set in your url request]
Ignore first line to False
Set other fields as per your requirement
Now add HTTP Sampler in your Thread Group and set the Protocol, Server Name, Method & Path as instructed in the screenshot:
Create .csv or .txt file and add all emails separated by new line:
Hope this answer is useful.
You can use the CSV Data Set Config. Put all your email credentials in the CSV file and make sure you have put this CSV file in your JMeter /bin directory.
Add a CSV dataset config in your test plan. Your CSV dataset config should be like:
Now in your thread group, define the number of threads you want to execute and then in your sampler put the path as follows:
http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id=${Email}
Depending on where do your emails live there are following options:
If they are in a text file, each email on a new line you can use __StringFromFile() function like:
If they are in a database you can use JDBC PreProcessor to fetch the data from the database table column and put your request under ForEach Controller
If you need to provide just some random characters you can use __RandomString() function.
More information: JMeter Parameterization - The Complete Guide

How to do parameterization for file name text of csv data set config in jmeter

I am passing the value for file name text filed in csv data set config as ${filename}, this variable contains entire path and fetching it form one more csv data set config which is present immediate to the thread group and the variable which I am passing to csv data set config that is inside the if controller here I couldn't able to pass that value to file name text filed, getting problem.
CSV Data Set Config cannot use JMeter Variable as the "Filename". However it is possible to use __property function there.
So your test plan should look as follows:
Read some value into a JMeter Variable i.e. foo via 1st CSV Data Set Config
Convert foo variable into foo property via __setProperty function
Use ${__property(foo,,)} as a "Filename" in 2nd CSV Data Set Config.
For more information on different JMeter's functions see How to Use JMeter Functions post series

Resources