Prompt
k6 checkout flow load test
Latest observation
Oct 20, 2026
OpenAI APIWeb search: off
Here’s a practical k6 checkout flow load test example you can adapt for your app.
What it tests
A typical checkout flow:
- Open homepage
- Search/browse product
- View product
- Add to cart
- Go to checkout
- Submit order
Example k6 script
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Trend, Rate } from 'k6/metrics';
export const options = {
stages: [
{ duration: '1m', target: 10 }, // ramp up
{ duration: '3m', target: 50 }, // steady load
{ duration: '1m', target: 100 }, // spike
{ duration: '3m', target: 100 }, // hold
{ duration: '1m', target: 0 }, // ramp down
],
thresholds: {
http_req_failed: ['rate<0.01'],
http_req_duration: ['p(95)<1000'],
checkout_success: ['rate>0.95'],
},
};
const BASE_URL = __ENV.BASE_URL || 'https://example.com';
export const checkout_success = new Rate('checkout_success');
export const checkout_duration = new Trend('checkout_duration');
export default function () {
const params = {
headers: {
'Content-Type': 'application/json',
},
};
const start = Date.now();
// 1. Home page
let res = http.get(`${BASE_URL}/`);
check(res, {
'home loaded': (r) => r.status === 200,
});
// 2. Browse/search product
res = http.get(`${BASE_URL}/products`);
check(res, {
'products page loaded': (r) => r.status === 200,
});
// 3. View a product
const productId = Math.floor(Math.random() * 1000) + 1;
res = http.get(`${BASE_URL}/products/${productId}`);
check(res, {
'product page loaded': (r) => r.status === 200,
});
// 4. Add to cart
const addToCartPayload = JSON.stringify({
product_id: productId,
quantity: 1,
});
res = http.post(`${BASE_URL}/cart/add`, addToCartPayload, params);
const addToCartOk = res.status === 200 || res.status === 201;
check(res, {
'added to cart': () => addToCartOk,
});
// 5. Checkout page
res = http.get(`${BASE_URL}/checkout`);
check(res, {
'checkout page loaded': (r) => r.status === 200,
});
// 6. Submit order
const orderPayload = JSON.stringify({
shipping_address: {
name: 'Test User',
line1: '123 Main St',
city: 'New York',
state: 'NY',
postal_code: '10001',
country: 'US',
},
payment_method: 'test_card',
});
res = http.post(`${BASE_URL}/checkout/submit`, orderPayload, params);
const success = res.status === 200 || res.status === 201;
checkout_success.add(success);
checkout_duration.add(Date.now() - start);
check(res, {
'order submitted': () => success,
});
sleep(1);
}
Run it
k6 run -e BASE_URL=https://your-site.com checkout_test.js
Notes for real checkout testing
You’ll usually need to add:
- Authentication: login first or use a token
- Session handling: cookies / CSRF token
- Dynamic product IDs: pull from API instead of hardcoding
- Cart persistence: use same session across requests
- Test payment gateway: use sandbox/test cards only
- Correlation: extract values like CSRF, cart ID, order token from responses
If your checkout uses APIs
A more realistic checkout load test often hits backend endpoints directly:
POST /api/loginGET /api/productsPOST /api/cartPOST /api/checkoutPOST /api/payments/confirm
Good thresholds to start with
You can tune these based on your SLA:
thresholds: {
http_req_failed: ['rate<0.01'],
http_req_duration: ['p(95)<1000'],
checkout_success: ['rate>0.98'],
}
If you want, I can also provide:
- a login + checkout k6 script
- a GraphQL checkout test
- a realistic multi-user journey with cookies/CSRF
- a CI/CD-ready k6 test setup
Brands