Monitoring as Code works by connecting Playwrighttest files with Checkly constructs to handle the end-to-endconfiguration of your Browser Check.

Browser Check Construct

The Browser Check construct is used to configure your monitoring settings, such as frequency, locations, and tags. Learn more about the Browser Check Construct
browser-check.ts
import { BrowserCheck, Frequency } from 'checkly/constructs'
import * as path from 'path'

new BrowserCheck('browser-check-1', {
  name: 'Browser check #1',
  frequency: Frequency.EVERY_10M,
  locations: ['us-east-1', 'eu-west-1'],
  code: {
    entrypoint: path.join(__dirname, 'login.spec.js')
  }
})

Test Script Structure

Checkly uses Playwright to power Browser Checks. Playwright is a robust, open-source framework for browser automation and end-to-end web application testing. It enables you to write atomic, reliable tests and easily control interactions within a web page. Browser checks execute automated test scripts in real browsers.
login.spec.ts
// Use environment-specific URLs and credentials
const baseURL = process.env.BASE_URL || 'https://app.example.com'
const testUser = process.env.TEST_USER_EMAIL
const testPassword = process.env.TEST_USER_PASSWORD

test('Environment-aware test', async ({ page }) => {
  await page.goto(`${baseURL}/login`)
  await page.fill('[name="email"]', testUser)
  await page.fill('[name="password"]', testPassword)
  // ... rest of test
})