How to save request body in Jmeter? - 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

Related

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

Jmeter: How to create HTML dashboard in jmeter using saved summary csv file

I am using following command to generate HTML dashboard:
jmeter -g C:/Users/E01659/Desktop/feb28/feb28_10_3600.csv -o C:/Users/E01659/Downloads/apache-jmeter-5.1/bin/sonali/
Following error is coming: File
'C:\Users\E01659\Desktop\feb28\feb28_10_3600.csv' does not contain the
field names header, ensure the jmeter.save.saveservice.* properties
are the same as when the CSV file was created or the file may be read
incorrectly when generating report An error occurred: Mismatch between
expected number of columns:17 and columns in CSV file:11, check your
jmeter.save.saveservice.* configuration or check line is complete
errorlevel=1
From the error message, it is clear that - CSV file created earlier don't have the header as the first line. When you want to create the APDEX Dashboard from CSV file, JMeter expects that files are created with correct Save Service Configuration. You can change Result file config which are present in jmeter.propertes file.
You may need to change the line as below, so that file created has the headers name as required
jmeter.save.saveservice.label = true
The command you're using is correct, the reason of failure is mismatch of the .jtl file contents and what JMeter expects it to be.
If you got this feb28_10_3600.csv file from execution on another JMeter installation - make sure that JMeter's result save configuration on the machine where you're trying to generate the report is identical to the JMeter installation where JMeter was running.
Inspect the associated JMeter properties and amend them to for 100% match, once done you should be able to normally generate the dashboard.
If you still experience the differences update your question with first 2-3 lines of your .jtl results file.
You are receiving this error (most likely) due to a corrupt line at the end of your file. Just execute a 'tail ' to see the last few lines. Most likely, your last line is missing columns due to an abrupt stop in the test. Once you delete the problematic line, you should be able to generate the HTML report.

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 - store variable data for an hour

Is there a way to access Jmeter variable data even after tests are run?
This is what i am looking for:
Run a test, store the data in a variable (test finishes in 2 mins)
Idle for 15 mins
Run another test
i want the variable in step 3, Without running step1 again.
The most straightforward choice is saving the variable(s) you need into JMeter's .jtl results file using Sample Variables property. In order to "tell" JMeter to save certain variable value you need to add the next line to user.properties file:
sample_variables=your_variable_name
Alternatively you can pass this property value using -J command-line argument
jmeter -Jsample_variables=your_variable_name -n -t ....
Once done you should see an extra column in the .jtl results file holding your variable values. You should be able to access these values using i.e. CSV Data Set Config.
See Configuring JMeter user manual chapter for more details.
Variables are per test. You need to use a resource as file.
Use propert file to save and load variable as follows:
Start jmeter with property file as -q my.properties
On your test check if property exists if exists skip step 1
If not - do step 1 and then add the variable to property file line as propName=propValue
See example

Saving a exact response in file in Jmeter

How to save exact response from Jmeter in a file?
e.g. - I have a response as email only so I want to save this email address only in a file with a success and failure but If I am saving a file as xml its giving a whole bunch of code otherwise if I save it as a csv file it's giving all sort of infomation other than a email address. Pls help me to solve it.
If you need to save the whole response - Save Responses to a file listener is what you're looking for.
If you need to store a part of the response - first of all get the necessary part with i.e. Regular Expression Extractor. Once you have JMeter Variable holding required value i.e. email you can add the next line to user.properties file (lives under /bin folder of your JMeter installation)
sample_variables=email
and ${email} variable value will be stored along with other results.
NB
you need to restart JMeter to pick the property up
you can also pass it via -J command line argument like:
jmeter -Jsample_variables=email -n -t /path/to/testplan.jmx -l /path/to/results.jtl
References:
Sample Variables
Apache JMeter Properties Customization Guide

Resources