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 ?

  1. missing semicolon after int count = 50
  2. 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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -