This repository contains performance testing scripts written with k6 for two API performance testing scenarios.
- k6
- JavaScript (ES6)
K6.mp4
| Method | Endpoint |
|---|---|
| POST | /api/auth/login |
| GET | /api/user/users |
| GET | /api/user/:id |
-
Login as Admin.
-
Extract the authentication token.
-
Fetch all users.
-
Randomly select a user.
-
Search the selected user by ID.
-
Print:
- User ID
- Name
- Phone Number
-
Print response time for each API.
- Admin Login API
- Get All Users API
- Get User By ID API
- Login response status is 200
- User list response status is 200
- User details response status is 200
- Selected user ID matches searched user ID
| API | Threshold |
|---|---|
| Admin Login API | p(95) < 600ms |
| Get All Users API | p(95) < 800ms |
| Get User By ID API | p(95) < 600ms |
GET
https://demoqa.com/BookStore/v1/Books
| Stage | Duration |
|---|---|
| Ramp up to 10 VUs | 20s |
| Stay at 10 VUs | 30s |
| Ramp up to 25 VUs | 20s |
| Stay at 25 VUs | 30s |
| Ramp down to 0 VUs | 20s |
- Response status is 200
- Response body contains books
- Response time is below 600ms
- 95% of requests complete within 600ms
- Failed request rate remains below 1%
The script prints the total number of books returned by the API.
Run Question 1:
k6 run question1.jsRun Question 2:
k6 run question2.js- API response status validation
- API response time logging
- Random user selection and verification
- User information printed to the console
- Total number of books printed
- Threshold evaluation after test completion