To verify a file with the time stamp in its name

As a part of testing we have to download a file from website .the file downloaded is always appended with the date and time stamp. We need to verify the down loaded file and delete it after verification. Every time we set the time stamp and date stamp there is 1 sec diff to the name of the file downloaded which is due to the step being executed 1 s before.Is there any suggestion to handle this.

Hello,

if I get it correctly, your file name would look like {timestamp}_{timestamp+1}.txt, doesn’t it?

If so (and given that you know at least one of the timestamps), this code would work.

import com.kms.katalon.core.util.KeywordUtil

long filenameTs = System.currentTimeMillis() / 1000L
long filenameAppend = filenameTs + 1

String downloadFolderPath = "C:\\test\\"
String filename = filenameTs.toString() + "_" + filenameAppend.toString() + ".txt"
File downloadedFile = new File(downloadFolderPath + filename)

if(!downloadedFile.isFile()) {
	KeywordUtil.markFailed("File does not exist.")
}

// here you can verify your file 

downloadedFile.delete()
2 Likes