martedì 14 agosto 2012

Selenium RC: overcome HTTPS not trusted certificate issue in testing firefox

When you get "This connection is untrusted" here is what you can do:

Create a firefox profile and make the Selenium RC to use it



Instead of
// Starting Selenium Server
try 
{
      sesrv = new SeleniumServer();
      sesrv.start();
} catch (Exception e) 
{
      e.printStackTrace();
}

we start the Selenium Server by imposing a firefox custom profile (solution suggested here remote configuration )

// Starting Selenium Server
try 
{
      RemoteControlConfiguration configuration = new RemoteControlConfiguration();
      File newFirefoxProfileTemplate = new File("C:/Users/andrea.ferraresi/AppData/Roaming/Mozilla/Firefox/Profiles/7phs191j.selenium");
      //To get the firefox profile and force Selenium to dump it temporarily into the file system and then use that path to set the firefox profile template via

      configuration.setFirefoxProfileTemplate(newFirefoxProfileTemplate);

      sesrv = new SeleniumServer(configuration);
      sesrv.start();
} catch (Exception e) 
{
      e.printStackTrace();
}

We create the custom profile by using firefox.exe -P
as explained here Creating_a_new_Firefox_profile_on_Windows

and then we have to
- browse with the custom profile just created to the https page where "This connection is untrusted" appears
- accept the certificate so the next time this profile will be used then the connection would be trusted
- by creating the custom profile, a new folder is created in the default location (for example
C:/Users/andrea.ferraresi/AppData/Roaming/Mozilla/Firefox/Profiles/) where the profiles are store. It is necessary to specify
new File("<folder where cert8.db and extensions.ini files are> ");

Be careful to specify the folder name: I've used 7phs191j.selenium in my case because that's the name of the folder created when I  created the custom profile by running firefox.exe -P :
I specified selenium as a profile name, while 7phs191j was added automatically.

This blog is sponsored by Italian Aurora e da Veni Vidi Vici Bici! da 0 a 139 anni. Puoi guardare il video della presentazione di Veni Vidi Vici Bici! da 0 a 139 anni