Selenium Handling / Testing Downloads with a custom profile
January 14, 2011
Posted by on
Selenium and downloads don’t play nicely as the Firefox (et al) download dialogs are out of reach of Selenium. The GWT application I’m working on allows the user to click on an icon and have an Excel file download initiated.
Searching for ways to test downloading files with Selenium came up with methods focused on running some kind of download dialog GUI interaction tool like AutoIT (anyone tried sikuli?).
While this is a practical solution it feels fragile to me.
To avoid this I created a custom Firefox profile to use as a template. This custom profile contains a customised download save path that I use to check files are downloaded, and a mimetype setting to that Excel files are automatically saved.
To do this:
- Copy the customProfileDirCUSTFF from the Selenium 1.0.1 sources
- Add a custom prefs.js file with a download path set (at least)
- Add a mineTypes.rdf and set excel files to auto save (alwaysAsk=false)
- Start the selenium server with a template profile parameter
The easiest way to create these files is by changing the settings in Firefox and then looking at the prefs.js file and mimeTypes.rdf file in your profile directory.
The line from the prefs.js is:
And the section from the mimeTypes:
To start your Selenium server with the template profile use:
java -jar selenium-server.jar -firefoxProfileTemplate
or in Java:
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
server = new SeleniumServer(rcc);