This is the code I'm trying to execute in beanshell sampler:
import java.lang.*;
import java.util.*;
String name_lead = vars.get("Name_lead");
String[] lead = name_lead.split("\\s+");
//vars.put("myname",lead[0]);
//vars.put("myname1",lead[1]);
//vars.put("myname2",lead[2]);
for(int i=1; i<=Integer.parseInt(vars.get("title_pass_matchNr")); i++)
{
String title = vars.get("title_pass_"+i);
String fname = vars.get("firstname_"+i);
String lname = vars.get("lastname_"+i);
String[] fn = fname.split("");
//vars.put("title",title);
//vars.put("fname",fn[1]);
//vars.put("lname",lname);
if(lead[i-1].equals(title) && lead[i].equals(fn[1]) && lead[i+1].equals(lname))
{
vars.put("namep",lead[i]);
}
}
But I'm getting the following error:
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.lang.; import java.util.; String name_lead=vars.get("Name_lead"); . . . ''
I'm not able to understand it. Can sombody help me? How do I fix this?
name_lead
has something like Mr P singh ..and taking using regex extractor
There is a good way to convert this Error invoking bsh method
error into a more human-readable stacktrace: put your code into a try block like:
try {
//your code here
}
catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
This way you will able to see the exception details in jmeter.log file
Another way to add debug() directive at the very beginning of your Beanshell script. This way you'll get a lot of debugging output into stdout.
See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on using Beanshell in JMeter tests and scripts development and troubleshooting