Back to home
Built with
A
Adamm QA Labs
Playwright
API Testing
AI Test Plan
AI Test Case
History
AR
Playwright Automation Demo
Edit the script, run tests, and see real-time terminal output
Templates
Run Tests (7)
Script Editor
Terminal Output
tests/api-tests.spec.ts
7 tests detected
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { test, expect } from '@playwright/test'; const BASE_URL = 'https://jsonplaceholder.typicode.com'; test.describe('JSONPlaceholder API Tests', () => { test('GET /posts should return 100 posts', async ({ request }) => { const response = await request.get(`${BASE_URL}/posts`); expect(response.status()).toBe(200); const posts = await response.json(); expect(posts).toHaveLength(100); }); test('GET /posts/1 should return a single post', async ({ request }) => { const response = await request.get(`${BASE_URL}/posts/1`); expect(response.status()).toBe(200); const post = await response.json(); expect(post.id).toBe(1); expect(post).toHaveProperty('title'); expect(post).toHaveProperty('body'); }); test('POST /posts should create a new post', async ({ request }) => { const newPost = { title: 'Automation Test Post', body: 'Created by Playwright', userId: 1, }; const response = await request.post(`${BASE_URL}/posts`, { data: newPost, }); expect(response.status()).toBe(201); const created = await response.json(); expect(created.title).toBe(newPost.title); }); test('PUT /posts/1 should update a post', async ({ request }) => { const updatedPost = { id: 1, title: 'Updated Title', body: 'Updated body content', userId: 1, }; const response = await request.put(`${BASE_URL}/posts/1`, { data: updatedPost, }); expect(response.status()).toBe(200); const result = await response.json(); expect(result.title).toBe('Updated Title'); }); test('DELETE /posts/1 should delete a post', async ({ request }) => { const response = await request.delete(`${BASE_URL}/posts/1`); expect(response.status()).toBe(200); }); test('GET /users should return 10 users', async ({ request }) => { const response = await request.get(`${BASE_URL}/users`); expect(response.status()).toBe(200); const users = await response.json(); expect(users).toHaveLength(10); }); test('GET /posts?userId=1 should filter posts by user', async ({ request }) => { const response = await request.get(`${BASE_URL}/posts?userId=1`); expect(response.status()).toBe(200); const posts = await response.json(); expect(posts.length).toBeGreaterThan(0); posts.forEach((post: { userId: number }) => { expect(post.userId).toBe(1); }); }); });