Wednesday, April 27, 2011

Selenium and self-signed SSL Certificates(https)

For quite some time , i have postponed this task of running my product in https mode and add this part in the selenium framework we have designed.

The following is my learning in this part . Though half baked (yet of find an answer for this in IE) , it might be useful for someone .

Basic of selenium RC , ie starting a new firefox profile everytime and so we will be loosing the https added certificates which we have stored by default . The best workaround is to create a new custom firefox profile , add the exception to it . And use this firefox profile to start the selenium session.

Following blog posts would be well suffice to do get it work on this workaround

http://jktechtrip.wordpress.com/2011/04/14/selenium-and-self-signed-ssl-certificates-in-firefox-java-linux/

  1. Close down any running Firefox instances.
  2. Start Firefox (the one you're going to run your tests with) with the profile manager: firefox -ProfileManager
  3. Create a new profile. You'll be prompted to choose a directory for the profile. Put it somewhere inside the project where you're writing the tests.
  4. Select the profile and run Firefox using it.
  5. Browse to the HTTPS URL (with self-signed certificate) you're going to be testing against.
  6. Accept the self-signed certificate when prompted. This creates an exception for it in the profile.
  7. Close the browser and go to the Firefox profile directory.
  8. Copy the files cert_override.txt and cert8.db files in the new firefox custom profile directory
  9. When you run your Selenium server (like in my Ant example above), pass a -firefoxProfileTemplate /path/to/profile/dir argument to it. This tells Selenium to use your partial profile (with certificate exceptions) as a basis for minting its new profile. So you get the certificate exceptions, but without any of the other clutter you would get if you used a whole profile. Ie java -jar selenium-server.jar -firefoxProfileTemplate “

You can check for the newly created firefox profile at

C:\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\hpgmv92o.testprofile (This will change based on the location u create ur profile)

Info : cert_override.txt is a text file generated in the user profile to store certificate exceptions specified by the user. This file is used by Firefox, Thunderbird, and other XUL-based applications.

Why is that trustAllSSLCertificates flag can't be used . Yup the following blogpost tells you in detail how to use that

http://mogotest.com/blog/2010/04/13/how-to-accept-self-signed-ssl-certificates-in-selenium

For a long time , i was searching for a answer to find a way how to start selenium in IE in https mode . But still not have found a way . Comment and say if you have an answer for this

No comments:

Post a Comment