Best Practice to Download CSV File

Ask general questions here.
natesun
Posts: 14
Joined: Wed Oct 17, 2018 4:05 pm

Best Practice to Download CSV File

Post by natesun » Tue Aug 27, 2019 5:50 pm

Hi,

I have several test cases that requires to download a csv file first, and then open that csv file to look for some values and compare with webpage. I know that there is a DownloadFile() under WebLibrary of Ranorex.AutomationHelpers, but this does not really apply to our application and uri is unknown so far. What has happened is click that link on the webpage and then opens from download folder. My question is how to validate download is complete? I have been using try catch within a while loop, with try to find if the csv file contains ".partial" and catch part wait for 2 seconds. Because sometimes it happens that download has not finished before the Directory tries to open csv file. Is there a better way to validate download completed before Directory.GetFiles() reads and returns the files contains ".partial" and was still downloading?

Thanks,
Nate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Best Practice to Download CSV File

Post by Support Team » Wed Sep 04, 2019 8:53 pm

Hello Natesun,

The DownloadLoadFile() Automation Helper should be perfect in this scenario as you mention you are clicking on a web link. You can get the uri by right-clicking on the link and copying the address, if this link is static you can copy and paste that link into the uri field. If the link is dynamic you will have to use a get value and assign it to a variable to pass to the method. Alternatively, if you are having trouble getting the uri you can track the link using spy and grab the uri that way which should be an href.

I hope this helps!
Sean
.
Image

natesun
Posts: 14
Joined: Wed Oct 17, 2018 4:05 pm

Re: Best Practice to Download CSV File

Post by natesun » Thu Sep 05, 2019 7:35 pm

Thanks for your reply. So I checked web element and also used spy to capture Href, this is what I see:

javascript:gotoSave('J4l2%2fshDzGrqjCFL23ityxHPOBumRFm5FJN39qWd5BUQ4kIRngI%2bPx9IpC%2bxBgz74sPRGrrpRmRLX7iIl4OVng%3d%3d','import');

Not sure how to get the uri from this href, and seems like have to find javascript code.

Thanks,
Nate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Best Practice to Download CSV File

Post by Support Team » Fri Sep 06, 2019 3:01 pm

Hello natesun,

Unfortunately, with the involvement of Java it does complicate things, However, you can accomplish this task using the Ranorex Validation NotExist action. This will allow your test to validate a specific element does not exist before moving on with your test. If you go this route I recommend setting the timeout fairly high on this action as to give it enough time to validate, increasing the timeout will not increase the length of your test as the test will continue once the .partial element does not exist anymore. Please see a small sample below.
2019-09-06 09_56_50-MyTest44 - Ranorex Studio - (32bit) (Administrator).png
2019-09-06 09_56_50-MyTest44 - Ranorex Studio - (32bit) (Administrator).png (13.27 KiB) Viewed 49 times
Regards,
Sean
.
Image