Testing the Downloading/Uploading of files with Selenium IDE/WebDriver/Other?

626 views
Skip to first unread message

ckoeber

unread,
Oct 11, 2015, 11:40:54 PM10/11/15
to Selenium Users

In a series of applications my team is building we would like to test our import and export functionality which requires the respective upload and download to be automated.


The functionality is simple but tied to the UI; the end-user needs to be able to click on a button on the web UI and then the resultant export file is downloaded. With uploads, the idea is to have a local file relevant to the application and then use the web UI to upload said file and then test the import functionality.


Ideally I am looking for the ability to do this via Selenium IDE but as I understand it that is not possible.


Can this be done via Selenium WebDriver (via C#)?


If not, what is the best strategy to test this functionality? I'd like to test this as the end user and not simply pointing to some back-end URL to perform these tests.


Thank you for your time.

Quang Chanh Phan

unread,
Oct 12, 2015, 1:10:17 AM10/12/15
to Selenium Users
Dear ckoeber,
Is the flow of function is: upload(import) --> parse data (your function on Web)--> download (export) ?
I think your problem can be solved by using SE Webdriver + robot.awt.
Rgs,
ChanhPQ

Vào 10:40:54 UTC+7 Thứ Hai, ngày 12 tháng 10 năm 2015, ckoeber đã viết:

Mark Collin

unread,
Oct 12, 2015, 3:49:19 AM10/12/15
to Selenium Users
use .sendKeys() on the input element to upload files, you will need to provide an absolute file path.  It must be an <input type="file"> for uploads to work.

For download have a read of this:

Quang Chanh Phan

unread,
Oct 12, 2015, 4:57:22 AM10/12/15
to Selenium Users
Dear Mark Collin,
If architect design of Download/Upload haven't a text box, i think we must use robot.awt or AutoIT.
Do you have an other better solution? I recognize when use robot and run automation, if anyone types on keyboard (current with robot perform), our automated program will be affected.
Tks and regards,
ChanhPQ

Vào 14:49:19 UTC+7 Thứ Hai, ngày 12 tháng 10 năm 2015, Mark Collin đã viết:

Mark Collin

unread,
Oct 12, 2015, 5:43:06 AM10/12/15
to Selenium Users
There is usually an <input type="text"> hidden away in the background.  In mot cases making it visible so that Selenium can interact with it is enough.  

If there isn't an <input type="text"> hidden in the background you are probably using a JavaScript library to upload a file.  In this case the developers need to provide a test hook that will allow you to supply the absolute file path to the library and trigger the upload process.  

I've not yet come across an implementation that requires the use of AutoIT or a Java robot class.

Quang Chanh Phan

unread,
Oct 12, 2015, 5:57:09 AM10/12/15
to Selenium Users
Thanks Mark Collin.
Regards.

Vào 16:43:06 UTC+7 Thứ Hai, ngày 12 tháng 10 năm 2015, Mark Collin đã viết:

Dmitri T

unread,
Oct 13, 2015, 3:07:18 PM10/13/15
to Selenium Users
File Download

If you don't want to deal with modal dialogs which cannot be handled by Selenium, there is a workaround to amend browser's profile to automatically store certain file types into pre-defined folder. 

Code for FirefoxDriver

FirefoxProfile profile = new FirefoxProfile();

profile
.SetPreference("browser.download.folderList",2);
profile
.SetPreference("browser.download.manager.showWhenStarting",false);
profile
.SetPreference("browser.download.dir", @"c:\path\to\downloads\folder");  
profile
.SetPreference("browser.helperApps.neverAsk.saveToDisk","MIME/TYPE");    
FirefoxDriver driver = new FirefoxDriver(profile);

driver
.Get("http://path/of/your.file");

File Upload

Simulating file upload is as simple as passing full path to the file via IWebElement.SendKeys() method

IWebElement element = FindElement(By.Locator.of.your.file.type.input);
element
.SendKeys(@"c:\full\path\to\file\for.upload.txt");



Other way of automating file upload/download scenarios is using Apache JMeter which doesn't drive a browser, but sends appropriate HTTP Requests. JMeter is designed for load testing so you'll be able to test your server performance in regards to file transfer operations. See Performance testing: Upload and Download Scenarios with Apache JMeter guide for detailed instructions.

Reply all
Reply to author
Forward
0 new messages