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	(3694 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:

Categories: Articles, Best Practices, JMeter

69 comments

  • satish

    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

  • Guneet

    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

    • vIns

      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.

  • Guneet

    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

    • vIns

      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.

  • bhanu

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

  • bhanu

    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

  • wevanson

    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?

  • Nina

    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?

    • vIns

      Weird. I see a similar issue reported by someone else. I will take a look for sure.
      Thanks for pointing it out.

  • Kris Biszta

    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.

      • Kris

        I will try to check it clean after restart with debug sampler and get back if this will give any more info.

      • Kris Biszta

        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.

        • vIns

          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.

  • sams

    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)}/

  • sams

    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??

    • vIns

      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)}

  • sams

    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

    • vIns

      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”

  • sams

    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 ??

    • vIns

      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!

  • sams

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

  • tylor

    Hello. There is no download on the on the link given for Property File Reader – Config Element

    • vIns

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

  • Nish

    Hi ,

    I want to insert the throughtput values,i tried using Property File but it is failing.

  • Eric

    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

  • Eric

    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?

    • vIns

      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.

  • Ranjitha

    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*)

  • Vineethpp

    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

    • vIns

      You still face the issue? Relative path should work. Confirm. I will also take a look.

  • Vineethpp

    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!!!

      • Deepa

        “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?

        • vIns

          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.

    • vIns

      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.

  • Nishant

    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)

    • vIns

      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

    • vIns

      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/

  • Jack

    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

    • vIns

      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.

  • Stijn Schepers

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

  • Sophiya

    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.

  • sailaja

    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.

    • vIns

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

  • SMP

    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.

    • vIns

      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

  • orbit websig

    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$

  • Irina

    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!

    • vIns

      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