2015-06-19 60 views
0

我有第一個線程組獲取一些id並將其寫入變量。 這個var有這樣的視圖「654564546,564564,56454,56456454,21231321,8972341,65423187」。 我需要隨機選取其中一個id並將其放到另一個變量中。 在JMeter的2.07我用這個代碼:JMeter 2.10從字符串獲取數據的隨機變量

import java.util.Random; 

String[] erroridcox = (vars.get("erroridcox")).split(","); 

int id1 = new Random().nextInt(erroridcox.length); 
String randerror = (erroridcox[id1]); 

vars.put("rnd_erroridcox", randerror); 

但在2.10的JMeter這個代碼不起作用。 的JMeter日誌說:

jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.util.Random; String[] erroridcox = (vars.get("erroridcox")).split(. . . '' : Typed variable declaration 
+0

發現問題。問題是由於我的erroridcox字符串具有這樣的視圖:'code'[「45654」,「564564」,「908098」]'code'。你能否讓我跳過符號[]「 –

+0

我已經閱讀過有關trim函數,但我不知道如何在BeanShell預處理器中使用它。 –

回答

0

您的代碼看起來不錯,唯一可能的故障點是您的erroridcox變量未設置。

添加一個Debug SamplerView Results Tree listener來仔細檢查erroridcoxrnd_erroridcox變量值。

此外,您可以在腳本的開頭部署debug();函數,並查看STDOUT以觀察其流量 - 它將提供足夠的信息來找出原因。

請參閱How to debug your Apache JMeter script瞭解更多調試技術。

0

BeanShell的錯誤信息是不是超級翔實而很少提供有關實際問題有用的信息。使用try catch塊獲取更多信息。

try { 
    //Place your script here 
} 
catch (Exception e) { 
    log.error("OMG Beanshell ERROR::", e); 
} 

請參閱記錄錯誤的jmeter.log。