Configuring HTTPS Certificates in Playwright

Mudit Maheshwari
2 min readJul 25, 2023

--

Most of us talk about following best practices while writing any code . We say that it is good to develop code that is written following all the best practices . However , most of us are actually facing challenges in configuring the client side certificates in the test automation framework . Most of us tend to use the ignoreHTTPSErrors: true setting to make things work. However that is not the right and correct way of implementing a best practice

Problem: When trying to access https sites that require custom client certificate , if we do not use the ignoreHTTPSErrors: true flag in our code and just copying the certificates in /usr/local/share/ca-certificates/ ,we see the below error

In this article , I would share the way to use client certificate in playwright framework in gitlab ci where in we are going to use the docker image : mcr.microsoft.com/playwright:v1.35.0-jammy

Playwright which is built on top of puppeteer framework internally uses NSSDB to access the certificates.

In the gitlab-ci.yml, mention the following :

image: mcr.microsoft.com/playwright:v1.35.0-jammy
stages:
test #test suite automation run stage
test:
stage: test
tags: [shared]
before_script:
- apt-get update
- apt-get install build-essential -y
- apt-get install libnss3-tools # setting up certutil
- echo $HOME
- mkdir -p $HOME/.pki/nssdb
- certutil -d $HOME/.pki/nssdb -N --empty-password
- curl -k <url to download the pem file from>- create-dirs -o /usr/local/share/ca-certificates/CertificateName.pem
- certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n CertificateNickName -i '<path of the pem file>';
- update-ca-certificates --fresh
script:
- yarn install
- yarn playwright install
- npx playwright install msedge
- source set-env.sh
- yarn playwright test - workers 6
artifacts:
paths: #assuming deafult playwright artifacts paths
-./playwright-report/
when: always

The before_script section contains the configurations that must be done in order to be able to use client certificates. Certutil is a command-line tool in used to manage certificates and cryptographic services. It handles various operations, including installing, backing up, and verifying certificates, and more.

--

--