JMeter result in JTL format along with request and response data - jmeter

I am trying to get Jmeter output in JTL format so that I can utilize JMeter GUI to "View result tree" using "Read from file" option
I am running following command from cmd line
jmeter -Jjmeter.save.saveservice.samplerData=true -Jjmeter.save.saveservice.response_data=true -n -t nmame.jmx -l JmeterReports/TestReport.jtl
When I open the result file Testreport.jtl generated, I don't see request and response data. Can you please help me?

You need to amend a little bit your command line in order to include some more properties responsible for the results file configuration like:
jmeter -Jjmeter.save.saveservice.output_format=xml -Jjmeter.save.saveservice.response_data=true -Jjmeter.save.saveservice.samplerData=true -Jjmeter.save.saveservice.requestHeaders=true -J jmeter.save.saveservice.responseHeaders=true -Jjmeter.save.saveservice.url=true n -t nmame.jmx -l JmeterReports/TestReport.jtl
In order to make the change permanent add the next lines to user.properties file (lives in "bin" folder of your JMeter installation)
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.url=true
More information: How to Save Response Data in JMeter

You have chosen to include entities that are available only if the output format is XML.
Hence, include below as part of your argument list
-Jjmeter.save.saveservice.output_format=xml
items with (XML) only apply to XML format
Source: https://jmeter.apache.org/usermanual/listeners.html#sample_configuration
Reference Screenshot
You can still persist with .JTL file extensions for your log files and need not rename all of them to .XML. JMeter will still read the data and provide you with the necessary details
Hope this helps!

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

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.

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

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

Jmeter - running command line arg -l doesn't log headers

Does anyone know if it is possible when using the -l switch on command line to execute, if you can log the headers in the .jtl file as well? I've actually named mine as .csv (read somewhere it doesn't matter) but no headers are appearing.
If this is not possible, can someone please tell me the what the headings should be?
Cheers,
J
If you're looking for HTTP request and response headers:
Storing headers in "csv" mode is not supported, you will have to switch to "xml" mode
It is unclear whether you look for "request" or "response" headers.
Kindly find the instructions on how to switch JMeter to store results in XML format and "tell" JMeter to store request and response headers:
Command-line mode:
jmeter -Jjmeter.save.saveservice.output_format=xml -Jjmeter.save.saveservice.responseHeaders=true -Jjmeter.save.saveservice.requestHeaders=true -n -t /path/to/your/script.jmx -l /path/to/results/file.jtl
Unattended mode:
Locate user.properties file in /bin folder of your JMeter installation
Add the next 3 lines to the user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.requestHeaders=true
and after JMeter restart the properties will get applied.
If you're looking for printing field names in CSV mode like like timeStamp,elapsed,label,responseCode,responseMessage,threadName,success,grpThreads,allThreads,Latency,Connect etc.
Command-line mode:
jmeter -Jjmeter.save.saveservice.print_field_names=true -n -t ....
Unattended mode: add the next line to user.properties file
jmeter.save.saveservice.print_field_names=true
See Apache JMeter Properties Customization Guide for comprehensive information on different JMeter properties and ways of setting and/or overriding them
See this post on how to add headers to csv output file.
You need to configure it in the jmeter.properties (Command switch won't work with this since it has to be defined first):
Configuring result file data when running JMeter in non-GUI mode
The print_field_names is by default false.
Edit jmeter.properties file in the Jmeter home directory, and set:
#---------------------------------------------------------------------------
# Results file configuration
#---------------------------------------------------------------------------
# This section helps determine how result data will be saved.
# The commented out values are the defaults.
# legitimate values: xml, csv, db. Only xml and csv are currently supported.
jmeter.save.saveservice.output_format=csv
...
...
# Only applies to CSV format files:
jmeter.save.saveservice.print_field_names=true
And run from command line:
\bin\jmeter.bat -n -t C:\Jmeter\Tests\Test.jmx -l Results.csv
Output example:
timeStamp;elapsed;label;responseCode;threadName;success;bytes;grpThreads;allThreads;Latency;SampleCount;ErrorCount;Hostname
11:49:16;32;Get the Agent ID;500;SM play 10 calls per user 1-1;false;0;1;1;0;1;1;HOST1

Resources