Reading a pdf in katalon testcloud

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

1 Like

Hi,

I found this guide on downloading files with Testclouds. Can you please take a look and try?

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