Friday, February 5, 2010

Dealing with SSL certificates while running selenium tests with Firefox-3.x

Selenium works without any problem if application does not use HTTPS; but as soon as application goes to the HTTPS URI on the same host everything goes unexpected. As Selenium effectively runs Firefox with a new profile every time, you potentially lose every certificate exceptions you might accept.

One technique is to create a custom profile; run Firefox using that profile; browse to the HTTPS URL and accept the exception into that profile; then close the profile. So accepted expectation would not be asked to accept again if we use same profile.

Following are steps to setup profile and some more hack to make accepted certificate available:

1. Start Firefox with the profile manager: firefox -ProfileManager
2. Create a new profile. You'll be prompted to choose a directory for the profile.
3. Select the profile and run Firefox using it.
4. Browse to the HTTPS URL (with self-signed certificate) you're going to be testing against.
5. Accept the self-signed certificate when prompted. This creates an exception for it in the profile and Close the browser.
6. Go to the Firefox profile directory and delete everything in the directory except for the cert_override.txt and cert8.db files.
7. When you run your Selenium server, pass a -firefoxProfileTemplate /path/to/profile/dir argument to it. This tells Selenium to use your partial profile with certificate exceptions.


In this way selenium would not ask you to accept any certificate once you accept against this profile. Do not forget to use same profile while run selenium. Have a look at beautiful code calling your profile:


The Ant task above, with this option, looks like this:


Outside of Ant, the command might look something like:

java -jar path_to/selenium-server.jar -firefoxProfileTemplate /path/to/profile \
-htmlSuite '*chrome firefox-bin' http://host.com testSuite.html seleniumResults.html



Cheers!!!

1 comment:

  1. Hi vaibhav i am using TESTNG and trying to invoke server from the code itself so how do i pass the path in java code

    ReplyDelete