I am trying to read an xml file, update values and save as new file to upload in each iteration But when I run with 2 iteration the JSR223 sampler doesn't create second xml . please help. My code
import org.apache.commons.io.FileUtils;
try {
String content = FileUtils.readFileToString(new File("C:/test.xml"));
content = content.replaceAll(">70<", ">${counterincrement}<");
content = content.replaceAll(">file_name<", ">${newFileName}${counterincrement}<");
vars.put("content", content);
FileUtils.writeStringToFile(new File("E:/${newFileName}${counterincrement}.xml"), content);
}
catch (Throwable ex) {
log.info("What happened?", ex);
throw ex;
}
The request doesnt fail for the second iteration it just doesn't create a new xml file .
We are not telepathic enough to guess what's wrong without seeing your code so please get familiarized with How do I ask a good question? SO documentation chapter
Blind shot: you're using a JMeter Function or a Variable directly in your assertion code. Given you have Cache compiled script if available
box checked JMeter will resolve the value only once and cache it for the future use. So basically the assertion runs twice but it overwrites the file on 2nd iteration so you have the data from 2nd (or whatever is the last iteration) only.
So if you have a JMeter Variable in your script either use vars
shorthand or put it to "Parameters" section. The same applies to JMeter Functions.
Like instead of ${foo}
use vars.get('foo')
or do something like this: