k6 load testing script generator prompt
Describe an endpoint or user flow and get a k6 load test script with realistic ramp-up stages and pass/fail thresholds.
متى تستخدم هذا البرومبت
- Before a launch or traffic spike you want to prepare for.
- When validating that a new API can handle target request volume.
- When comparing performance before and after an optimization.
نص البرومبت
Write a k6 load test script in {{language}} for this endpoint/flow: {{focus}}. Include realistic virtual user ramp-up and basic pass/fail thresholds.
{{CLIPBOARD}}{{language}}{{focus}}{{CLIPBOARD}}الكتلة {{CLIPBOARD}} تُستبدل تلقائياً بما نسخته قبل الضغط على «نسخ».
كيف تستخدمه
- انسخ البرومبت بالزر أو املأ المتغيرات أولاً.
- الصقه في ChatGPT أو Claude أو Gemini.
- عدّل النتيجة أو أعد الطلب بتغيير المتغيرات.
مثال على النتيجة
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 100 },
{ duration: '30s', target: 0 },
],
thresholds: { http_req_duration: ['p(95)<300'] },
};
export default function () {
const res = http.get('https://api.example.com/products');
check(res, { 'status is 200': (r) => r.status === 200 });
sleep(1);
}نصائح للاستخدام
- State your target request rate and expected latency budget so thresholds are meaningful, not arbitrary.
- Include auth details as environment variables in the script, never hardcoded tokens.
- Run the test against a staging environment first, never directly against production without warning your team.
أسئلة شائعة
- Can it test a multi-step user flow, not just one endpoint?
- Yes, describe each step (login, then add to cart, then checkout) in the focus field and it will chain them in one script.
- Does it handle authentication tokens?
- It will reference them via k6 environment variables; never paste real tokens into the prompt itself.