Reputation: 53
I am trying to duplicate a file using JMeter,
The scenario:
I have tried to do that with Simple Data Writer but it didn't work.
Upvotes: 1
Views: 488
Reputation: 168217
If you need to generate 20 files with different age you can do it using any of JSR223 Test Elements. Example Groovy code would look like:
def json = new groovy.json.JsonSlurper().parseText("{\"name\":\"John\",\"age\":\"\"}")
def builder = new groovy.json.JsonBuilder(json)
1.upto(20, {
builder.content.age= "${it}"
def writer = new File('file' + "${it}" + ".json").newWriter()
writer << builder.toPrettyString()
writer.close()
})
Once you execute your test it will create the following files in the "bin" folder of your JMeter installation:
file1.json
- with the age of 1
file2.json
- with the age of 2
file20.json
- with the age of 20
References:
Upvotes: 1
Reputation: 58892
You have JSR223 Elements as Sampler or Pre processor which you can add powerful script,
The easiest is to replace age_place
with your value, for example if saved in variable age_place
:
f = new FileOutputStream("c:\\temp\\template.json", false);
p = new PrintStream(f);
this.interpreter.setOut(p);
print("{\"name\":\"John\",\"age\":\"age_place\"}".replaceAll("age_place", vars.get("age_place")));
f.close();
Upvotes: 1