I'm storing data in CSV file, I want to remove CSV file content after test execution.
Or delete csv file and create it again before new test run. Was using tearDown
Thread Group and BeanShell
Samper, and it does not work.
And If adding new csv again before execution, where should I write the script, cause test will not be run, untill system find needed csv file.
I have a script which in the end produces customers to csv file, but before customers creation csv file is deleted. I used setUp Thread Group which is executed before other thread groups and in that setup group I used BeanShell Sampler with such code:
import org.apache.jmeter.services.FileServer;
String customers = FileServer.getFileServer().getBaseDir() + "\\customers.csv";
try {
File file = new File(customers);
if (file.delete()) {
System.out.println(file.getName() + " is deleted!");
} else {
System.out.println("Delete operation has failed!");
}
} catch (Exception e) {
e.printStackTrace();
}
And it works as expected.
setUp thread Group
for creating new file
Check this example for file creation
teardown thread Group
for deleting the file new File("/path/to/your/file.csv").delete();
Just another BeanShell example, delete the csv of stored filename.
import org.apache.commons.io.FileUtils;
String filename = "D://jmeter//"+vars.get("csvfilename")+".csv";
new File(filename).delete();
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.