从字符串获取数据的 JMeter 2.10 随机变量
JMeter 2.10 Random Variable that gets data from string
我有第一个线程组获取一些 id 并将其写入变量。
这个变量有这样的视图“654564546,564564,56454,56456454,21231321,8972341,65423187”。
我需要随机选择一个 id 并将其放入另一个变量。
在 jmeter 2.07 中我使用了这段代码:
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);
但在 Jmeter 2.10 中,此代码不起作用。
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
Beanshell 错误消息信息量不大,很少提供有关实际问题的有用信息。使用 try catch 块获取更多信息。
try {
//Place your script here
}
catch (Exception e) {
log.error("OMG Beanshell ERROR::", e);
}
有关记录的错误,请参阅 jmeter.log。
您的代码看起来不错,唯一可能的失败点是您的 erroridcox
变量未设置。
添加 Debug Sampler and View Results Tree listener 以仔细检查 erroridcox
和 rnd_erroridcox
变量值。
您也可以将 debug();
函数放在脚本的开头,然后查看 STDOUT 以观察其流程 - 它将提供足够的信息来找出原因。
有关更多调试技术的说明,请参阅 How to debug your Apache JMeter script。
我有第一个线程组获取一些 id 并将其写入变量。 这个变量有这样的视图“654564546,564564,56454,56456454,21231321,8972341,65423187”。 我需要随机选择一个 id 并将其放入另一个变量。 在 jmeter 2.07 中我使用了这段代码:
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);
但在 Jmeter 2.10 中,此代码不起作用。 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
Beanshell 错误消息信息量不大,很少提供有关实际问题的有用信息。使用 try catch 块获取更多信息。
try {
//Place your script here
}
catch (Exception e) {
log.error("OMG Beanshell ERROR::", e);
}
有关记录的错误,请参阅 jmeter.log。
您的代码看起来不错,唯一可能的失败点是您的 erroridcox
变量未设置。
添加 Debug Sampler and View Results Tree listener 以仔细检查 erroridcox
和 rnd_erroridcox
变量值。
您也可以将 debug();
函数放在脚本的开头,然后查看 STDOUT 以观察其流程 - 它将提供足够的信息来找出原因。
有关更多调试技术的说明,请参阅 How to debug your Apache JMeter script。