I did say I'd let you know how it went...
I now have a script unit that can do all the required work to do this. Too much code to put it here, but basically, I have two project variables. DownloadsFolder and WorkingFolder.
I change my browser to always download to the Project Variable folder (c:\TC\Downloads)
There is a method that can clear folder contents, some copy/move functions and GetFile methods.
Before I download, I delete the contents of both folders. I can then use aqFileSystem.FindFiles and return the first one I find - there is handling if I don't find anything in the form of returning null. The calling function needs to check for nulls. This function can take a search pattern, so I don't need to know the exact filename. This caters for those downloads that have their names changing because they were downloaded at a later time. Now, the piece that I had to put in to cater to the fact that there is no connect between clicking the save button (using UIAObjects) and the file download completing. I have a function that waits for the file to exist. Its more reliable and faster than a set delay. :smileytongue::
function WaitFileExistsSearch(folderPath, searchPattern, timeout)
{
if(StringIsNullOrEmpty(folderPath))
{
Log.Error("No folder path specified");
return false;
}
//DefaultValue is a script unit I wrote that has methods for converting null or undefined values to a default value. If it's not null, the current value is returned
searchPattern = DefaultValue.GetString(searchPattern,"*.*");
timeout = DefaultValue.GetInt(timeout,Options.Run.Timeout);
var startTime = GetTickCount();
var fileExists = false;
LogMessageVerbose("Waiting for file to exists","FilePath : " + folderPath + "\nSearch Pattern : " + searchPattern);
var waitTime = GetTickCount() - startTime;
while(waitTime < timeout && fileExists==false)
{
if(GetFile(folderPath,searchPattern,true)!=null)
{
fileExists=true;
}
else
{
aqUtils.Delay(100,"Checking File Existence (" + folderPath + ")");
}
waitTime = GetTickCount() - startTime;
}
if(!fileExists)
{
Log.Error("File did not exists within the specified time period","FilePath : " + folderPath + "\nSearch Pattern : " + searchPattern);
}
else
{
LogMessageVerbose("File Exists", "Wait Time : " + waitTime + "ms");
}
return fileExists
}
Once I have the file in the downloads folder, I can move the file to the working folder :
aqFileSystem.MoveFile(DownloadFolder,WorkingFolder,!overwriteOnCollision);
Now I can reliably use my datadriver, since I control where my files are and it doesn't matter that the file name changes each time, because I can rename it to what I want before DataDrivers start using it - or I can pass the file path to the DataDriver