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

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.

Related

Passing relative path file name in csv config element in jmeter

I want to pass relative path file name in csv config element in jmeter.i have used ./filename.csv but the jmeter script doesn't work .I have also used ../filename.csv but jmeter script doesn't work.
Need resolution to pass relative path file name in csv config element in jmeter.i have used ./filename.csv but the jmeter script doesn't work .I have also used ../filename.csv but jmeter script doesn't work.
Relative to what?
As per CSV Data Set Config documentation:
Relative file names are resolved with respect to the path of the active test plan.
csvdata.txt and ./csvdata.txt - then these are treated as different files
If you have filename.csv in the same directory as your .jmx test plan - just use filename.csv, the ../filename.csv construction will look for the filename.csv file in the parent folder for the active test plan.
If you want to know the full path to the current base directory - look for FileServer entry in the jmeter.log file
INFO o.a.j.s.FileServer: Set new base='/this/would/be/the/base/for/relative/CSV/file/lookup'
you will see where JMeter tries to load the CSV file in the same jmeter.log file

Parametrize source folder directory or file path in JMeter

Is there any way to parameterize the CSV data file path or source directory path in JMeter?
There are at least 2 possibilities:
Via User Defined Variables like:
and then referring the variable in the CSV Data Set Config
Or via __P() function like:
the property value can be passed via -J command line argument or put into the user.properties file. See Overriding Properties Via The Command Line for more information.

How can i provide different csv files via command line for the same JMX file in 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.

JMeter GUI - Set default settings for exporting results to CSV file

How to set default settings in JMeter for exporting result to csv file?
It keeps asking in pop up below
Since JMeter 3.3
Update jmeter.properties in JMeter's bin folder: uncomment the property
#resultcollector.action_if_file_exists=ASK
and choose value between 2 options (instead of ASK):
# APPEND : Append results to existing file
# DELETE : Delete existing file and start a new file
save the fle, and restart JMeter

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