I have 1 Thread Group with detail like this:
And here is my Regular Expression Extractor:
And here is my BeanShell PostProcessor:
And this is my response data:
<NPWP>999999999999999</NPWP>
And this is my Error:
2017/08/21 12:06:15 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.services.FileServer; // Get npwp from response data SO . . . '' Token Parsing Error: Lexical error at line 7, column 68. Encountered: "v" (118), after : "\"\\"
2017/08/21 12:06:15 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.services.FileServer; // Get npwp from response data SO . . . '' Token Parsing Error: Lexical error at line 7, column 68. Encountered: "v" (118), after : "\"\\"
Please help.
Thank you.
===========================================================================
Thank you Dmitri and user7294900, I can use both of your ways:
Groovy:
import org.apache.jmeter.services.FileServer; // Import Library
npwp = vars.get("npwp"); // Get the value of response data of SOAP/XML-RPC Request
def myFile = new File(FileServer.getFileServer().getBaseDir()+"\\variable.txt"); // Open the file
myFile << "npwp = " + npwp + "\r\n"; // Write data to file
def fileContent = myFile.text; // Read data from file
log.info("Read from file: " + fileContent); // Print the file
BeanShell:
import org.apache.jmeter.services.FileServer; // Import Library
npwp = vars.get("npwp"); // Get the value of response data of SOAP/XML-RPC Request
f = new FileOutputStream(FileServer.getFileServer().getBaseDir()+"\\variable.txt", true); // Open File(s)
p = new PrintStream(f);
p.println( "npwp = " + npwp ); // Write data to file
p.close();f.close(); // Close File(s)
([0-9]+)
otherwise it will return only one digitSwitch to JSR223 PostProcessor and Groovy language, the relevant Groovy code would be something like:
new File('variable.txt') << vars.get('npwp')
References: