I use the below custom keyword when validating whether a file is downloaded and it works totally fine when running locally
public class DownloadManager {
@Keyword
def isFileDownloaded(String filePath,String fileName) {
File dir = new File(filePath);
File[] dirContents = dir.listFiles();
String lastAttempt = '';
if (dirContents.length > 0) {
for (int i = 0; i < dirContents.length; i++) {
if (dirContents[i].getName().equals(fileName)) {
// File has been found, it can now be deleted:
dirContents[i].delete();
KeywordUtil.markPassed(fileName + ' exist in ' + filePath + ' and was deleted')
return true;
}
lastAttempt = dirContents[i].getName().equals(fileName);
}
if (lastAttempt != fileName) {
KeywordUtil.markFailed(fileName + ' does not exist in ' + filePath)
return false;
}
}
return false;
}
But when I execute this on the pipeline (bitbucket) it is failing mainly because Im not sure how to verify when it is running and downloading through a docker. Is there a way we could set the download location within the project itself to validate whether the file is downloaded? Or is there other workaround?
Thanks in advance!