How to write Jmeter Regex into a file after extraction - jmeter

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

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.

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