regex - I Want to execute Regular expression using beanshell preprocessor in Jemeter -
here code have written,
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"); } }
it giving error :error - jmeter.util.beanshellinterpreter: error invoking bsh method: eval sourced file: inline evaluation of: import java.util.regex.*; import java.util.regex.matcher; import java.util.reg . . . '' token parsing error: lexical error @ 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 . . . '' token parsing error: lexical error @ line 14, column 64. encountered: "\" (92), after : ""
can 1 me resolve issue ?
- missing semicolon after
int count = 50
issues escaping
tmp
string. if original looks as:wirereviewapprove:headertable:0:wirestatusvalue">\(\.\+\?\)<\/span>
you need make like:
string tmp = "wirereviewapprove:headertable:0:wirestatusvalue\">\\(\\.\\+\\?\\)<\\/span>";
full beanshell code:
int count = 50; (int = 0; < 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[" + + "]", "true"); } }
see how use beanshell: jmeter's favorite built-in component guide more information on beanshell scripting in jmeter.
n.b. better switch jsr223 sampler , groovy language in case of large loads beanshell can bottleneck.
Comments
Post a Comment