从Java代码调用Jmeter函数时不执行 [英] Jmeter functions don't executing when calling from java code
问题描述
我在jmx文件中使用了一些jmeter函数。
当我使用jmeter工具从命令行运行它时,它正常运行,执行函数并返回一个值。
当我运行java代码时,它加载相同的jmx文件,它将一个函数作为一个字符串并且不返回一个值。
我已经测试了几个函数,结果是一样的。
在jtl文件中,我看到类似这样的内容 - $ {__ time(yyyy-MM-dd HH:mm:ss)}
< httpSample t =663it =0lt =631ts =1492989803759s =truelb =User-getapikey $ {__ time(yyyy-MM-dd HH:mm: ss)}rc =200rm =tn =线程组1-1dt =textde =UTF-8by =528ng =1na =1> ;
它是我的java代码,当我没有函数时它正常工作:
StandardJMeterEngine jmeter = new StandardJMeterEngine();
JMeterUtils.loadJMeterProperties(jmeterPropertiesPath);
JMeterUtils.setJMeterHome(jmeterHomePath);
JMeterUtils.initLogging();
JMeterUtils.initLocale();
SaveService.loadProperties();
HashTree testPlanTree = null;
尝试{
log.info(loading testPlanTree);
testPlanTree = SaveService.loadTree(jmxFile);
JMeter.convertSubTree(testPlanTree);
} catch(IOException ex){
log.info(将文件加载为树时出错);
log.info(ex.getMessage());
return;
}
jmeter.configure(testPlanTree);
jmeter.run();
您的代码看起来不错,只需您的项目类路径中有 ApacheJMeter_functions.jar
。该文件位于JMeter安装的lib / ext文件夹下。
您可能还想添加 查看 I'm using some jmeter functions in my jmx file.
When I run it from command line with jmeter tool, its running normally, executing the function and return a value. When I run the java code , which load the same jmx file its taking a function as a string and don't return a value. I have tested with several functions, Results are the same.
In jtl file I see something like this- ${__time(yyyy-MM-dd HH:mm:ss)} Its my java code, its working normally when I don't have a functions:
Your code looks good, just double check you have You might also want to add ResultCollector to store your test execution results into .jtl file like: Check out Five Ways To Launch a JMeter Test without Using the JMeter GUI for more information on different approaches to JMeter test execution including using Java API to kick off and develop tests. 这篇关于从Java代码调用Jmeter函数时不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault(summariser.name,summary); (sumriserName.length()> 0){
summer = new Summariser(summariserName);
if
}
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(result.jtl);
testPlanTree.add(testPlanTree.getArray()[0],logger);
<httpSample t="663" it="0" lt="631" ts="1492989803759" s="true" lb="User-getapikey ${__time(yyyy-MM-dd HH:mm:ss)} " rc="200" rm="" tn="Thread Group 1-1" dt="text" de="UTF-8" by="528" ng="1" na="1">
StandardJMeterEngine jmeter = new StandardJMeterEngine();
JMeterUtils.loadJMeterProperties(jmeterPropertiesPath);
JMeterUtils.setJMeterHome(jmeterHomePath);
JMeterUtils.initLogging();
JMeterUtils.initLocale();
SaveService.loadProperties();
HashTree testPlanTree = null;
try{
log.info("loading testPlanTree");
testPlanTree = SaveService.loadTree(jmxFile);
JMeter.convertSubTree( testPlanTree );
}catch(IOException ex){
log.info("error loading file as tree");
log.info(ex.getMessage());
return;
}
jmeter.configure(testPlanTree);
jmeter.run();
ApacheJMeter_functions.jar
in your project classpath. The file is located under "lib/ext" folder of your JMeter installation. Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}
ResultCollector logger = new ResultCollector(summer);
logger.setFilename("result.jtl");
testPlanTree.add(testPlanTree.getArray()[0], logger);