cancel
Showing results for 
Search instead for 
Did you mean: 

determine file name of downloaded file

SOLVED
Community Leader

determine file name of downloaded file

Hi all,

 

I'm trying to confirm that the contents of my CSV exports are as expected.  Or conversely, export the data from my application to check the application data is correct by checking the CSV results.  This works better than Database checks for some situations, since the CSV eport can do all the object property lookups with multiple database calls etc.  I have all the required tools through DataDrivers/ADO to read through the csv/xls etc.  What I'm finding a challenge is finding resources that can help me find the path and filename of the last download.  I have tried solutions described in thread

 

https://community.smartbear.com/t5/TestComplete-Functional-Web/Downloading-and-looking-at-a-file/m-p...

 

and 

https://support.smartbear.com/viewarticle/8999/

 

Both these resources however assume you are trying to download an existing file to your machine.  I'm trying to get a CSV/XLS that gets generated and uniquely named when you click the "Export" button.  I'm sure it's been done before.  Are there any other resources I haven't found yet you know of ?

 

Something like https://support.smartbear.com/viewarticle/51660/

 

but I do testing in IE and I'm not clear exactly how I'm going to extract the file name from there...

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Hero

Re: determine file name of downloaded file

You should be able to use https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/sa... when you export / save and specify your path and file name.

 

Alternatively, you could use https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/methods.html and https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfilesystem/methods.html to determine the newest file in your download directory. 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Community Hero

Re: determine file name of downloaded file

My guess is that it exports/downloads to the default "Downloads" folder for the currently logged in user.  So, you can do something like %AppData% to get the pathing to start with.

 

As for the filename, It might not be a matter of filename, but more on the lines of just detecting the CSV/XLS file with the most recent date/time stamp.  Look into using aqFileSystem to determine that.  

I would also suggest, in order to make that easier, at the end of the test, delete all CSV/XLS files from that folder or at least move them to an archive place.  That way, when you do the export, the ONLY file in that downloads folder will be the one you want... and the specific filename itself won't matter.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
3 REPLIES 3
Community Hero

Re: determine file name of downloaded file

You should be able to use https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/sa... when you export / save and specify your path and file name.

 

Alternatively, you could use https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/methods.html and https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfilesystem/methods.html to determine the newest file in your download directory. 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Community Hero

Re: determine file name of downloaded file

My guess is that it exports/downloads to the default "Downloads" folder for the currently logged in user.  So, you can do something like %AppData% to get the pathing to start with.

 

As for the filename, It might not be a matter of filename, but more on the lines of just detecting the CSV/XLS file with the most recent date/time stamp.  Look into using aqFileSystem to determine that.  

I would also suggest, in order to make that easier, at the end of the test, delete all CSV/XLS files from that folder or at least move them to an archive place.  That way, when you do the export, the ONLY file in that downloads folder will be the one you want... and the specific filename itself won't matter.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Leader

Re: determine file name of downloaded file

Thanks, both

 


You should be able to use https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/sa... when you export / save and specify your path and file name.

Not going to be able to do that this time.  You never get a save as dialog for this particular application.

 

I reckon however that between aqFile and aqFileSystem I can cobble together a wrapper script that can find the file and return the path.  If I feel like a real mister fancypants, I'll make it so it can copy the file to a convenient path while I'm at it and delete it when I'm done reading the file.  I will probably control my environment by setting up my browser to always save downloads to a specific folder I specify e.g. "C:\TC\Downloads" and storing it in a project variable in case the environment changes in the future.  I'll probably add a script I can call each time before I click that export button that just deletes the download folder contents. That way the first (only) file will alsways be the one I'm looking for. 

 


... and the specific filename itself won't matter.

I'll be needing the filename if I'm going to use DataDriver/ADO, but if there's only the one file left as you suggested it will be easy to get from file info.  I'll let you know how it went...


-------------------------------------------------
Standard syntax disclaimers apply
Regards,