Skip to main content
Experience faster, smarter testing with BrowserStack AI Agents. See what your workflow’s been missing. Explore now!
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Test using PFX certificates

You can upload and install .pfx (Personal Information Exchange) certificates on BrowserStack Automate to test websites and workflows that require client-certificate authentication.

To start testing with .pfx certificates, contact BrowserStack Support to have your certificates reviewed and validated.

Use cases

Testing with .pfx certificates is useful in scenarios such as:

  • Testing websites that require a valid client certificate for authentication.
  • Verifying workflows that depend on certificate-based access.
  • Conducting compatibility checks for advisory portals that require authentication.
  • Ensuring that certificate installation works across different operating systems and browsers.

Supported operating systems and browsers

The following operating systems and browsers support .pfx certificates:

Operating System Versions Browsers
Windows Windows 11 Chrome
macOS Sequoia, Tahoe, Golden Gate Chrome

Upload your file to BrowserStack

Run the following upload media cURL command to upload your file to BrowserStack servers:

Request
Copy icon Copy

Here is a sample cURL response. It returns the media_url parameter value.

Response
Copy icon Copy

Set the capability in test script

To use certificate based authentication, set the customCertificates capability. Here is an example to set this capability in your config file:

package org.example.threads;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;


public class BrowserStackClientCertTest {

    public static final String USERNAME = "YOUR_USERNAME";
    public static final String ACCESS_KEY = "YOUR_ACCESS_KEY";
    public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@hub-cloud.browserstack.com/wd/hub";

    public static void main(String[] args) throws MalformedURLException, InterruptedException, JsonProcessingException {
        MutableCapabilities capabilities = new MutableCapabilities();
        ObjectMapper mapper = new ObjectMapper();
        // ChromeOptions
        ChromeOptions options = new ChromeOptions();
        // SSL client certificate preference
        Map<String, Object> certPref = new HashMap<>();
        certPref.put("pattern", "https://client.badssl.com");
        certPref.put("filter", Map.of("SUBJECT", Map.of("CN", "BadSSL Client Certificate")));
        String certJsonString = mapper.writeValueAsString(certPref);
        options.setExperimentalOption("prefs", Map.of(
                "profile.managed_auto_select_certificate_for_urls", new String[]{certJsonString}
        ));
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        // BrowserStack options
        capabilities.setCapability("browserName", "Chrome");
        capabilities.setCapability("browserVersion", "latest");

        Map<String, Object> bstackOptions = new HashMap<>();
        bstackOptions.put("os", "OS X");
        bstackOptions.put("osVersion", "Sequoia");
        bstackOptions.put("userName", "");
        bstackOptions.put("accessKey", "");
        bstackOptions.put("uploadMedia", new String[]{"media://xyz"});

        bstackOptions.put("customCertificate", Map.of(
                "media://xyz", Map.of("password", "badssl.com")
        ));
        capabilities.setCapability("bstack:options", bstackOptions);
        WebDriver driver = new RemoteWebDriver(new URL("https://USERNAME:ACCESS_KEY@hub-cloud.browserstack.com/wd/hub"), capabilities);
        driver.get("https://client.badssl.com/");
        Thread.sleep(2000);
        System.out.println("Title: " + driver.getTitle());
        driver.quit();
    }
}

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle