簡體   English   中英

Jmeter BeanShell-訪問響應數據-Beanshell錯誤?

[英]Jmeter BeanShell - Access Response Data - Beanshell error?

我的Beanshell后處理器中有此代碼

String line;
String[] words;

line = SampleResult.getResponseMessage(); log.info(msg);

words  = line.split("*");

log.info("Here We are"); 

for (int i = 0; i < words.length; i++) {
  log.info(words[i]);
 }

這是我得到的錯誤

2017/02/21 14:23:31錯誤-jmeter.util.BeanShellInterpreter:調用bsh方法錯誤:eval源文件:內聯評估: String line; String[] words; line = SampleResult.getResponseMessage(); log.inf . . . '' : Attempt to resolve method: getResponseMessage() on undefined variable or class name: SampleResult 2017/02/21 14:23:31 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: String line; String[] words; line = SampleResult.getResponseMessage(); log.inf . . . '' : Attempt to resolve method: getResponseMessage() on undefined variable or class name: SampleResult 2017/02/21 14:23:31 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: String line; String[] words; line = SampleResult.getResponseMessage(); log.inf . . . '' : Attempt to resolve method: getResponseMessage() on undefined variable or class name: SampleResult 2017/02/21 14:23:31 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:字符串行; String []個字; 行= SampleResult.getResponseMessage(); log.inf '':嘗試解析方法:未定義的變量或類名稱上的getResponseMessage():SampleResult

嚴格來說,要擺脫該錯誤,您需要用prev替換SampleResult

prev-(SampleResult)-提供對上一個SampleResult的訪問

來源

因此解決異常:

line = prev.getResponseMessage(); 
log.info(line);

您總是可以看到對象本身為您提供的變量列表:

在此處輸入圖片說明

但是,如果我理解正確,則希望獲取數據而不是采樣器的響應消息 因此,您可能要使用getResponseDataAsString()而不是getResponseMessage()

所以一起:

line = prev.getResponseDataAsString(); 
log.info(line);
  1. SampleResult是您可以通過這種方式使用的東西
  2. ResponseMessage!=響應主體

因此,請使用以下方法之一

  • line = new String(data);
  • line = prev.getResponseDataAsString();
  • line = ctx.getPreviousResult().getResponseDataAsString());

哪里:

還可以考慮使用JSR223 PostProcessorGroovy語言而不是Beanshell,因為Groovy更加兼容Java,性能更好並且具有不錯的語言功能,這將使您的代碼看起來和工作得更好。 有關詳細信息,請參見Groovy是新黑人

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM