2017-07-31 225 views
0

我想将数据写入csv文件,我能够写入一些值到csv文件,但无法写入一个值超过20个单词的一个句子。使用beanshell后处理程序无法将参数文本写入文件,给null?

文字:<msg>Congratulations! Your hall eGift Card of 120000 INR has been redeemed successfully on all Merchant Your redemption transaction number is 188</msg>

代码:

import java.io.File; 
import org.apache.jmeter.services.FileServer; 


pramvalues=vars.get("paramvalues_2"); 

Result = "FAIL"; 
Response = prev.getResponseDataAsString(); 

if(Response.contains("Congratulations! Your hall eGift Card")) 
    Result = "PASS"; 


f = new FileOutputStream("E:/ApacheJmeter/TestResults/Results.csv", true); 
p = new PrintStream(f); 

p.println(vars.get("mes")+","+Result); 

p.close(); 
f.close(); 

我得到 “MES” 为 “零”,但在调试,采样数据即将到来。

请提供帮助。

+0

调试采样器中的mes在SystemProperties/JMeterProperties或JMeterVariables中找到的数据? – user7294900

回答

1

使用Beanshell将文本行写入文件并不是最好的主意,就好像您将同时处理多个线程一样,您将遇到竞争条件并且结果文件将被损坏。

我想提出以下建议:

  1. 使用Response Assertion检查在响应Congratulations! Your hall eGift Card文本的存在
  2. 使用Sample Variables财产“告诉” JMeter的存储mes变量值到.jtl结果文件。你可以这样做在两个方面:

    • 以下行添加到user.properties文件(生活JMeter的 “bin” 文件夹)

      sample_variables=mes 
      
    • 或通过-J command-line argument like

      传递
      jmeter -Jsample_variables=mes -n -t test.jmx -l resutl.jtl 
      

      请参阅Apache JMeter Properties Customization Guide了解更多关于JMeter属性以及设置和覆盖它们的方法

      假设一切顺利,您应该在您的.jtl结果文件中看到一个名为mes的额外列,它将包含${mes}变量值。


如果你仍然想使用脚本切换到JSR223 ElementsGroovy language,也可能是使用Critical Section Controller避免竞争条件是一个好主意。

相关问题