Is it possible to write data to a file inside a JSR223 Assertion
using javascript as the language? 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. 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:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.