天天看點

Jmeter報這個錯BeanShell Sampler故事背景問題解決思路嘗試解決問題

故事背景

jmeter中建立一個BeanShell Sampler。編寫了一個BeanShell Sampler腳本。結果,報錯了…… 代碼如下:

String s = "s";
String y = "y";
boolean result = s.equals(y);
vars.put("result2",result);
           

如圖:

Jmeter報這個錯BeanShell Sampler故事背景問題解決思路嘗試解決問題

報錯如下:

Jmeter報這個錯BeanShell Sampler故事背景問題解決思路嘗試解決問題

詳細報錯代碼:

Error Count: 
Response code: 
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval        Sourced file: inline evaluation of: ``String s = "s"; String y = "y"; boolean result = s.equals(y); vars.put("result2" . . . '' : Error in method invocation: Method put( java.lang.String, boolean ) not found in class'org.apache.jmeter.threads.JMeterVariables'
           

問題解決思路

1、看報錯資訊

2、根據報錯内容調試代碼

嘗試解決問題

報錯的提示如下

沒有找到put( java.lang.String, boolean )這個方法。

大膽猜測,put的value應該是String。驗證猜想:

Jmeter報這個錯BeanShell Sampler故事背景問題解決思路嘗試解決問題

運作結果:

Jmeter報這個錯BeanShell Sampler故事背景問題解決思路嘗試解決問題

Good!運作成功!

繼續閱讀