Tuesday, May 13, 2008

Selenium and HTTPS

This is documented elsewhere, but here it is again:

The problem - you want to test a web site where you get a popup to accept an unrecognised certificate, eg when using a self-generated certifictate. Selenium cannot click on the resulting confirmation window, but worse still Selenium does not store your decision even though you have selected 'permanently accept' manually the first time.

The solution - basically Selenium is launching a clean copy of the browser each time. So you need to create a persistent profile to use each time.

As far as I know this is only possible with Firefox.

Create a new Firefox profile (firefox.exe -profileManager). In this case the name of the new profile is selenium-https-profile

Add the certificate to it Add a suitable .pac to redirect to the SeleniumServer

function FindProxyForURL(url, host) {
if(shExpMatch(url, '*/selenium-server/*')) {
return 'PROXY localhost:4444; DIRECT';
}
}


Start the server

java -jar selenium-server.jar -firefoxProfileTemplate "C:selenium-ffox-profile"


Use the *custom target in your Selenium client to start Firefox with the specific profile

*custom C:\Program Files\Mozilla Firefox\firefox.exe -P selenium-https-profile

12 comments:

Vivek said...

Can you explain how to add the .pac file. I am trying to run selenium tests against https site using *chrome but I am still getting the pop up asking to accept the certificate.

I've created a profile but didnt know where to add the proxy.pac file

Chris Pitts said...

In Firefox Preferences->Advanced->Network->Connection Settings add the location of the .pac file to the Automatic Proxy Configuration URL field.

HTH

Anonymous said...

How do you do this in linux version?

Chris said...

Pretty much the same way - only the paths will be different (obviously! :-) ).

andy-shev said...

In my case the applying profile as default template in the -firefoxProfileTemplate command line parameter for selenium server works perfectly. Only one problem which I still have is a popup window for HTTP auth. Any idea how to click OK automatically?

Murali said...

Hi Chris,

I didn't get this!
Use the *custom target in your Selenium client to start Firefox with the specific profile ..

Should we give this ["*custom C:\Program Files\Mozilla Firefox\firefox.exe -P selenium-https-profile"] as browser star command in DefaultSelenium constructor?

Murali said...

Sorry for the typo..i meant browser start command

Chetan-24 said...

hello,
I have done all configuration as mentioned. i am facing two issues here
1) while i am running the script the firefox choose user profile menu is open and always need to select profile.

2) after starting selected profile The certificate is not trusted because the issuer certificate is unknown.

(Error code: sec_error_unknown_issuer) error displayed please guide me how can i overcome this issue.

Anonymous said...

I am not only working with firefox, I have to test the application with IE6, any ideas how to skip this certificate or how accept it ?

Kewl said...

Does this method still work? It doesnt work for me.

Anonymous said...

I have created a new firefox profile for selenium. Now, I am not able to go through the next step mentioned below:

Add the certificate to it Add a suitable .pac to redirect to the SeleniumServer

function FindProxyForURL(url, host) {
if(shExpMatch(url, '*/selenium-server/*')) {
return 'PROXY localhost:4444; DIRECT';
}
}

do we need to add this method to our testcase?
From where do we get the .pac file?
I am using Firefox 3.5.5.

Chris said...

I'm afraid I have had to adopt a policy of not answering specific "can you do my do my homework for me" type queries. However I am available for hire, so if you have a specific problem you need solved then please do get in touch, and we can discuss costs. But here's a starter for 10 - you write the .pac.