Modern QA2026Step 3: Generating Load Test Scenarios — tiles
Log inJoin
5 / 95 · 05 Performance & Chaos Engineering · AI-Driven Load Profiling from Production Traffic← prev⊞ allnext →☰ Read as one page

1.5Step 3: Generating Load Test Scenarios

Once you have personas, use an LLM to translate cluster profiles into load test code. This is where AI accelerates what was previously hours of manual work:

# generate_k6_from_personas.py
from openai import OpenAI

client = OpenAI()

def generate_k6_scenario(persona_profile: dict) -> str:
    """Use an LLM to translate a persona profile into a k6 scenario."""
    prompt = f"""Generate a k6 JavaScript scenario for this user persona:

    Persona: {persona_profile['name']}
    Avg requests per session: {persona_profile['avg_requests']}
    Avg session duration: {persona_profile['avg_duration_s']}s
    Top endpoints (by frequency): {persona_profile['top_endpoints']}
    Write ratio: {persona_profile['write_ratio']}
    Think time range: {persona_profile['think_time_range']}

    Generate realistic k6 code with:
    - Proper think times based on the persona behavior
    - Endpoint mix matching the frequency distribution
    - Appropriate checks and custom metrics
    - Comments explaining the persona's behavior pattern
    """

    response = client.chat.completions.create(
        model="gpt-5.5",  # current OpenAI flagship as of July 2026
        messages=[{"role": "user", "content": prompt}],
        temperature=0.2,
    )
    return response.choices[0].message.content