title: Add ssl certificate to selenium-webdriver
body: <p>I use selenium for end-to-end test with chromeDriver. The websites to test require an ssl certificate. When I manually open the browser, there is a popup that lets me select an installed certificate. Different tests access different URLs and also need different certificates. However, if I run the tests in headless mode, there is no popup. So I need a way to programatically set a certificate (eg. set a <code>.pem</code> file) to be used for the current test.</p>
  
  <p>How can I achieve this?
  I tried setting up a <a href="https://github.com/lightbody/browsermob-proxy" rel="noreferrer">browserMob</a> proxy which I then configured as a proxy in selenium - however, this does not seem to do anything... Are there better approaches? What am I doing wrong? Here's what I tried:</p>
  
  <pre class="lang-java prettyprint-override"><code>PemFileCertificateSource pemFileCertificateSource = new PemFileCertificateSource(
          new File("myCertificate.pem"),
          new File("myPrivateKey.pem"),
          "myPrivateKeyPassword");
  
  ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
          .rootCertificateSource(pemFileCertificateSource)
          .build();
  
  BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
  browserMobProxy.setTrustAllServers(true);
  browserMobProxy.setMitmManager(mitmManager);
  
  browserMobProxy.start(8080);
  
  
  ChromeOptions chromeOptions = new ChromeOptions();
  chromeOptions.setProxy(ClientUtil.createSeleniumProxy(browserMobProxy));
  
  WebDriver webDriver = new ChromeDriver(chromeOptions);
  
  // use the webdriver for tests, e.g. assertEquals("foo", webDriver.findElement(...))
  </code></pre>