当我从 gui 调用 jmeter test 时,它可以正常工作,但是当我调用标准 JMeter 引擎的run或runTests时,它不会在/tmp/jmeter中保存任何内容。
我怎样才能让它发生?如何从保存响应保存到文件侦听器的 Java 代码中执行和获取 api 有效负载。
我使用 JMeter 5.0
JMeterUtils.setJMeterHome(getJmeterHome());
JMeterUtils.loadJMeterProperties(jmeterPropertiesFile.toString());
JMeterUtils.initLocale();
StandardJMeterEngine standardJMeterEngine = new StandardJMeterEngine();
standardJMeterEngine.configure(rootTree);
standardJMeterEngine.run();
生成器类
public class MySaveResponseToFileBuilder {
private String name;
private String comment;
private boolean enabled;
private String fileName;
private String variableName;
public MySaveResponseToFileBuilder() {
this.name = "Save Response to File";
this.enabled = true;
this.comment = "";
this.fileName = "";
this.variableName = "";
}
public String getName() {
return name;
}
public MySaveResponseToFileBuilder setName(String name) {
this.name = name;
return this;
}
public String getComment() {
return comment;
}
public MySaveResponseToFileBuilder setComment(String comment) {
this.comment = comment;
return this;
}
public boolean isEnabled() {
return enabled;
}
public MySaveResponseToFileBuilder setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}
public String getFileName() {
return fileName;
}
public MySaveResponseToFileBuilder setFileName(String fileName) {
this.fileName = fileName;
return this;
}
public String getVariableName() {
return variableName;
}
public MySaveResponseToFileBuilder setVariableName(String variableName) {
this.variableName = variableName;
return this;
}
public ResultSaver build() {
ResultSaver resultSaver = new ResultSaver();
resultSaver.setName(this.getName());
resultSaver.setComment(this.getComment());
resultSaver.setEnabled(this.isEnabled());
resultSaver.setVariableName(this.getVariableName());
resultSaver.setFilename(this.getFileName());
resultSaver.setProperty(TestElement.TEST_CLASS, ResultSaver.class.getName());
resultSaver.setProperty(TestElement.GUI_CLASS, ResultSaverGui.class.getName());
return resultSaver;
}
}
ResultSaver resultSaver = new MySaveResponseToFileBuilder().setName("Save Response to File").setFileName("/tmp/jmeter/${__samplerName()}").build();