How can I set the connection timeout or the Response Timeout in JMeter through the properties (JMeter/User/System) files? I can do it by adding an HTTP Request Defaults but I need to do it through the property files?
2 Answers
There are 2 ways you can pass properties 1. pass by command line options 2. pass by using properties files.
To pass properties using command line options:
The flag to set a property is -JpropertyName
The function to read a property is ${__P(propertyName)}
To pass properties using JMeter.properties file
Define a property in JMeter.properties file (i have defined a test property in the screenshot below)
To read the property you can use __Property function
for example ${__property(testproperty,value,)}
this statement reads the property named testproperty and stores it in JMeter variable "value"
You can also read properties from external file. For more info on reading properties from external files read this article
For more info on JMeter command line options follow this link
Looking into HTTPHC4Impl.java
int rto = getResponseTimeout();
if (rto > 0){
requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, rto);
}
int cto = getConnectTimeout();
if (cto > 0){
requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cto);
}
protected int getConnectTimeout() {
return testElement.getConnectTimeout();
}
There is no way to set the values via JMeter properties, you will have to continue using the HTTP Request Defaults.
However instead of hard-coding timeout values into the .jmx script you can use __P() function like:
Once done you will be able to define the values in user.properties file like:
connectTimeout=1
responseTimeout=1
Or via -J
command-line argument like:
jmeter -JconnectTimeout=1 -JresponseTimeout=1 -n -t test.jmx -l result.jtl
If you don't pass the value it will default to 0
(no timeout)