Skip to content

Instantly share code, notes, and snippets.

View checklyalex's full-sized avatar

Alex checklyalex

View GitHub Profile
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 }) => {
@checklyalex
checklyalex / playwright_page_crawler.js
Last active May 17, 2023 12:08
This JavaScript script navigates to a given webpage, checks all links, and logs their status. It handles redirections, reporting the final URL and its HTTP status code.
const { test, expect } = require('@playwright/test');
const crawl_url = "https://checklyhq.com";
test('Check all links on a page', async ({ page }) => {
test.setTimeout(120000)
// Navigate to the URL
await page.goto(crawl_url); // Replace with your URL
// Get all links on the page
@checklyalex
checklyalex / upload_image_to_s3_bucket.js
Created March 24, 2023 15:11
A Checkly Playwright/Test script to upload a screenshot to S3.
const { expect, test } = require('@playwright/test')
const aws4 = require('aws4')
const axios = require('axios').default
const S3_BUCKET_NAME = 'xxx';
const S3_OBJECT_KEY = '/image.jpg'; // The name you want to give to the uploaded image file
const AWS_REGION = 'eu-west-2'
test('visit page and take screenshot', async ({ page }) => {
const response = await page.goto(process.env.ENVIRONMENT_URL || 'https://checklyhq.com')