JMeter – Property File Reader – A custom config element

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	(302807 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.

jm-prop-display1

  •  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.

jm-prop-display2

  • Lets assume our property file contains below properties.

jm-prop-display3

  • 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.

jm-prop-display4

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 🙂

 

 

Share This:

87 thoughts on “JMeter – Property File Reader – A custom config element

  1. nice blog. also if you can post a blog on custom code(Where custom code can be used in JMeter ) and monitoring part would help us.

    Thanks,
    Satish

  2. When i add location in property file and try to pass in http request it is not picking correct value

    getting http://d:/test/
    it should be like this http://d:/test/

    error is when we pass C;\abc
    in this : colon is giving error can you solve this problem

    asap

    1. Sorry that I do not understand your question at all.

      If you want c:\abc , You need to have c:\\abc as value in your property file as \ is used for escape sequence in Java.
      It is not limitation of this property file reader.

  3. in property file i have this
    url=c:\abc

    in jmeter i get this
    http:///

    error is due to use of colon
    if i use without colon ie url=c\abc
    then it get correct value

    1. Instead of using Property File Reader, Just declare a User Defined Variable url=c:\abc & use it in your test.
      You should see the same error. So, It is not limitation of this config element.

      I do not understand why you use c:\abc in HTTP sampler.

  4. I followed the installation procedure and not able to see the updated config element. Should i be changing any settings?

  5. it looks like a Java version above 6 is required. when i updated the version to 8,, the property file reader is visible in the options.
    but still my jmeter doesn’t pick any values from the properties file.
    i declared them as below
    {_P(threads)}
    {_P(rampup)}

    and set the values in the properties file as
    threads=10
    rampup=10

  6. Is it possible to get the source code for this extension? I would like to integrate this into some existing libraries I have for meter?

  7. Hi,
    I’m using this just with C:\\abc. But the problem is:
    If I try to run my test, it does not work for first time(I think JMeter reads the file in C:\\ in first try too late! )
    but if I run the test several times again, then it works good.
    do you have any Idea?

  8. Hey,

    This property reader is very handy add-on, but I think I found a minor defect. It doesn’t limit the functionality but still is the pain in the ass a bit 😉

    The property reader is the first item of my Test Plan in JM. Even thou, the first launch of the test run gives fails of all tests relying on properties data. If I stop the run and restart it everything work like a charm then.
    Or maybe it is because I store values property file as JM’s properties? Is JMeter property is created as first thing ever, so read values needs a restart to be stored as properties too?

    JMeter version is use is: 2.13 r 1665067

    Cheers,
    Kris.

      1. I did check it once again with a fresh start.
        The thing I am doing is to read the property file and after that assign property values to user variables with `User Defined Variables` config item.
        And, as I wrote yesterday – it works starting from second launch of the test plan.

        1. Kris,

          That was a good find. Thanks once again.
          I tried to fix it. What happens here is…

          Jmeter’s StandardJMeterEngine class always loads the User Defined Variables first before loading other config elements (!!!). As you can also define UDV in the test plan level.
          So basically even if you place an UDV element as the last element of your test plan, that will get loaded first.

          StandardJMeterEngine’s run method starts as given below…

          @Override
          public void run() {
          log.info("Running the test!");
          running = true;

          /*
          * Ensure that the sample variables are correctly initialised for each run.
          * TODO is this the best way to do this? should it be done elsewhere ?
          */
          SampleEvent.initSampleVariables();
          JMeterContextService.startTest();

          SampleEvent.initSampleVariables() -> is for initializing the UDV.
          JMeterContextService.startTest() -> After this point only all other config elements get initialized.

          So, We might not be able to fix the issue you are reporting.

          As you already know, you can directly use the property in your testplan instead of assigning the property to a UDV.

  9. Hi,
    I am unable to retrieve the value from the Properties file.
    I have a properties file called Testdata.properties in that i have
    #url
    url=www.google.com

    in HTTP Request Defaults i gave ${_P(url)} to retrieve the data from properties file
    and added HTTP request
    if i execute its giving error message
    java.net.URISyntaxException: Illegal character in authority at index 8: https://${_P(url)}/

  10. 1 )how to give path of the properties file to execute in command line
    i have Testdata.properties in “c:\Jmter\Testdata.properties”
    it is working file when i give only filepath =”Testdata.properties” in GUI mode, but it will fail when i execute in the command line
    2) How to give the file path dynamically in the command line??

    1. You need to pass the file path as a property to the test.

      jmeter -n -t test.jmx -Jmypropfile=”c:/path/to/file.properties”

      In the prop file reader, for the file path, use ${__P(mypropfile)}

  11. Thanks for your help..
    I tried the same its giving error in Command line
    let me explain more details , i have both jmx and properties file in the same folder in C drive
    C:\performace\Sampler.jmx and C:/performace/Testdata.properties
    and in Properties file i have
    durl=www.xyz.com
    dport=8080
    req=http
    and finally i gave ${__P(mypropfile)} in prop file reader and ${__P(dUrl)},${__P(dport)},${__P(req)} in Http request defaults
    then i tried to execute in command line using below command
    jmeter -n -t C:\performace\Sampler.jmx -Jmypropfile=”C:/performace/Testdata.properties” -Jdurl -Jport -Jreq
    it is giving error
    but if i hard code the path of the properties file mean to say if i give C:/performace/Testdata.properties in the prop file reader it will work

    2) one more thing i saw -Jdurl always take value from the properties file only if i give
    -Jdurl=”www.abc.com” in the command line it will not take . it will take http://www.xyz.com which is there in properties file

    1. Why do you pass these info (-Jdurl -Jport -Jreq) in the commandline?
      See..you need to use either property file or pass the info using commandline arguments.
      As you have all the url, port, req details in the property file, you do not need to pass the info.

      Below statement will do to execute in your case.

      jmeter -n -t C:\performace\Sampler.jmx -Jmypropfile=”C:/performace/Testdata.properties”

  12. No its failing in the command line, you can see my email id, could you email me so that i can send screen shot…
    the same thing if i hard code the path in prop file it will work

    2) how to give URL , portnumber dynamically
    i am using like this “jmeter -n -t C:\performace\Sampler.jmx -Jmypropfile=”C:/performace/Testdata.properties” -Jdurl= “www.xyy.com” -Jport=”8089″ -Jreq=”https”” is this right ??

    1. I do not really understand the issue. When you have the url, port etc in the property file, why do you need to pass the information in the commandline?

      Eventhough it is nothing wrong to pass the arguments, I am afraid it might not reflect if you have the same properties in the property file as it might overwrite.

      Either this

      jmeter -n -t C:\performace\Sampler.jmx -Jdurl=”www.xyy.com” -Jport=8089 -Jreq=https

      or this

      jmeter -n -t C:\performace\Sampler.jmx -Jmypropfile=”C:/performace/Testdata.properties”

      Good luck!

  13. Hi Its not working for me, both are not working.
    I want to pass URL,,Portnumber dynamically its not working

    1. There was a recent update in the wordpress blog which messed up many things – this is one of them :(. It has been fixed now.

  14. Thanks for putting this plugin together and sharing it. I’m trying to get the best of all worlds. I was using UDV to define defaults and pull in CLI driven variable changes. Now that i’ve found this, most of the time I will be using the properties file, but it would still be great to be able to pass in quick changes via command line when need be. Any plans to support something like:
    server=${__P(server_ip,localhost)} so i can pass in -Jserver_ip=10.0.3.10

  15. Thanks for creaeting this add-on. it’s exactly what i’m looking for. A couple questions:
    * have you thought about adding on ability to still use -J command line option to override the property file variable?
    * 2.13 does not show the variables in debug sampler from property file. any suggesetions?

    1. By default, debug sampler shows only the variables. Please enable the properties to see that.
      Regarding the overriding the property file variable, It is bit difficult to implement as the property file reader reads the file only when the test starts whereas the command line options would have already set the property values before the test starts. But i will see how we can include this. I agree that it could be nice.

  16. Please help me with this:
    I am unable to access the property values.
    propertyfile name: ThreadGroups.properties
    path in PFR – C:\Users\Jmeter\ThreadGroups.properties

    Contents of file
    #ThreadGroup
    usercount=1
    rampup=1

    Property value in thread group
    Number of Threads (Users) : ${__P(usercount)}
    Ramp up period (In seconds): ${__P(rampup)}

    Log :
    2016/05/27 14:37:51 INFO – jmeter.engine.StandardJMeterEngine: Running the test!
    2016/05/27 14:37:51 INFO – jmeter.samplers.SampleEvent: List of sample_variables: []
    2016/05/27 14:37:51 INFO – com.tag.jmeter.ext.config.PropertyReader: Property file reader – loading the properties from C:\Users\Jmeter\ThreadGroups.properties
    2016/05/27 14:37:51 INFO – jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*)
    2016/05/27 14:37:51 INFO – jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : A
    2016/05/27 14:37:51 INFO – jmeter.engine.StandardJMeterEngine: Starting 0 threads for group
    A
    2016/05/27 14:37:51 INFO – jmeter.engine.StandardJMeterEngine: Thread will continue on error
    2016/05/27 14:37:51 INFO – jmeter.threads.ThreadGroup: Starting thread group number 1 threads 0 ramp-up 0 perThread NaN delayedStart=false
    2016/05/27 14:37:51 INFO – jmeter.threads.ThreadGroup: Started thread group number 1
    2016/05/27 14:37:51 INFO – jmeter.engine.StandardJMeterEngine: All thread groups have been started
    2016/05/27 14:37:51 INFO – jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
    2016/05/27 14:37:51 INFO – jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)

  17. Hi,
    I am able to successfully use this plugin, i am using a mac machine, the plugin is picking up the file if i am giving the absolute path “/Users/z001wp5/Desktop/JScripts-2016/Adaptive SearchMOD – 2016/user.properties” , But its not working when i am giving the relative path.
    My main jmx is in and the user.properties are in the “/Adaptive SearchMOD – 2016” .
    The csv config element works fine if i give just like “file.csv” or relative path from the working directory. Is there any way we can make the same work in this plugin also

  18. Hi,
    I am able to successfully use this plugin, the only issue i figured out is to enter the absolute path of the properties file. It is not taking the .properties file when the file and jmx is in same directory or the .properties file in child directory. Could you please add that feature also into the element.
    The CSV Data Set config element works in all the way , you can give absolute path , relative path or if the file is in working directory you can mention the filename alone.
    It will be very helpful if you can do that , is this in GIT repo , i mean the code.
    Thanks and Great Work!!!

      1. “File path” takes only absolute path value. File name works if the property file is placed in the same path as the jmeter bin. Is there any possible solution to load the property file from the same location as the Test.jmx file or from the repo?

        1. Deepa, Yes, It used to work with only absolute path. I have uploaded the updated version.
          It will now work with both absolute / relative path. Please download and try.

    1. I too wanted to do the same for all the utilities i have in github. Too many things going on – could not find time to do that. Will do that.

  19. I used this plug in. Installed and add in test plan. I gave path as C:\my.properties. While executing getting error

    ERROR – com.tag.jmeter.ext.config.PropertyReader: C:\my.properties (The system cannot find the file specified)

    1. Please check the path and file name once again. That would be first testcase to check if it reads the file properly. Check the log – does it give any proper message like this?

      com.tag.jmeter.ext.config.PropertyReader: Property file reader – loading the properties from C:\my.properties

    1. You can use any number of property file reader in the same test plan. 1 element is to read 1 property file. These properties are all like JMeter.properties – will be globally accessible by all the thread groups of the test plan. Not specific to a ThreadGroup.

      If you need something to specific to a thread group, then you would need to use JMeter Variables. https://jmeter-plugins.org/wiki/VariablesFromCSV/

  20. Yes,as you spoke,the property file “will be globally accessible by all the thread groups of the test plan. Not specific to a ThreadGroup.”

    But I want just that it just be used in “current thread group”, so is it easy to add a function of “sharing mode ”?

    Like the image : http://i.stack.imgur.com/UZoV5.jpg

    1. I understand your question. But properties, in general, are not specific to a thread group / function / module. If you would like to do something specific to a thread group, do not use properties. use variables and share it with all the threads.

  21. Thanks you. The property file reader is part of my JMETER framework and templates. Beautiful work. Cheers, Stijn

  22. Hi
    i am trying to use this plugin. but it’s not working for me. I am using the file reader path as C:\PartnerService\testData.properties. and it contains Target=***.***.59.38
    Users=2
    Duration=300
    Ramp=1
    When i am trying to read the properties like ${__P(Users)} , the test stops immediately. Please help me out here.

  23. Hi,
    I have senarios where i run a test for 24 hrs with random no of threads and randomly generated durations between a certain range for both.

    can it be done through the properties file.

    1. You can use ultimate thread group to define variables for load & time. Then you use Property file reader to update the values

  24. Hi
    Have just tried to read the value from the property file as you mentioned in the post. But, the values are not read from the file. Have just created a property file and debug sampler to verify the values. In the log too, couldn’t see any errors. Attached the log for reference.

    1. I have been using this for 2 years without any issues. Do you have some properties in the file? Can you try to print the property value in the log and see if it works? Enable ‘JMeter Properties’ in Debug Sampler to see them

  25. Looks like NO WORKY on Macbook Pro 🙁

    The file exists, yo! Yet attempt to load fails ~ perhaps not coded for platform independence for the Mac OS X Yosemite Version 10.10.5 (14F1021) operating system???

    2017/02/01 16:21:48 INFO – com.tag.jmeter.ext.config.PropertyReader: Property file reader – loading the properties from /Users/orbit_websig/git_src/nop-services/nop-core-service/jMeter/cpsTestPlan.properties
    2017/02/01 16:21:48 ERROR – com.tag.jmeter.ext.config.PropertyReader: /Users/orbit_websig/git_src/nop-services/nop-core-service/jMeter/cpsTestPlan.properties (No such file or directory)
    2017/02/01 16:21:48 INFO – yadda yaddy…
    ^C
    SymMacToolkit-C02Q5SKUG8WP:2.13 orbit_websig$ ls -la /Users/orbit_websig/git_src/nop-services/nop-core-service/jMeter/cpsTestPlan.properties
    -rw-r–r– 1 orbit_websig SYMC\Domain Users 157 Feb 1 16:12 /Users/orbit_websig/git_src/nop-services/nop-core-service/jMeter/cpsTestPlan.properties
    SymMacToolkit-C02Q5SKUG8WP:2.13 orbit_websig$

  26. Hi Vins, I am trying to read from the property file into a String. “String destinationStr = ${__P(destination)};” Here is what I have in my OCR.properties:
    destination=C:\\Users\\irina \\parasoft\\workspace\\FSTOR_OCR\\Datasources\\Base64enc
    original=C:\\Users\\irina\\parasoft\\workspace\\FSTOR_OCR\\Datasources\\Original

    Can you please help?
    Thanks!

    1. Irina,

      In beanshell, I would advise not to use ${..} format as it might lead to this kinda exceptions due to missing quotes.

      Best way to do this , String destination = props.get(“destination”);
      You do not need to add \\ to escape.

      destination=C:\path\to\file – should work

  27. Hello,

    I am facing Same issue as mentioned by Kris Biszta in 2016

    But when i am trying to use directly the property in Testplan as below
    def outputFolderName = ${__P(OUTPUT_SUBFOLDER_SCRIPT)};

    getting below error ( Proprty file has value OUTPUT_SUBFOLDER_SCRIPT = SITBAT15)
    javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: SITBAT15 for class: Script27

  28. I use Property File Reader in Centos 7,but error:
    2018-04-09 14:34:27,921 ERROR c.t.j.e.c.PropertyReader: /home/apache-jmeter-4.0/PerformaceTest/TestPlans/config.ini (No such file or directory)

    I also send mail to u!

    1. I confirm again..
      2018-04-12 13:14:46,664 INFO c.t.j.e.c.PropertyReader: Property file reader – loading the properties from /home/huzhq/jmete_Per/apache-jmeter-4.0/bin/dd.txt
      2018-04-12 13:14:46,665 ERROR c.t.j.e.c.PropertyReader: /home/huzhq/jmete_Per/apache-jmeter-4.0/bin/dd.txt (No such file or directory)

      but file exits!!!
      [root@localhost bin]# ll /home/huzhq/jmete_Per/apache-jmeter-4.0/bin/dd.txt
      -rw-r–r– 1 root root 25 Apr 12 13:08 /home/huzhq/jmete_Per/apache-jmeter-4.0/bin/dd.txt

      [root@localhost bin]# cat /home/huzhq/jmete_Per/apache-jmeter-4.0/bin/dd.txt
      url=http://www.baidu.com

  29. Hi, I come from china.
    I use PropertyReader, but my config have chinese character,like this:
    configUser=我
    and the file encodingI chose utf-8; file format is unix
    but, when I use ${__P(configUser)},return ???
    Why?
    use cvs if right!!

  30. Good work!
    I have a similar issue: I want to get some properties from an external web application (with HTTP resquest) and I don’t find a way to do it. More precisely I have JDBC information in a web application (host,SID,password…) and I want to get theses information in my users defined variables to execute my JMeter script and I find no way to do this properly (The JDBC connection configuration is set before any sampler or preprocessor 🙁 )

  31. It seems tag-jmeter-extn-1.1.zip is invalid. It is html file with extension .zip. Please try to unzip file.(files corrupted)

  32. Wow..! Sounds like a good and helpful feature..!
    I have a quick question. Let’s say, that at the beginning of the test execution, I have given the Number of threads as ’10’ in the properties file.
    And then I execute the test. And it will load 10 users (Threads). And now I open the properties file again and I change the number of Threads as 20.
    Will JMeter starts to execute the scripts by adding 10 more new users?
    Or do I need to do some other changes?

    1. Prop file is loaded when the test starts. So, JMeter will not know the on the fly changes on the property file changes. You need to restart your test.

Leave a Reply to vIns Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.