2

I was working with on a Jmeter script. At the 1st Response I have extract a lengthy code which I have to pass to the next request. Unfortunately, the 1st request contains "\x2D" characters , which need to be replaced with "-". Is there any way to do this. I tried with below code on a BeanShell PostProcessor, but its giving me an error.

def originalValue = vars.get("BE_stateToken");
def newValue = originalValue.replace("\x2D", "-");
vars.put("myVar", newValue);


log.info("Variable myVar value: " + vars.get("myVar"));

Below are the errors I'm getting.

2023-08-29 14:17:48,365 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: def originalValue = vars.get("BE_stateToken"); def newValue = originalValue.re . . . '' : Typed variable declaration : Class: def not found in namespace 2023-08-29 14:17:48,365 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: def originalValue = vars.get("BE_stateToken"); def newValue = originalValue.re . . . '' : Typed variable declaration : Class: def not found in namespace 2

1 Answer 1

2

We cannot help you without seeing the details of the "error" you're getting. Check jmeter.log file for any suspicious entries.

The code is almost fine, you just need to escape a backslash with another backslash:

def newValue = originalValue.replace("\\x2D", "-");

enter image description here

You can also consider using __strReplace() function, in this case you won't need to do any scripting. It can be installed as a part of Custom JMeter Functions bundle using JMeter Plugins Manager

1
  • Thanks, @Dimirti, I was able to replace the string with the help of your response.
    – ChathuD
    Commented Aug 29, 2023 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.