[英]Write to a file using JSR223 Assertion
Is it possible to write data to a file inside a JSR223 Assertion
using javascript as the language? 是否可以使用javascript作为语言将数据写入JSR223 Assertion
的文件? How can it be done? 如何做呢?
It is somehow possible. 这是有可能的。
Due to security reasons you cannot access file system in JavaScript, but according to JSR223 specification is is not only possible to call scripts from Java but you can do the opposite thing - call Java from scripts, in your case from JavaScript. 出于安全原因,您无法使用JavaScript访问文件系统,但是根据JSR223规范,不仅可以从Java调用脚本,而且可以做相反的事情-从脚本调用Java(在您的情况下从JavaScript调用)。 The relevant code would be: 相关代码为:
var writer = new java.io.PrintWriter('your_file.txt')
writer.write('hello')
writer.close()
Reference material and code snippets: 参考资料和代码段:
I'd rather use Groovy (and check cache checkbox) to follow best-practices: 我宁愿使用Groovy(并检查缓存复选框)来遵循最佳实践:
It's just this: 就是这样:
import org.apache.commons.io.FileUtils;
FileUtils.writeStringToFile(new java.io.File("/data/jmeter/test.log"),
"String to append",
"UTF-8",
true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.