I am working on a tests scenario that downloads a file from a website and adds it to folder.
For the download part I am using the code described here (for Firefox).
The main problem was encountered when in my tests I am waiting for the file to be downloaded:

3 Answers
3

You simply check the directory contents before you download the file, then wait until there's a new file added to the directory (by comparing the current content with the previous content). This is how you get the new file name:

You can't use "glob" with File.exists? like File.exists?("*.csv"). It checks whether the file named *.csv exists, not any file with name ends with .csv. You should use exact file name to check if a file exists.

The problem is that the name of the file contains an unique number, that is generated when pressing the Download link. There is now way I can get this number :|, so I used this method, to see if the files is present in the folder.
–
Cristian MJun 15 '12 at 9:27

1

What I mean is, if the file isn't there, then an infinite sleep loop won't help much.
–
pguardiarioJun 15 '12 at 9:42

The file is there, is downloaded... but, is not visible by ruby during the test run. Even if I run the code to display all the files from the directory (after the download is done), it returns nothing-> path = Dir.getwd + "/downloads/" Dir.glob("#{path}*.csv").each { |f| puts f }
–
Cristian MJun 15 '12 at 11:29