JMeter has many config elements to define some variables which can be used in the JMeter test.
For example – the mostly used ones,
- User Defined Variables to create variable names & values
- CSV Data Set Config to read the test data from CSV file
But we do not have one to read a user property files!! hm..Well..that is not true exactly!!
In the JMETER_HOME/bin folder, we have a jmeter.properties file which has JMeter specific properties to set logging configuration, HTTPClient configuration, remote host configuration etc.
The same file also has a property called user.properties in which we can mention our file path to be read to use it in JMeter. So, JMeter can actually read the user property files. Then what? But – I do not want to touch JMETER_HOME/bin folder to read my property files every time.
Reading a user property files can also be done using Beanshell pre processors/Samplers in JMeter. However, as JMeter is open source, I wanted to create a custom config element to read the property files. This link has the details to create a plugin for JMeter.
Property File Reader – Config Element:
- Download this zip file which contains a jar file.
tag-jmeter-extn-1.1.zip (320067 downloads)
- Go to JMETER_HOME/lib/ext foler.
- Place the jar file & Restart JMeter.
- Once yo launch the JMeter, You will see ‘Property File Reader’ as given below.
- Select it to add it under Test Plan. Enter the file path of the Property file. Enter the absolute file path Or a variable containing file path.
- It supports both absolute or relative file path
- relative file path should be relative to the current jmx test plan.
- Lets assume our property file contains below properties.
- Create a simple test as given below. Response data of the Debug sampler shows the user properties we wanted to read. Use ${__P(PROPERTYNAME)} in JMeter test to get the property value.
I maintain no of users, ramp up period, test duration, application URL & many other information for my test in the property file. So I wanted to create a simple config element to read property file instead of using a Beanshell preprocessor to make a test neat & reusable.
Happy Testing & Subscribe 🙂