How to configure SSL certs for automation test with Cypress.io

Bothi Palani
1 min readOct 4, 2023

As you know there are many ways to authenticate to APIs, One of the ways to authenticate to the API request is SSL certificates.

Let us learn about how to configure cypress automation tests to use SSL certs for making request to the APIs.

SSL certificates are stored in the server and you will be given *.crt and *.key files for authentication from client side.

First, we need to create a folder certs at the top level of the project and place the files inside.

certificates have to be configured in the cypress.config.js file so when you run the command to open / run cypress , it would verify the certs against the url, if the certs are invalid it fails to load.

How to configure the SSL certificates ?

module.exports = defineConfig({
clientCertificates: [
{
url: 'https://a.host.com',
certs: [
{
cert: 'certs/cert.pem',
key: 'certs/private.key',
},
],
url: 'https://b.host.com',
certs: [
{
cert: 'certs/cert.pem',
key: 'certs/private.key',
},
],
},
e2e: {
setupNodeEvents(on, cypressConf) {

on('task', {
// custom tasks goes here.
},
specPattern: 'cypress/e2e/**/features/*.{feature,features}',
excludeSpecPattern: '**/integration/modules/*.js',
experimentalWebKitSupport: true,
experimentalRunAllSpecs: true,
},
});

--

--