Testing File Uploads with Selenium RC and Firefox(Or: Reducing Javascript Security in Firefox for fun and profit.)

People seem to have some problems when it comes to testing file uploads with Selenium RC. I’m not the first to provide a solution but making this work with Selenium RC might take a few more steps.

With Selenium RC you get a fresh browser each time you start a test run. So you’ll need to add this to your default profile in a You can upload files with Firefox if you build a custom profile with relaxed Javascript securities. You wouldn’t want to run this relaxed security version against any code that you don’t trust obviously, so be careful.

Step 1. Create a new Firefox profile. Step 2. Edit prefs.js to include:

user_pref("signed.applets.codebase_principal_support", true);

Step 3. Modify your AUT (this is why this is bad way to test file uploads via Selenium) to request enhanced permissions via:

netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead"); 
// This gives Javascript the ability to open file:// URI's.

Step 4. Visit your AUT using the profile you’ve just created, you’ll hopefully be greeted with a warning asking you if Javascript should be allowed UniversalFileRead permissions. Clicking yes will add entries to your prefs.js file that look like the following:

user_pref("capability.principal.codebase.p0.granted", "UniversalFileRead");
user_pref("capability.principal.codebase.p0.id", "http://your_aut_domain.com");
user_pref("capability.principal.codebase.p0.subjectName", "");

You can then edit your SeleniumRC instance to launch FireFox using this specific profile.

You can, and probably should, go farther with this by granting per file permissions.

More info:

5 Responses to “Testing File Uploads with Selenium RC and Firefox(Or: Reducing Javascript Security in Firefox for fun and profit.)”

  1. Also, one could use the *chrome launcher instead of the *firefox launcher. This worked for me to solve my upload issues.

  2. Hi

    though this is old post still i have a an issue i did every thing as mentioned in the above post but still i am facing the same problem still, kindly help me out.

    Regards Umar

  3. Hello,

    I’m using Selenium RC and i don’t have the file selenium-api.js in the selenium-server directory.

    Is this normal ?

    Thanks!

  4. Also we need to modify the firefox settings

    In FireFox enter “about:config” in the address bar, and set the value of “signed.applets.codebase_principal_support” to “true”. This allows non-signed scripts to request higher privileges.

  5. I have interesting automation scenario where I need to upload a html file, the way I wanted it to be uploaded in application is I need to open this file in browser, enter password in text box provided, and click submit.

    Challenge is how will I open a file using Selenium RC commands ?

Leave a Reply