这是我写的代码,
import java.util.regex.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String pStr ="Review Required";
int count = 50
for(int i=0;i<count;i++)
{
String tmp = "wireReviewApprove:headerTable:0:wireStatusValue">\(\.\+\?\)<\/span>";
Pattern patternN = Pattern.compile(tmp);
Matcher matcher = patternN.matcher(pStr);
if (matcher.find())
{
sampler.addArgument("selectedItemId["+i+"]","true");
}
}
给出错误:ERROR - jmeter.util.BeanShellInterpreter:调用bsh方法时出错:eval源文件:内联评估:import java.util.regex.*; import java.util.regex.Matcher; import java.util.reg . . . '' Token Parsing Error: Lexical error at line 14, column 64. Encountered: "\\" (92), after : ""
2015/07/14 08:15:15 WARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:
import java.util.regex。*; import java.util.regex.Matcher; import java.util.reg。 。 。 &#39;&#39;令牌解析错误:第14行第64列的词汇错误。遇到:&#34; \&#34; (92),之后:&#34;&#34;
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
int count = 50
转义tmp
字符串的问题。如果原件看起来像:
wireReviewApprove:headerTable:0:wireStatusValue">\(\.\+\?\)<\/span>
你需要看起来像:
String tmp = "wireReviewApprove:headerTable:0:wireStatusValue\">\\(\\.\\+\\?\\)<\\/span>";
Full Beanshell代码:
int count = 50;
for (int i = 0; i < count; i++) {
String tmp = "wireReviewApprove:headerTable:0:wireStatusValue\">\\(\\.\\+\\?\\)<\\/span>";
Pattern patternN = Pattern.compile(tmp);
Matcher matcher = patternN.matcher(pStr);
if (matcher.find()) {
sampler.addArgument("selectedItemId[" + i + "]", "true");
}
}
有关JMeter中Beanshell脚本的更多信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。
N.B。最好切换到JSR223 Sampler和Groovy语言,就像大负载一样,Beanshell可能成为瓶颈。