Type your question here. Then choose a suitable category and tag(s)
did you mean report file?
No, I have Test Case that clicks the download button and i want verify/assert if the file is downloaded or not. I tried this code, but this is only working on my local. When I run this in Katalon Testops, it’s not working.
Thread.sleep(5000)
String home = System.getProperty("user.home");
File userDownloads = new File(home+"/Downloads/");
File[] listofFiles = userDownloads.listFiles();
boolean found = false;
File f= null;
for(File listOfFile : listofFiles) {
if(listOfFile.isFile()) {
String FileName = listOfFile.getName();
if(FileName.contains("RED-T98")) {
// File fileD = new File(home+"/Downloads/"+FileName);
// fileD.delete();
listOfFile.delete()
found=true;
break;
}
}
}
try{
assert found==true;}
catch(Exception e) {
Thread.sleep(2000)
assert found == true;
}
Hi @cagus,
Welcome to our community. Thank you for sharing your issue.
Based on your code, I think that your handling is not quite correct. I would like to suggest the below code and let me know if it works/ not. Thank you
String home = System.getProperty("user.home");
File userDownloads = new File(home + "/Downloads/");
boolean found = false;
int retryCount = 0;
int maxRetries = 10; // Adjust based on expected download time
while (!found && retryCount < maxRetries) {
File[] listOfFiles = userDownloads.listFiles();
if (listOfFiles != null) {
for (File listOfFile : listOfFiles) {
if (listOfFile.isFile() && listOfFile.getName().contains("RED-T98")) {
found = true;
println("File found: " + listOfFile.getName());
break;
}
}
}
if (!found) {
println("File not found, retrying... (" + retryCount + ")");
Thread.sleep(2000); // Wait before retrying
}
retryCount++;
}
assert found : "File RED-T98 was not downloaded successfully!";
Hi @cagus,
Can you please try my suggestion and let us know if it works? Thank you
still not working. seems like the path for Downloads folder does not exist when run in a katalon agent
Can you share the error trace