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
@cagus you found the cause yourself: on the agent there is no ~/Downloads folder, the browser downloads somewhere else (or nowhere, if the folder is missing). so do not guess the folder, tell chrome where to put the file, inside the project so it exists everywhere:
import com.kms.katalon.core.configuration.RunConfiguration
String dlDir = RunConfiguration.getProjectDir() + '/downloads'
new File(dlDir).mkdirs()
RunConfiguration.setWebDriverPreferencesProperty('prefs', [
'download.default_directory': dlDir,
'download.prompt_for_download': false,
'safebrowsing.enabled': true
])
WebUI.openBrowser('')
then your polling loop looks in dlDir instead of user.home. two more things that bite on agents: also ignore the .crdownload temp file while polling (name ends with .crdownload means not finished), and if the agent runs chrome headless on an old katalon version downloads were disabled by default, upgrading to 10.x headless fixes that. with the folder forced like this the same test passes locally and on the agent.