Method requires 2 post-processors on Sampler element:
Type: Regular Expression Extractor
Extracts some data from the request into a variable (say, “myData”)
Type: BSF Post-Processor
Saves the extracted data in the variable into the file:
String filename = vars.get("userVariableWithFileName"); String message = "At " + System.currentTimeMillis() +" data is " + vars.get("myData"); FileOutputStream f = new FileOutputStream(filename, true); PrintStream p = new PrintStream(f); this.interpreter.setOut(p); print(message); f.close(); vars.put("myData", "N/A"); // Make sure we don't accidentally record the same data twice
I would not recommend this method for large production-scale load tests, but for smaller tests it could be a quick and convenient way to retrieve and save some data from request, without changing script in any significant way. The performance of this piece largely depends on the the performance of the underlying hard disk, which is why it’s not good for large-scale performance. But it gives a lot of flexibility in how and what you write (e.g. each user could have its own file; the format of the file is absolutely up to you; you may do some statistics on the fly, and so on). Thus might be worth it.