这是我的正则表达式提取器:
这是我的BeanShell PostProcessor:
这是我的回复数据:
<NPWP>999999999999999</NPWP>
这是我的错误:
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 : "\"\\"
请帮忙。
谢谢。
============================================ ===============================
谢谢Dmitri和user7294900,我可以使用你的两种方式:
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 :(得分:2)
([0-9]+)
,否则只返回一位数切换到JSR223 PostProcessor和Groovy语言,相关的Groovy代码如下:
new File('variable.txt') << vars.get('npwp')
参考文献:
答案 1 :(得分:1)
您有额外的分隔符,您可以使用getFullPathNoEndSeparator
函数删除它并稍后添加\\variable.txt
:
import org.apache.commons.io.FilenameUtils;
import org.apache.jmeter.services.FileServer;
String baseDir = FilenameUtils.getFullPathNoEndSeparator(FileServer.getFileServer().getBaseDir() );
f = new FileOutputStream(baseDir+"\\variable.txt");
答案 2 :(得分:0)
将txt文件类型更改为csv即可..为我工作
请参阅链接以获取详细步骤和Code to write parsed json variable value to file