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
Related
File: DevEnv.properties
# Development Environment property file
environment.protocol=https
environment.hostname=dev.env.com
environment.port=443
environment.path=api
File: StagingEnv.properties
# Staging Environment property file
environment.protocol=https
environment.hostname=staging.env.com
environment.port=443
environment.path=stagingapi
command used jmeter -g "StagingEnv.properties" - t "Practice11.jmx";
Test Plan Structure
Test Plan
JSR223 PreProcessor
HTTP Request Defaults
Thread Group
jp#gc - Dummy Sampler
View Results Tree
In short value should read from file location provided in command line and when run directly then it must be read the default value.
JMX file is attached in this link
You can try defining the ${__P(variable,defaultVariable)} in User Defined Variables itself and use it with default values or command line arguments. no need for reading it from properties file.
protocol ${__P(protocol,https)}
hostname ${__P(hostname,testHostName.com)}
port ${__P(port,80)}
Then command to use it:
jmeter -Dprotocol='http' -Dhost='localhost' -n - t "Practice11.jmx";
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.
I have problem with set parametrize $url variable in Jmeter.
I must set parametrize because I will run my project test in three other URL addresses, because application is deployed for 3 others such as production, development and I also would like testing in local.
I have the following CSV file:
protocol
$url
${dev} http://10.200.XXX.XX/{$url}
${trial} trial.mycompany.io{$url}
${product} product.mycompany.io{$url}
How can I set this in JMeter, set parametrization my URL variable?
Your question is not very clear, moreover my expectation is that you shouldn't have JMeter variables reference in form of ${variable} in the CSV file, only "plain" data should go there.
With regards to running test on different servers I would go for creating 3 separate CSV files, i.e.
dev.csv with the following contents:
protocol,host
http,10.200.XXX.XX/
trial.csv with the following contents
protocol,host
https,trial.mycompany.io
product.csv with the following contents
protocol,host
https,product.mycompany.io
Once done you can add a CSV Data Set Config and set it up like:
And finally add HTTP Request Defaults to your Test Plan to read the values from the relevant CSV file:
So when you run JMeter without any parameters it will pick up dev.csv file and will go to 10.200.XXX.XX host
If you run JMeter like:
jmeter -Jenvironment=trial
it will pick up trial.csv and will go to trial.mycompany.io host
If you run JMeter like:
jmeter -Jenvironment=product
it will pick up product.csv and will go to product.mycompany.io. host
More information:
__P() function
Overriding Properties Via The Command Line
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
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