Thursday, December 8, 2011

Selenium and SSL

If you have to test https sites using Selenium on a variety of browsers, you are asking for a world of pain!  Practically every version of every browser on every platform requires either a different jar file or different arguments for both the selenium server and the remote client.

First of all, the all-important version disclaimer!
   selenium-server-standalone-2.15.0.jar
   selenium-grid-1.0.8
   Firefox 3.6  on Windows 7 and Ubuntu 11.04
   Firefox 8 on Windows7
   Chrome 15.0.874.121 on Windows 7
   Internet Explorer 9 on Windows 7

For Local Selenium Server
-------------------------------------
 java -jar selenium-server-standalone-2.15.0.jar


For Selenium RC Clients (your test app)
-----------------------------------------------------
  call selenium.start with the commandLineFlag -disable-web-security

  Python example:
    from selenium import selenium
    sel = selenium(test_host, int(test_port), self.browser, url)
    sel.start('commandLineFlags=-disable-web-security')

For Selenium Servers and Selenium Grid Remote Clients
---------------------------------------------------------------------------

For Firefox, I needed to use a profile and pass it into the startup script.
  1. start firefox from the command-line with "firefox -profileManager" and create a new profile
  2. Manually go into the site using Firefox, accept the various certificate challenges, and then quit the browser
  2. Start the selenium client using your new firefox profile. For example, as a Selenium Grid remote client:
           ant -Dport=5777 -Denvironment="*chrome" -Dhost=MY_IP
 -DhubURL=http://SELENIUM_GRID_SERVER_IP:4444 -DseleniumArgs="-firefoxProfileTemplate C:\Users\ME\FIREFOX_PROFILE_DIRECTORY_COPY\firefox_profile"  launch-remote-control

you may need to add some lines to the prefs.js file in the firefox profile. for example, if you see 403's and/or 404's being returned because of the browser looking for /favico.ico, you should add these two lines
    user_pref("browser.chrome.favicons", false);
    user_pref("browser.chrome.site_icons", false);
NOTE that this USUALLY WORKS but, in my case, it simply STOPPED WORKING on Windows 7. The -firefoxProfileTemplate argument passed in to ant as seleniumArgs is not passed along by the remote control to the firefox startup command. Here the specified profile is simply ignored:
    [java] 09:16:47.113 INFO - Preparing Firefox profile...
     [java] 09:16:49.072 INFO - Launching Firefox...
     [java] 09:16:49.074 DEBUG - Execute:Java13CommandLauncher: Executing 'C:\Program Files
(x86)\Mozilla Firefox\firefox.exe' with arguments:
     [java] '-profile'
     [java] 'C:\Users\ME\AppData\Local\Temp\customProfileDirc829f057ff9e497ea065add1ca892726'


The solution was to replace the selenium-server-standalone jar file in selenium-grid-XX/vendor with a newer one from Selenium org (2.15) - However, this broke IE which needed selenium server standaloine 2.12.0 !!!)


For Internet Explorer
    Disable popup blockers - Select Tools/Popup Blocker/Turn off pop-up blocker
    Disable IE protected mode - Untick Tools/Internet Options/Security/Enable protected mode - do this for all four zones

For Google Chrome
    Open Chrome Options
    go to 'Under the Hood'
    click on the 'Manage Certificates' button at HTTPS/SSL
    IMPORT your https server's PFX certificate and save it under Trusted Root Certification Authorities (input the password when prompted)



No comments:

Post a Comment