So I’m trying to write a suite of tests using Selenium WebDriver in Ruby for our web application, but I can’t even get into the application because of SSL certificate issues in Firefox. Our application is deployed on a local server, and uses a self-signed SSL Certificate for testing/development. When you’re simply using the browser manually, you can tell Firefox to set a security exception, and store it permanently, which works fine. This isn’t really a possibility using Selenium. First off, the tests fail before I would be able to set the permanent exception. Secondly, the moment I set the exception, Selenium forgets it and displays the screen again.
I’ve already tried creating a custom profile with firefox -p and adding the exception in that profile and loading it up via Selenium, but Selenium doesn’t seem to respect that exception. I also tried setting various profile parameters to get it to ignore or accept the certificate, but Selenium appears to ignore those profile parameters as well. Finally, I made Selenium add an extension that skips the invalid certificate screen, but it still doesn’t work. Here’s my code:
require 'rubygems'
require 'selenium-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.from_name "Selenium"
profile.add_extension("./skip_cert_error-0.3.2-fx.xpi")
profile["browser.xul.error_pages"] = "false"
profile["browser.ssl_override_behavior"] = "1"
driver = Selenium::WebDriver.for(:firefox, :profile => profile)
I figured it out. The trick was to download the certificate to the site, and save it somewhere, then go back into Firefox settings (with the Selenium Profile loaded), and manually upload the certificate, then “Edit Trust” to trust the certificate.