Last active
September 12, 2023 09:12
-
-
Save checklyalex/c81e00c0d27f19322155ff07bd0042ff to your computer and use it in GitHub Desktop.
An example of a Checkly Multi-Step API check utilising Playwright Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) => { | |
/** | |
* Step 1: GET all tasks | |
*/ | |
const tasks = await test.step('get all', async () => { | |
return request.get(url, { headers }) | |
}) | |
expect(tasks).toBeOK() | |
const { items } = await tasks.json() | |
expect(items.length).toEqual(0) | |
/** | |
* Step 2: POST create new task | |
*/ | |
const taskTitle = 'New task!' | |
const newTask = await test.step('create task', async () => { | |
return request.post(url, { | |
data: [{ title: taskTitle }], | |
headers, | |
}) | |
}) | |
expect(newTask).toBeOK() | |
const { items: [{ title, _uuid }] } = await newTask.json() | |
expect(title).toBe(taskTitle) | |
expect(_uuid).toBeDefined() | |
/** | |
* Step 3: DELETE remove task | |
*/ | |
const deletedTask = await test.step('delete task', async () => { | |
return request.delete(url, { | |
data: [{ _uuid }], | |
headers, | |
}) | |
}) | |
expect(deletedTask).toBeOK() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment