I am trying to validating that a particular file exists or not in a folder using BeanShell sampler in jmeter.
import org.apache.commons.io.FileUtils;
String filename;
String tempFile;
if(vars.get("LogFile") != null)
{
filename = vars.get("LogFile");
log.info("File exist");
}
else {
log.info("File exist");
}
I have defined LogFile in user-defined variable. And it is defined as LogFile : D:\Jmeter\Jmeter.log, currently, it is always returning true because it is not validating whether the file really exists or not.
To check you need to add a file exists check
if (new File(filename).exists()) {
log.info("File exist");
} else {
log.info("File not exist");
}