Using Self-Signed Certificates with Sauce Labs
Using self-signed certificates can help you mimic real world interactions on your dev site but can also create issues when trying to test on a Sauce VM. You can use different techniques on different browsers to get around these problems.
Internet Explorer 8,9,10,11
There is currently no way to allow self-signed certificates to be trusted or ignored in Internet Explorer. A way around this is to trust the certificate by clicking on the warning after it appears.
Add this after the command to load the site:
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
NOTE: This may stop working if Internet Explorers id ever changes.
Firefox 47 or lower
Firefox versions 47 and lower use Selenium's FirefoxDriver, which will automatically accept a self-signed certificate without any additional configuration.
Firefox 48 - 51
Starting with Firefox 48, Selenium uses Mozilla's geckodriver which leverages Mozilla's own Marionette Driver. This brought more changes and different capabilities.
As of now the only way to have a self-signed certificate on these versions of Firefox is to create a new Firefox Profile where you manually accept the certificate and upload the profile to Sauce Labs.
It is up to you to create the profile. Using the profile can be done with commands like these:
ProfilesIni profiles = new ProfilesIni(); #Initializes Profiles stored in local instance of Firefox FirefoxProfile myProf = profiles.getProfile("Profile-Dev"); caps.setCapability(FirefoxDriver.PROFILE, myProf);
NOTE: If using Sauce Connect you will need to add the CyberVillains certificate to the Firefox Profile as described above due to re-encryption made in Sauce Connect. Go here for the certificate: https://s3.amazonaws.com/sauce-public-files/cybervillainsCA.pem
Firefox 52+
Using self-signed certificates was made easier on version 52 of Firefox. To have Firefox ignore certificate warnings, add the following DesiredCapability:
caps.setCapability("acceptSslCerts",true);
Chrome
Sauce Labs will take care of any certificates launched on Chrome.
Safari
Safari has no way of accepting automatically self-signed certificates; they must be accepted manually. To overcome this problem, you can leverage the fact that Sauce Connect automatically re-encrypts your certificate with the CyberVillains certificate. After that is done, your site should be accessible.
NOTE: Assuming that when you launch your Sauce Connect instance, all your tests suites go through SC (not just Safari tests), this can cause unwanted side effects on other tests.
For more on this go to https://docs.saucelabs.com/secure-connections/sauce-connect/troubleshooting/