Custom Test
Write custom Node.js test scriptsEdit
Write custom test scripts for advanced scenarios that don't fit into browser, API, or database categories. Custom tests run in a sandbox with an approved set of testing, HTTP, data, and database packages.
Create Test
- Go to Create → Custom Test
- Write TypeScript/JavaScript code
- Run and debug
- Save when passing
Example
/**
* API CRUD flow executed serially.
*
* Purpose:
* - Test the full lifecycle of a resource (Create, Read, Delete)
* - Ensure data consistency across operations
* - Clean up test data after execution
*
* Key Actions:
* - POST to create a resource
* - GET to verify creation
* - DELETE to clean up
* - test.describe.serial ensures tests run in order
*
* @see https://playwright.dev/docs/api-testing
*/
import { expect, test } from '@playwright/test';
const API_URL = 'https://jsonplaceholder.typicode.com';
// Use serial mode to share state (createdId) between tests
test.describe.serial('posts CRUD', () => {
let createdId;
test('creates a post', async ({ request }) => {
const response = await request.post(API_URL + '/posts', {
data: { title: 'Playwright', body: 'API example', userId: 1 },
});
expect(response.status()).toBe(201);
const json = await response.json();
createdId = json.id;
expect(json).toMatchObject({ title: 'Playwright', body: 'API example' });
});
test('fetches the created post', async ({ request }) => {
// Skip if creation failed
test.skip(!createdId, 'create step failed');
const response = await request.get(API_URL + '/posts/' + createdId);
expect(response.ok()).toBeTruthy();
const json = await response.json();
expect(json.id).toBe(createdId);
});
// Cleanup after all tests in this group
test.afterAll(async ({ request }) => {
if (!createdId) return;
await request.delete(API_URL + '/posts/' + createdId);
});
});Features
- Sandboxed TypeScript and JavaScript execution
- Approved packages including Playwright, Axios, Zod, date-fns, Faker, and supported database drivers
- Access to variables with
getVariable() - Access to secrets with
getSecret() - Custom assertions and complex logic
Use Cases
- Multi-step workflows — Create, update, delete sequences
- Data validation — Complex business logic checks
- Integration tests — Multiple services in one test
- API and database workflows — Exercise supported services with approved clients
System APIs such as process, child_process, fs, native http/https, and net are blocked. Use Playwright's request client or Axios for HTTP calls and Supercheck helpers for variables and secrets.