Selenium and self-signed SSL Certificates in Firefox [java / linux]

AAAARRGGHHHHHH!!!!!!!!….. Finally, I’ve managed to solve my problem with self-signed certificates in FF and Selenium.

I think I spend three days trying various methods, following tutorials and ‘hacking’ through the selenium source code, etc.
Maybe it’d take someone much less time than me, but what’s done is done, and let’s get crackin’ 🙂

A. Follow Girlie’s tutorial to create customized Firefox profile with few changes:

  1. in step no. 7 – remember not to use spaces in forlder names
  2. skip steps no. 11 & 12
  3. [OPTIONAL STEP] Configure FF according to Girlie’s suggestions
  4. Once you’re done with creating custom profile, go to the HTTPS site which troubles you with an invalid security certificate. Use “Add exception” button to add security exception.
  5. Close FF

B. Go to your FF custom profile folder (see A.1)

  1. If you skipped step A.3, then remove all files and folders except: cert8.db, cert_override.txt, key3.db
  2. If you followed Girlie’s suggestions in step A.3, then you can remove all files and folders except:
    • cert8.db, cert_override.txt, content-prefs.sqlite, key3.db, localstore.rdf, permissions.sqlite, prefs.js, secmod.db, XPC.mfasl, xpti.dat, XUL.mfasl
    • More information about contents of FF profile folder at: http://kb.mozillazine.org/Profile_folder_-_Firefox

C. Open your selenium project and add some new code:

private static Selenium selenium = new DefaultSelenium(String serverHost, int serverPort, String browserStartCommand, String browserURL);
private static SeleniumServer seleniumServer;
seleniumServer = new SeleniumServer();


/* 
* And here are the DRAGONS!!
* Short description:
* start with preparing new RemoteControlConfiguration and profile location
* then, change some default settings
* start selenium server
* and finally pass new configuration to Selenium 
*/

RemoteControlConfiguration rcc = seleniumServer.getConfiguration();
File profileLocation = new File("/path/to/your/custom/FF/profile");
rcc.setProfilesLocation(profileLocation);
rcc.setFirefoxProfileTemplate(profileLocation);
rcc.setReuseBrowserSessions(true);
seleniumServer.start();
selenium.start(rcc);

Hope this this work also for you.
J