在我的JMeter测试计划中,我正在尝试将所有错误写入日志。我正在使用如下配置的BeanShell后处理器
org.apache.jorphan.util.JMeterStopThreadException: End of sequence
at org.apache.jmeter.functions.FileToString.execute(FileToString.java:105)
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:142)
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:118)
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:101)
at org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:274)
at org.apache.jmeter.config.Argument.getValue(Argument.java:146)
at org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:236)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPostData(HTTPHC4Impl.java:1111)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.handleMethod(HTTPHC4Impl.java:453)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:329)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: File 'C:\JMeter\test\payloads\Request_1.json' does not exist
at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:299)
at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1711)
at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1734)
at org.apache.jmeter.functions.FileToString.execute(FileToString.java:102)
我正在尝试进行一个简单的测试,其中HTTP请求正在执行POST,该POST从c:jmeter / tests / payloads传入json文件,其中该目录不再存在。 (假设某人不小心将其删除了......)
问题是测试正在停止(见下文)并且从未到达BeanShell将错误写入日志文件。我需要捕获所有错误回复,只有错误回复。
我不知道如何处理这件事。我已经阅读了Jmeter. BeanShell PostProcessor和其他人,但他们没有解决当它没有进入BeanShell时会发生什么的问题。
感谢任何帮助!
import org.apache.jmeter.services.FileServer;
if (ResponseCode != null && ResponseCode.equals("200") == true) {
SampleResult.setResponseOK();
}
else if (!ResponseCode.equals ("200") == true ) {
Failure = true;
FailureMessage ="Creation of a new record failed. Response code " + ResponseCode + "." ; // displays in Results Tree
print ("Creation of a new record failed: Response code " + ResponseCode + "."); // goes to stdout
log.warn("Creation of a new record failed: Response code " + ResponseCode); // this goes to the JMeter log file
// Static elements or calculations
part1 = "Unable to generate a new record via POST. The response code is: \"";
part2 = "\". \n\n For response code = \'Non-HTTP ressponse\', verify the payload file still exists. \n For response code = 409, check the recordTypeId and recordGrpId combination for validity. \n For response code = 500, verify the database and its host server are reachable. ";
// Open File(s)
FileOutputStream f = new FileOutputStream(FileServer.getFileServer().getBaseDir() + "\\error.csv");
PrintStream p = new PrintStream(f);
// Write data to file
p.println( part1 + ResponseCode + part2 );
// Close File(s)
p.close();
f.close();
}
解
根据Dmitri的反馈,我已经从Beanshell PostProcessor切换到Beanshell Assertion。经过一些调整后,我得到它的工作,它现在只将错误(响应!= 200)写入errors.csv文件。它不是在前一次运行中附加文件,而是在每次运行时覆盖,因此只捕获最后一次运行的错误。
如果有人认为我的解决方案可以改进,我很乐意收到反馈意见。再次感谢Kiril和Dmitri。
$table->decimal('m1',12,2)->default(0)->nullable();
答案 0 :(得分:1)
ResponseCode
,Failure
和FailureMessage
,转而使用Beanshell Assertion。 ResponseCode.equals("200")
子句假定响应成功,错误响应通常包含响应代码> 400 有关JMeter中Beanshell脚本编写的全面信息,请参阅How to Use BeanShell: JMeter's Favorite Built-in Component指南。