JMeter - 如何读取属性文件

JMeter - How to read properties file

我的JMeter项目是这样的

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

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

但是如何在调试时以 GUI 模式读取这个 属性 文件?我不想将它们放在 bin 文件夹中。还有别的办法吗?像一个配置元素?编写自定义配置元素来读取 属性 文件容易吗?

最简单的方法是通过 -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() or __P() 函数正常引用以这种方式加载的属性。

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

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

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

在你的 jmeter 的 ext 中添加 "tag-jmeter-extn-1.1.jat"。然后就可以轻松使用属性文件Reader

我的 THScript.properties 如下所示

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

正在访问 属性 文件值:

${__P(Performance_TestData)}