I have observed that many automation engineer gets stuck
while automating Upload/download File from/to
local disk ,related tests with selenium, I would like to take this
opportunity to throw some light on it
Autoit
is one of the option to download or upload the file but many automation
framework developer avoids the use of third party tools with their framework,
Even though it’s an open source, it could get licensed in future.
Apart
from AutoIt, there is couple of other solutions to achieve it.here I tried to
list it down along with the open issues for the provided solution.
Here
is what we already tried and the problems we faced along with the actual
solution :)
Solution 1 : Uploading
a file using Autoit & WebDriver
Solution 2: Download programmatically using href attribute of
button/link/image
Details in link: (http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/)
Problem: Works only for button/link/image having href pointing
to actual file location. IPP uses javascript as value for href. So cant be
used.
Solution 3: Use user32 (JNA)
Fine for tasks like checking window existence, setting focus on specific window
etc.
Problem: But can’t identify objects on window (buttons,
checkboxes etc. on window).
Solution 4: Use SendKeys on window under focus
Problem: Firefox popups doesn’t respond to keys send
programmatically.
Solution 5: Use Send keys using selenium
Problem: Selenium sends keys only on objects which
Selenium identifies. Firefox’s ‘File Download’ popup is not recognised by
Selenium.
Solution 6: Use AutoHotKey tool
Problem: Firefox’s ‘File Download’ popup doesn’t respond
to keys send by AutoHotKey.
Solution with which I moved ahead and found
very simple.
Simple Solution: Use firefox profile to handle file download
Firefox settings to manage File Download dialog in Selenium:
1. Disable “Show the Downloads window when downloading a
file”:
2. Add default download path to profile being used for
Selenium run.
3. Download each file type (which you will be downloading during
test runs e.g. .xls, csv, txt etc.) once and check the “Do this automatically
for files like this from now on” option.
Note:
1. Above options (1,2 and 3) once set, will automatically
download selected file types to folder specified in step 2.
2. Above options are stored in the current firefox
profile.
3. All these options can be changed using Applications
tab in Firefox’s options.
Even
internet explorer and chrome are having those options so that we can download
the file at one fix location so that you will not have to work on
download window.
Feel
free to revert back.