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
Start the server
Use the *custom target in your Selenium client to start Firefox with the specific profile
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';
}
}
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
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.
ReplyDeleteI've created a profile but didnt know where to add the proxy.pac file
In Firefox Preferences->Advanced->Network->Connection Settings add the location of the .pac file to the Automatic Proxy Configuration URL field.
ReplyDeleteHTH
How do you do this in linux version?
ReplyDeletePretty much the same way - only the paths will be different (obviously! :-) ).
ReplyDeleteIn 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?
ReplyDeleteHi Chris,
ReplyDeleteI 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?
Sorry for the typo..i meant browser start command
ReplyDeletehello,
ReplyDeleteI 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.
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 ?
ReplyDeleteDoes this method still work? It doesnt work for me.
ReplyDeleteI have created a new firefox profile for selenium. Now, I am not able to go through the next step mentioned below:
ReplyDeleteAdd 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.
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.
ReplyDelete