Skip to content

Instantly share code, notes, and snippets.

@checklyalex
checklyalex / visual.spec.ts
Last active September 4, 2025 15:20
Visual Regression Masking Example
const { expect, test } = require('@playwright/test')
test('wait for an element to become visible', async ({ page }) => {
await page.goto(process.env.ENVIRONMENT_URL || 'https://www.winzogames.us')
await page.waitForLoadState('networkidle');
// Use the "toHaveScreenshot" matcher to compare screenshots between check runs
// Don't forget to --update-snapshots on your first run!
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.2, //Define your thresholds here
@checklyalex
checklyalex / clientCertificates.spec.ts
Created August 5, 2025 15:56
Using a browser context, loading in base64 credentials for mTLS
import { expect, test } from '@playwright/test';
import fs from 'fs';
test('mTLS authentication test', async ({ browser }) => {
// Load client certificate from environment variable or file
let certBuffer;
if (process.env.CHECKLY_CERTIFICATE) {
certBuffer = Buffer.from(process.env.CHECKLY_CERTIFICATE, "base64");
} else {
const certPath = 'client.pem';
@checklyalex
checklyalex / detectConsoleErrors.spec.ts
Created July 2, 2025 10:57
Detect console errors with Playwright
import { test, expect } from '@playwright/test';
test.describe('Console error detection', () => {
test('should have no console errors on page load', async ({ page }) => {
const consoleErrors: string[] = [];
// Listen for console events and collect error messages
page.on('console', msg => {
if (msg.type() === 'error') {
consoleErrors.push(msg.text());
export const fetchLatestSMS = async (twilioClient, toNumber, timeout = 10000) => {
return new Promise((resolve, reject) => {
setTimeout(async () => {
try {
// Fetch the latest message to a specific number
const messages = await twilioClient.messages.list({
to: toNumber, // Filter messages sent to this number
limit: 1, // Fetch only the most recent message
order: 'desc' // Order by date sent in descending order
});
const { expect, test } = require('@playwright/test')
const twilio = require('twilio');
import { fetchLatestSMS } from './smsHelpers.ts';
const TWILIO_ACCOUNT_SID = ""
const TWILIO_AUTH_TOKEN = ""
test('Verify SMS code', async ({ page }) => {
const twilioClient = twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
const toNumber = "+44xxxxxxxxxx"
@checklyalex
checklyalex / setExtraHTTPHeaders.js
Created January 19, 2024 14:21
A Checkly browser check example utilising a separate context and extra HTTP headers - https://playwright.dev/docs/api/class-page#page-set-extra-http-headers
import { expect, test } from '@playwright/test'
const headers = {
'X-My-Header': 'value'
};
test('visit page and take screenshot with an extra http header for every request', async ({ browser }) => {
const context = await browser.newContext();
await context.setExtraHTTPHeaders(headers);
@checklyalex
checklyalex / jsbn.js
Created January 17, 2024 16:20
A pre-exported jsbn and rsa library
var RSA = function () {
/** BEGIN JSBN (http://www-cs-students.stanford.edu/~tjw/jsbn/jsbn.js) **/
/*!
* Copyright (c) 2003-2005 Tom Wu
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@checklyalex
checklyalex / klarna_multistep_check.spec.ts
Created December 5, 2023 17:21
A Klarna Playwright open banking flow implementation. This example can be directly used in Checkly.
const { test, expect } = require('@playwright/test');
const { sendEncryptedResponse } = require('./snippets/functions.js')
const auth_token = process.env.KOSMA_AUTH_TOKEN
const psu_ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36";
const psu_ip = "10.20.30.40"
test.describe('Klarna Open Banking', () => {
test('XS2A API Flow', async ({ request }) => {
@checklyalex
checklyalex / wss.js
Created November 15, 2023 15:03
Websocket Example
import WebSocket from 'ws';
const url = `wss://ws.postman-echo.com/raw`
const ws = new WebSocket(url);
const timeout = setTimeout(function () {
console.log('Failed to receive expected data within timeout. Terminating the WebSocket connection.')
ws.close()
throw new Error('Failed to receive expected data within timeout.')
}, 10000)
@checklyalex
checklyalex / mult-step-api.js
Last active September 12, 2023 09:12
An example of a Checkly Multi-Step API check utilising Playwright Test
import { test, expect } from '@playwright/test'
const token = '_ZMd4xxx'
const url = 'https://crudapi.co.uk/api/v1/tasks'
const headers = {
Authorization: `Bearer ${token}`
}
test('multi-step api', async ({ request }) => {