How can i provide different csv files via command line for the same JMX file in Jmeter - jmeter

I would like to run the same JMX file for different loads/threads using different csv config files.Let's say csv files contains data for the username and password. For test1 csv file has 1000 rows for the test2 csv file has 2000 rows like that so on..
How can i provide different csv files via command line for the same JMX file for different thread count.
I know i can pass the threads,rampup,rampdown,duration by usin __P() function like ${__P(threads,)}via command line as below
jmeter -Jthreads=200 -Jrampup=10 -Jduration=1000 -Jrampdown=10 -n -t test1.jmx -l result1.jtl
Thanks,
Raj

You can do it just the same way as you do for Threads, Rampup, Duration, etc.
In your CSV Data Set Config define the Filename using __P() function like:
${__P(csvFile,test1.csv)}
this will tell the CSV Data Set Config to read the filename from csvFile JMeter Property and use test1.csv if the property is not set (so you could debug your test in GUI mode)
That's it, now you will be able to pass the file name using -J command-line argument like:
jmeter -JcsvFile=/path/to/file2.csv -Jthreads=200 ....
alternative way of setting up the property is putting the value in user.properties file. Check out Apache JMeter Properties Customization Guide for more information.

Related

JMeter number of threads (users) variable from CSV file not working

I'm reading different parameters from the CSV file with the "CSV Data Set Config" component.
I added the threadCount column in the CSV. It could have for example the value 100.
Then I use in the "Thread Group" component in the field "Number of Threads (users)" the variable ${threadCount} and nothing happens when I run the report.
There is in the log file:
2021-09-29 09:34:19,704 DEBUG o.a.j.e.u.ValueReplacer: About to replace in property of type: class org.apache.jmeter.testelement.property.StringProperty: ${threadCount}
2021-09-29 09:34:19,704 DEBUG o.a.j.t.p.AbstractProperty: Not running version, return raw function string
2021-09-29 09:34:19,704 DEBUG o.a.j.e.u.ValueReplacer: Replacement result: ${threadCount}
If I add the threadCount variable to the "User Defined Variables" component then the program runs correctly.
Could you please tell where is the problem?
I don't think you can configure the number of threads in the Thread Group using CSV Data Set Config because Thread Group is initialized before the CSV Data Set Config is processed.
If you want to make the number of threads externally configurable you can define it using __P() function like
${__P(threadCount,)}
Once done you should be able to define the value in following ways:
Via user.properties file like:
threadCount=100
Via your custom .properties file, the same way but you need to pass this file to JMeter via -q command-line argument
jmeter -q /path/to/your/custom.properties file
And you can override the value via -J command-line argument like:
jmeter -JthreadCount=100
More information:
Full list of command-line options
Configuring JMeter
Apache JMeter Properties Customization Guide

How to read data from csv file in jmeter whose location is not fixed and might change in the future

I have a CSV File whose location is going to change later. Using Jmeter how can I still read the file even if the location change?
You can set the location of the CSV file as a JMeter property and pass it through the command line or through user.properties file
Set the file name with a property in the CSV Data Set Config element
${__P(full-path-to-file,/Users/hansi/Documents/test-data/test-data-users.csv)}
Note: A default value /Users/hansi/Documents/test-data/test-data-users.csv is set in the above screenshot.
2.Define the value
2.1 In user.properties file
full-path-to-file=/Users/hansi/Documents/test-data/test-data-users.csv
or
2.2 Set the property when JMeter test is executed from commandline
./jmeter.sh -n -t test-plan.jmx -Jfull-path-to="/Users/hansi/Documents/test-data/test-data-users.csv"
If the CSV file is going to change location then you could store the test plan which is using the file alongside it. This would maintain the context of the test plan if the CSV itself is going to be moving by storing them together. In JMeter relative file names are resolved with respect to the path of the active test plan (based on the official documentation), allowing you to specify only the name of the file in the CSV Data Set Config Filename property.

Saving an external ID to result file in Jmeter

I have an external data in my test data that is an id that I would like to be able to write to the the result file that is generated when I run this command:
./jmeter -n -t /home/usr/jmeter/script.jmx -l /home/usr/jmeter/scriptjtl
The id will not be used for any request, but the trackid is necessary to include i troubleshooting errors. Example of how the track_id can look: kJbc1W1YupprLcB8YZE0gla1T8APE7Td
Is there some possible away to save the track ID in the result file as a parameter or in any other way?
If you have this track_id extracted into a JMeter Variable you can use sample_variables property in order to add it to the .jtl results file, amend you command line as:
./jmeter -Jsample_variables=track_id -n -t /home/usr/jmeter/script.jmx -l /home/usr/jmeter/scriptjtl
once script finishes you will see an extra column called track_id containing the respective values for the ${track_id} variable for each Sample Result
In order to make the change permanent add the next line to user.properties file (lives in "bin" folder of your JMeter installation)
sample_variables=track_id
More information:
Configuring JMeter
Overriding Properties Via The Command Line
Apache JMeter Properties Customization Guide

How to save request body in Jmeter?

I am fetching data from the CSV file and giving as input to my Request.How can I save all the request in the same file when I run a test for an hour.
One more requirement is, if the result is success then I have to write that data I have used from the CSV into another file so that we can have only the data which is working in an separate file.
Please suggest
The best way would be using JMeter's built-in Sample Variables property.
Add the next line to user.properties file:
sample_variables=foo
Replace foo with the variable name you're getting from the CSV file
Next time you run your JMeter test in command-line non-GUI mode like:
jmeter -n -t test.jmx -l result.csv
your result.csv file will have an extra column called foo and having the foo variable value for each and every request. You will be also able to determine which data caused the failure by looking into "success" column

How to write Jmeter Regex into a file after extraction

In my Jmeter test, I am able to use REGEX Extraction, After extraction I want to write the value of the REGEX variable into a file
I found a workaround as using beanshell as mentioned here https://stackoverflow.com/a/15159521/4556894
Is there any clean way of doing it, May be some inbuilt features, which I am not aware of
It is possible to write variable values into JMeter .jtl results file. There is a JMeter Property called sample_variables
Optional list of JMeter variable names whose values are to be saved in the result data files.
Use commas to separate the names.For example:
sample_variables=SESSION_ID,REFERENCE
So if you run JMeter in command-line non-GUI mode as follows:
jmeter -Jsample_variables=myVariable -n -t /path/to/your/testplan.jmx -l /path/to/testresults.jtl
You'll get the output like
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,bytes,grpThreads,allThreads,Latency,"myVariable"
1425978657207,368,HTTP Request,200,OK,Thread Group 1-1,text,true,1591,1,1,367,YOUR_VARIABLE_VALUE
In above example column names are given for reference, they are not included into csv results file by default. This behavior is controllable via jmeter.save.saveservice.print_field_names property, set it to "true" to get column names printed along with results data.
You can also set sample_variables property value in user.properties file which lives under /bin folder of your JMeter installation or uncomment it in jmeter.properties file (same location)
For more information on JMeter properties and ways of setting and/or overriding them refer to Apache JMeter Properties Customization Guide

Resources