Hi,
I want to read a pdf file while executing the script using katalon testcloud
The scenario is like that
1.Found the latest downloaded file
2.Open the file
3.Verify
I am unable to find the latest downloaded file in the download folder where as i have confirmed from the chrome history that the file is being downloaded
here is my script
def static getlatestdownloadedfilename() {
try {
KeywordUtil.logInfo(“Get the latest downloaded file”)
Path userHome = Paths.get(System.getProperty("user.home"));
Path downloadsDirectory = userHome.resolve("Downloads");
KeywordUtil.logInfo("DownloadsDirectory: "+ downloadsDirectory)
File downloads = new java.io.File(downloadsDirectory.toString())
KeywordUtil.logInfo("Downloads: "+ downloads)
File[] files = downloads.listFiles()
KeywordUtil.logInfo("files: "+ files)
// Initialize variables to keep track of the most recent file
File mostRecentFile = null
long mostRecentTimestamp = 0
// Iterate through the files and find the most recently modified file
for (File file : files) {
if (file.isFile() && file.lastModified() > mostRecentTimestamp) {
mostRecentFile = file
mostRecentTimestamp = file.lastModified()
}
}
if (mostRecentFile != null) {
KeywordUtil.logInfo("The most recent downloaded file is: " + mostRecentFile.getName())
KeywordUtil.logInfo("Last modified time: " + mostRecentTimestamp)
return mostRecentFile.getName()
} else {
KeywordUtil.logInfo("No files found in the specified folder.")
}
}catch (Exception e) {
KeywordUtil.markFailed("No value found")
}
}
The same is working fine if executed using katalon studio but for testcloud its reporting that no file is found
Yes, I have reviewed it before,
In my case i don’t know the file name its randomly generated, so after download the first step I do is to fetch the latest downloaded file name
In my scenario I am unable to fetch the latest file name
Locally in the Studio everything is working as expected.
I’m using other keywords, but the essence of the code is the same with the same error.
// Get the Downloads Path
@Keyword
public static Path getDownloadPath() {
Path userHomePath = Paths.get(System.getProperty("user.home"))
Path directoryPath = userHomePath.resolve("Downloads")
return directoryPath
}
// Get the files that are present on the directory given (Downloads in this case)
@Keyword
public static Set<Path> getFilesContainedInDirectory(Path directoryPath) {
Set<Path> filesSet = Files.list(directoryPath).collect(Collectors.toSet())
WebUI.comment("<- Files in this directory: " + directoryPath + " -> " + filesSet)
return filesSet
}
// Get the latest downloaded file
@Keyword
public static String getNameLastFileDownloaded() throws Exception {
WebUI.comment('<- Getting the name of the last file downloaded ->')
Path downloadsFolderPath = getDownloadPath()
Set<Path> filesSet = getFilesContainedInDirectory(downloadsFolderPath)
if (filesSet != null && !filesSet.isEmpty()) {
// Find the latest file based on the last modified time
Path latestFile = filesSet.max { a, b ->
Files.getLastModifiedTime(a).toMillis() <=> Files.getLastModifiedTime(b).toMillis()
}
WebUI.comment("<- Last file " + latestFile)
return latestFile.getFileName().toString()
} else {
throw new Exception("No files found in the Downloads folder.")
}
}
In essence the code is the same, our error is trying to get a file from “/katalon-agent/downloads” (The path that we get in the cloud by using “getDownloadPath” which is the same code as the guide provided)
Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.
In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!
Hi @csalazar,
Have you executed tests using TestCloud on TestOps or Studio?
If you’re using TestOps, we currently don’t support retrieving the file path. However, we can verify if the file exists and provide its content and metadata. Please install the TestCloud Keyword Plugin in Katalon Studio and follow the instructions in the attached video to write your test script. (How to install plugin) Demo video
If you’re using Studio, you’ll be able to use the TestCloud Keyword Plugin after our upcoming release on September 25th.