JMeter - 如何读取属性文件

时间:2015-02-28 05:50:05

标签: jmeter

我的JMeter项目是这样的。

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

在非gui模式下,我可以通过命令行将.properties文件名传递给测试 - 我知道。

但是如何在调试时以GUI模式读取此属性文件?我不想将它们放在bin文件夹中。还有其他方法吗?像配置元素?编写自定义配置元素以读取属性文件是否容易?

3 个答案:

答案 0 :(得分:8)

最简单的方法是通过-q命令行参数将属性文件位置传递给在GUI中运行的JMeter:

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

替代选项是使用脚本,即您可以通过Beanshell Sampler和以下代码读取任意.properties文件:

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

您可以使用__property()__P()函数正常引用以这种方式加载的属性。

有关Apache JMeter中脚本编写的更多信息以及一种Beanshell食谱,请参阅How to use BeanShell: JMeter's favorite built-in component指南。

答案 1 :(得分:3)

我也有同样的要求。编写配置元素很容易。

参考这个。 http://www.testautomationguru.com/jmeter-property-file-reader-a-custom-config-element/

答案 2 :(得分:1)

enter image description here

添加" tag-jmeter-extn-1.1.jat"在你的jmeter的ext。然后你可以轻松使用Property file Reader

我的THScript.properties如下所示

TH_Performance_ScriptName = Web.jmx Performance_TestData = C:/结果/

访问Property文件值:

$ {__ P(Performance_TestData)}