To build upon Manvi's answer, I could not get it working using a PEM certificate nor a PFX certificate, so I had to manually extract the certificate and key from my PFX file using openssl
Extract the certificate
openssl pkcs12 -clcerts -nokeys -in "SourceFile.PFX" -out certificate.crt -password pass:"MyPassword" -passin pass:"MyPassword"
Extract the key
openssl pkcs12 -nocerts -in "SourceFile.PFX" -out private.key -password pass:"MyPassword" -passin pass:"MyPassword" -passout pass:TemporaryPassword
Code
File path=new File(phantomJSBinaryFile);
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
ChromeOptions cap =new ChromeOptions();
ImmutableMap<String, String> commandLineArguments = ImmutableMap.<String,
String>builder()
.put("web-security", "false")
.put("ssl-protocol", "any")
.put("ignore-ssl-errors", "true")
.put("webdriver-loglevel", "INFO")
.put("ssl-client-certificate-file", certificatePath) //certificate.cer
.put("ssl-client-key-file", keyPath) //private.key
.put("ssl-client-key-passphrase", pwd)
.build();
String[] params = commandLineArguments.entrySet().stream()
.map(e -> String.format("--%s=%s", e.getKey(), e.getValue()))
.collect(Collectors.toList())
.toArray(new String[0]);
cap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, params);
//cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new PhantomJSDriver(cap);
driver.get(url);
System.out.println(driver.getTitle());