如何从自身内部获取 Jmeter .jmx 项目文件的绝对文件夹位置? [英] How to get the absolute folder location of a Jmeter .jmx project file from within itself?

查看:16
本文介绍了如何从自身内部获取 Jmeter .jmx 项目文件的绝对文件夹位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 Maven 执行的 Jmeter 项目,并且能够通过路径 src/test/jmeter/external-scripts-dir/script1.bsh 找到外部 Beanshell 脚本,但是当我直接在我的计算机上的 GUI 中运行 Jmeter 相对位置不起作用并且测试不能独立运行.这迫使我从 Maven 运行 Jmeter.

I have a Jmeter project that is executed by Maven and is able to locate external Beanshell scripts by the path src/test/jmeter/external-scripts-dir/script1.bsh , but when I run Jmeter directly in the GUI on my computer the relative location doesn't work and the tests cannot be ran standalone. This forces me to run Jmeter from Maven.

所以,我有一个位于 Maven 布局位置的项目文件,例如 C:filesgitprojectAsrc estjmeterProject.jmx 但是因为我从它的安装中运行了 jmeterC:Jmeter2.12 文件夹,找不到我之前提到的外部脚本的相对位置.

So, I have a project file located at a Maven layout location like C:filesgitprojectAsrc estjmeterProject.jmx but since I ran jmeter from its installation folder at C:Jmeter2.12 , it cannot find the relative location of the external script I mentioned earlier.

为了解决这个问题,我需要为包含 .jmx 文件的目录设置一个变量.有没有办法做到这一点?

To solve this, all I need is to set a variable to the directory containing the .jmx file. Is there any possible way to do this?

我可以很容易地(使用以下代码)动态确定 Jmeter 的主页(C:Jmeter2.12),但这并不能帮助我获得项目文件的位置.

I can dynamically determine the home of Jmeter ( C:Jmeter2.12 ) pretty easily (using the following code) but that doesn't help me get the location of the project file.

${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer
  .getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}

是否有类似上述代码的东西可以让我推断出项目文件的位置?

Is there something similar to the above code that would allow me to deduce the project file location?

推荐答案

如果您正在寻找在 GUI 模式下运行 JMeter 时定位当前脚本的方法,您可以尝试以下 Beanshell 表达式:

If you're looking for the way to locate current script when you run JMeter in GUI mode you can try the following Beanshell expression:

${__BeanShell(import org.apache.jmeter.gui.GuiPackage;GuiPackage.getInstance().getTestPlanFile();)}

如果你把它分成 5 行,就会有:

If you brake this down into 5 lines there will be:

import org.apache.jmeter.gui.GuiPackage;
import org.apache.commons.io.FilenameUtils;
String testPlanFile = GuiPackage.getInstance().getTestPlanFile();
String testPlanFileDir = FilenameUtils.getFullPathNoEndSeparator(testPlanFile);
vars.put("testPlanFileDir", testPlanFileDir);
log.info("testPlanFileDir:" + testPlanFileDir);

您当前的 .jmx 文件填充存储为 scriptFile JMeter 变量.

Your current .jmx file fill be stored as scriptFile JMeter Variable.

参考文献:

这篇关于如何从自身内部获取 Jmeter .jmx 项目文件的绝对文件夹位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆