Oops Null Pointer

Java programming related

Selenium Handling / Testing Downloads with a custom profile

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:

user_pref("browser.download.dir", "C:\\temp\\ff_selenium_downloads");

And the section from the mimeTypes:

  <RDF:Description RDF:about="urn:mimetype:handler:application/vnd.ms-excel"
                   NC:saveToDisk="true"
                   NC:alwaysAsk="false" />

To start your Selenium server with the template profile use:

-firefoxProfileTemplate

java -jar selenium-server.jar -firefoxProfileTemplate

or in Java:

    RemoteControlConfiguration rcc = new RemoteControlConfiguration();
    rcc.setPort(SeleniumUtils.SELENIUM_SERVER_PORT);
    rcc.setFirefoxProfileTemplate(customFFProfileDir);
    server = new SeleniumServer(rcc);
    server.start();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: