How to do parameterization for file name text of csv data set config in jmeter - 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

Related

How to replace a string in a variable that came from a CSV Data Config?

In my JMeter test plan, I have two CSV Data Config elements.
CSV Data Config-element-requestBodies: This CSV Data Config element has a variable named "requestBody". In the corresponding CSV file, each line has an XML request with a placeholder string.
CSV Data Config-element-subject: variables. This CSV Data Config element has a variable name "subjectDn". In the corresponding CSV file, each line has a distinguished name (DN) for a user.
The "requestBody" variable will contain an XML request from the CSV file that has the request bodies, with a placeholder string and I want to replace that placeholder with the contents of the "subjectDn" variable, and then use the modified "requestBody" variable in the HTTP Request element.
In other words:
Replace the placeholder string in the ${requestBody} with the value in the ${subjectDn}, then
Use the modified ${requestBody} in the HTTP Request
How can I do that? What is the easiest/least overhead way of doing that?
I've tried using the "__evalVar" function (see https://am.net/lib/tools/NetworkManagement/apache-jmeter-2.8/printable_docs/usermanual/functions.html), but it looks like that is not able to do the replacement when the string is from a CSV file?
Thanks in advance!
Jim
Wrap your ${requestBody} into __eval() function, it will allow JMeter to resolve JMeter Functions and Variables which are present as "placeholders" in the CSV file to their respective values.
${__eval(${requestBody})}
Also if you consider scripting to accomplish your requirements be informed that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language. More information: Apache Groovy: What Is Groovy Used For?
I was able to get this woring by using a Beanshell pre-processor and some Java code that does var.get() and then Java String replaceall() and then var.put().

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.

Jmeter - CSV Data Config file name - Modify at RunTime

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.

Passing Multiple JSON parameters in JMeter

My registration form is accepting body in JSON format, and I need to run the test with 5 different user names.
How do I pass JSON as request body? Also I was unable to pass parameter from CSV file. How can I solve this issue?
Add CSV Data Set Config to your Test Plan
Configure it like:
Filename: full path to the file with your emails
Variable Names: anything meaningful, i.e. EmailId
In your HTTP Request sampler copy the recorded value to Body Data" tab and replace hard-coded email with JMeter Variable like:
{"EmailId" : "${EmailId}"}
In Thread Group set "Number of Threads" to 5
Next time you run your test JMeter will read next line from the file.csv and substitute the ${EmailId} variable with the value from the CSV file.
See Using CSV DATA SET CONFIG article for more information on parameterising your JMeter tests via CSV files.

I Want to add different values using csv config in my following code

In my below code i have to use multiple values in userEmail, userName, userMobile.
How can I do ti using csv config?
{"userDevicedId":"d0lfwViLwLQ:APA91bH4VSXS7VlthXhGQ4DPfb3otSUvwMnpmcK-mKyh7WN46xtDXWSYIOLB6Uw-nYr3zSBZOoiicpNuURQ2nR-a9vtwwSI8sehG-FbgYi4AaCdgurLG5C3Le4sYE0Lmp-piz_STLYnB","userEmail":"Tok#gmail.com","userMobileNo":"8989898995","userName":"Tik","userPasskey":"xmrVhb2MpmuzgLN941tGiLtdJnY3yvgMxlhXATEUa7SvsxclTiMLdJgPs7YTbNHF","userPassword":"Test123$$"}
Given your CSV file looks like:
someone#example.com,someone,1234567890
someoneelse#example.com,someoneelse,2345678901
etc.
Configure CSV Data Set config as follows:
Filename: full path to the CSV file
Variable Names: userEmail,userName,userMobile
Other config values - according to your scenario, see Using CSV DATA SET CONFIG guide for detailed explanation
Refer extracted values like ${userEmail}, ${userName}, etc. where required, i.e. if you want to send parametrised JSON it should look like:
{
"userDevicedId": "d0lfwViLwLQ:APA91bH4VSXS7VlthXhGQ4DPfb3otSUvwMnpmcK-mKyh7WN46xtDXWSYIOLB6Uw-nYr3zSBZOoiicpNuURQ2nR-a9vtwwSI8sehG-FbgYi4AaCdgurLG5C3Le4sYE0Lmp-piz_STLYnB",
"userEmail": "${userEmail}",
"userMobileNo": "${userMobile}",
"userName": "${userName}",
"userPasskey": "xmrVhb2MpmuzgLN941tGiLtdJnY3yvgMxlhXATEUa7SvsxclTiMLdJgPs7YTbNHF",
"userPassword": "Test123$$"
}
If you're using HTTP Request sampler, switch it to "Body Data" mode:
Remember that CSV Data Set config reads next line each iteration so make sure you provide enough loops on Thread Group level or via Loop Controller

Resources