J. Doem
J. Doem

Reputation: 649

Jmeter JSR223 PostProcessor unexpected char: '\'

I am using groovy JSR223 Post processor to process response and save to file.

Here is my configuration

in test plan adding UDV:

USER_PATH : ${__groovy(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__groovy(File.separator)}

JSR223 PostProcessor Script

def x = var.get ("${USER_PATH}");

out.print(x);

and i got following error in jmeter log viewer

ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script18.groovy: 1: unexpected char: '\' @ line 1, column 21.
   def x = var.get ("C:\Users\wins\learn\test\");

Seems groovy expected double slash from USER_PATH variable? what should i do to avoid unexpected char error from groovy?

thanks

Upvotes: 0

Views: 2891

Answers (2)

Dmitri T
Dmitri T

Reputation: 168157

Your code in the JSR223 PostProcessor Script is wrong:

  1. The keyword for accessing JMeter Variables is vars
  2. You should remove dollar sign and curly braces from your USER_PATH expression
  3. OUT shorthand is case sensitive

Fixed code will be

def x = vars.get ("USER_PATH");
OUT.print(x);

More information: Apache Groovy - Why and How You Should Use It

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58872

You need to get by variable key and not value, change code to:

  def x = vars.get("USER_PATH");

Upvotes: 1

Related Questions