Reputation: 6078
Is it possible to write data to a file inside a JSR223 Assertion
using javascript as the language? How can it be done?
Upvotes: 0
Views: 2806
Reputation: 168217
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:
Upvotes: 6
Reputation: 34566
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);
Upvotes: 1