I found a solution that requires no browser profile with a client certificate preconfigured but rather test must provide the certificate. The downside is that it is based on PhantomJS Web browser implementation, not on Firefox or Chrome.
You just need to install version 2.1.1 version or later. A client certificate can be provided with the following command-line parameters.
--ssl-client-certificate-file
: an absolute path of the client certificate file eventually containing a secret key.
--ssl-client-key-file
: an absolute path of a file containing just a secret key. Only needed in case of separate locations of certificate and key.
--ssl-client-key-passphrase
: a passphrase for the secret key.
Preparing client certificates
I followed the instructions here to prepare certificate in a proper format:
Extract cert for --ssl-client-certificate-file
parameter
openssl pkcs12 -nokeys -clcerts -in cert.p12 -out src/test/resources/keys/cert.cer
Extract key for --ssl-client-key-file
parameter
openssl pkcs12 -nocerts -in cert -out src/test/resources/keys/cert.key
Marrying with Selenium automated tests
I was able to use it with PhantomJSWebDriver (v1.2.1). which wraps PhantomJS:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("takesScreenshot", true);
ImmutableMap<String, String> commandLineArguments = ImmutableMap.<String, String>builder()
.put("web-security", "false")
.put("ssl-protocol", "any")
.put("ignore-ssl-errors", "true")
.put("webdriver-loglevel", "DEBUG");
.put("ssl-client-certificate-file", clientCertificateAbsolutePath)
.put("ssl-client-key-file", clientSecretKeyAbsolutePath)
.put("ssl-client-key-passphrase", clientSecretKeyPasshphrase)
.build();
String[] params = commandLineArguments.entrySet().stream()
.map(e -> String.format("--%s=%s", e.getKey(), e.getValue()))
.collect(Collectors.toList())
.toArray(new String[0]);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, params);
WebDriver driver = new PhantomJSDriver(capabilities);