I just started using Jmeter and don't know how to make a variable. This is the HTTP body request and I would like to change the project name each time I perform load testing.
I tried using CSV config but it didn't work.
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityIf you have a CSV file which looks like
project x
project y
project z
Add a CSV Data Set Config and:
projects.csv
project
Once done you will be able to refer the value from the CSV as ${project}
where required, i.e. in the Body Data tab of the HTTP Request sampler
When you run your test the ${project}
JMeter Variable placeholder will be replaced by the next line from the CSV file on each iteration of each virtual user:
More information: JMeter Parameterization: The Complete Guide
You can parametrize the body in JMeter by using the following steps:
1 Add a "HTTP Request" sampler to your test plan
2 In the Body Data section of the HTTP Request sampler, use variables to define the content of the request body. For example, if you want to send a JSON payload, you can write it like this:
{
"username":"${username}",
"password":"${password}"
}
3 To define the values of the variables, you can use a "CSV Data Set Config" element.
4 In the CSV Data Set Config element, specify the file name and other details of the CSV file containing the data.
5 Reference the variables in the HTTP Request sampler using the syntax ${variable_name}
For more detailed information, you can refer to the following resources: