JMeter - 如何读取属性文件

Kit*_*son 7 jmeter

我的JMeter项目是这样的.

project
    |
     ----> test (folder containing .jmx)
    |
     ----> properties (folder containing .properties files)
Run Code Online (Sandbox Code Playgroud)

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

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

Dmi*_*i T 11

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

jmeter.bat -q d:\somefolder\somefile.properties
Run Code Online (Sandbox Code Playgroud)

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

FileInputStream is = new FileInputStream(new File("d:/somefolder/somefile.properties"));
props.load(is);
is.close();
Run Code Online (Sandbox Code Playgroud)

您将能够使用__property()__P()函数正常引用以这种方式加载的属性.

有关Apache JMeter中的脚本和一种Beanshell食谱的更多信息,请参阅如何使用BeanShell:JMeter最喜欢的内置组件指南.


vin*_*ins 5

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

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