Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter - How to read properties file

Tags:

jmeter

My JMeter project is like this.

project
    |
     ----> test (folder containing .jmx)
    |
     ----> properties (folder containing .properties files)

In the non-gui mode, I can pass .properties file name to the test via commandline - which I know.

But how can I read this property file in GUI mode while debugging? I do not want to place them in the bin folder. Is there any other way? like a config element? Is it easy to write a custom config element to read a property file?

like image 889
KitKarson Avatar asked Feb 28 '15 05:02

KitKarson


People also ask

Where is JMeter properties file?

The property files will be automatically loaded if they are found in the current directory or if they are found in the JMeter bin directory.

What is __ P in JMeter?

Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function. When using \ before a variable for a windows path for example C:\test\${test}, ensure you escape the \ otherwise JMeter will not interpret the variable, example: C:\\test\\${test}.

What is JSR223 sampler in JMeter?

JSR223 Sampler JMeter Sampler elements allow taking actions in any place in the test, without depending on a specific request. In this example a JSR223 sampler will be used to send HTTP requests to either BlazeMeter or JMeter websites, based on the thread id.

Does JMeter need JDK or JRE?

1.1. Because JMeter uses only standard Java APIs, please do not file bug reports if your JRE fails to run JMeter because of JRE implementation issues. Although you can use a JRE, it is better to install a JDK as for recording of HTTPS, JMeter needs keytool utility from JDK.


3 Answers

I too had a same requirement. It is easy to write a config element.

Refer to this. http://www.testautomationguru.com/jmeter-property-file-reader-a-custom-config-element/

like image 74
vins Avatar answered Sep 27 '22 23:09

vins


The simplest way is passing the property file location to JMeter running in GUI via -q command-line argument as:

jmeter.bat -q d:\somefolder\somefile.properties

Alternative option is using scripting, i.e. you can read arbitrary .properties file via Beanshell Sampler and the following code:

FileInputStream is = new FileInputStream(new File("d:/somefolder/somefile.properties"));
props.load(is);
is.close();

You'll be able to reference properties loaded this way as normal using __property() or __P() function.

For more information on scripting in Apache JMeter and a kind of Beanshell cookbook see How to use BeanShell: JMeter's favorite built-in component guide.

like image 30
Dmitri T Avatar answered Sep 27 '22 22:09

Dmitri T


enter image description here

Add "tag-jmeter-extn-1.1.jat" in ext of your jmeter. Then you can use Property file Reader easily

My THScript.properties looks like below

TH_Performance_ScriptName=Web.jmx Performance_TestData=c:/Result/

Accessing Property file values:

${__P(Performance_TestData)}

like image 38
Sylvia Lobo Avatar answered Sep 27 '22 22:09

Sylvia Lobo