Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
version: "1.0.0"
title: "OpenAPI to Locust Load Test Generator"
description: "Generate comprehensive Locust load tests from OpenAPI/Swagger specifications"
author:
contact: Better-Boy

instructions: |
You are an expert in API testing and load testing with Locust.
Your task is to generate production-ready Locust load test files from OpenAPI specifications.

Follow this workflow:
1. First, analyze the OpenAPI spec to understand the API structure
2. Generate Locust task sets for different endpoint groups
3. Create the main locustfile with proper configuration
4. Generate supporting files (requirements.txt, README, config)

Ensure the generated tests are:
- Well-structured with proper task weighting
- Include realistic user behavior patterns
- Have proper error handling and assertions
- Use parameterized data where appropriate
- Follow Locust best practices

parameters:
- key: openapi_spec_path
input_type: string
requirement: required
description: "Path to the OpenAPI specification file (JSON or YAML)"

- key: base_url
input_type: string
requirement: optional
default: "http://localhost:8000"
description: "Base URL for the API to test"

- key: output_dir
input_type: string
requirement: optional
default: "./load_tests"
description: "Directory where generated test files will be saved"

- key: test_complexity
input_type: string
requirement: optional
default: "standard"
description: "Test complexity level: basic, standard, or advanced"

- key: include_auth
input_type: string
requirement: optional
default: "true"
description: "Whether to include authentication handling in tests"

sub_recipes:
- name: analyze_openapi
path: "./subrecipes/analyze-openapi.yaml"
values:
analysis_depth: "comprehensive"

- name: generate_task_sets
path: "./subrecipes/generate-task-sets.yaml"

- name: generate_locustfile
path: "./subrecipes/generate-locustfile.yaml"

- name: generate_support_files
path: "./subrecipes/generate-support-files.yaml"

extensions:
- type: builtin
name: developer
timeout: 600
bundled: true

prompt: |
Generate complete Locust load tests from the OpenAPI specification at {{ openapi_spec_path }}.

Configuration:
- Base URL: {{ base_url }}
- Output directory: {{ output_dir }}
- Test complexity: {{ test_complexity }}
- Include authentication: {{ include_auth }}

Use the sub-recipe tools in this order:
1. analyze_openapi - Parse and analyze the OpenAPI spec
2. generate_task_sets - Create Locust TaskSets for endpoint groups
3. generate_locustfile - Generate the main locustfile.py
4. generate_support_files - Create requirements.txt, README.md, and config files

After all subrecipes complete, verify all files were created successfully and provide:
- Summary of generated files
- Instructions for running the tests
- Example commands for different load scenarios
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: "1.0.0"
title: "OpenAPI Spec Analyzer"
description: "Parse and analyze OpenAPI specification to extract endpoints, schemas, and auth details"
instructions: |
You are an API specification expert. Parse the OpenAPI/Swagger specification file
and extract all relevant information for load test generation.

Your analysis should include:
- List of all endpoints grouped by tags/categories
- HTTP methods, paths, and parameters for each endpoint
- Request/response schemas and content types
- Authentication and security schemes
- Rate limits and other constraints if defined

Output Format:
Create a structured analysis with:
1. API metadata (title, version, description)
2. Base servers/URLs
3. Authentication methods used
4. Endpoint groups with their operations
5. Common schemas and data models
6. Recommended test scenarios based on endpoint relationships

parameters:
- key: output_dir
input_type: string
requirement: required
description: "Output directory"

- key: openapi_spec_path
input_type: string
requirement: required
description: "Path to the OpenAPI specification file"

- key: analysis_depth
input_type: string
requirement: optional
default: "standard"
description: "Depth of analysis: basic, standard, or comprehensive"

extensions:
- type: builtin
name: developer
timeout: 300
bundled: true

prompt: |
Analyze the OpenAPI specification at {{ openapi_spec_path }}.
Perform a {{ analysis_depth }} analysis.

Steps:
1. Read and parse the spec file (handle both JSON and YAML formats)
2. Extract API metadata and server information
3. Identify all authentication/security schemes
4. Group endpoints by tags or logical categories
5. For each endpoint, document:
- HTTP method and path
- Path/query/header parameters
- Request body schema (if applicable)
- Response schemas
- Security requirements
6. Identify endpoint relationships (e.g., POST /users before GET /users/{id})
7. Suggest realistic test scenarios and user flows

Save the analysis to {{ output_dir }}/analysis.json for use by other sub-recipes.

Present a summary with:
- Total number of endpoints
- Endpoints grouped by category
- Authentication types used
- Recommended test flow sequences
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
version: "1.0.0"
title: "Main Locustfile Generator"
description: "Generate the main locustfile.py that orchestrates all TaskSets"
instructions: |
You are a Locust expert. Create the main locustfile.py that ties together
all the TaskSets and provides the entry point for load testing.

The main locustfile should:
- Import all TaskSet classes from the tasks directory
- Define HttpUser classes that use the TaskSets
- Configure wait times and user behavior
- Set up authentication and session handling
- Include environment configuration (host, users, spawn rate)
- Add event hooks for setup/teardown and custom stats
- Include command-line argument handling if needed

Support multiple user types/personas if the API has different access levels
(e.g., AdminUser, RegularUser, GuestUser)

parameters:
- key: output_dir
input_type: string
requirement: required
description: "Output directory"

- key: base_url
input_type: string
requirement: required
description: "Base URL for the API"

- key: include_auth
input_type: string
requirement: required
description: "Whether to include authentication"

- key: test_complexity
input_type: string
requirement: required
description: "Test complexity level"

extensions:
- type: builtin
name: developer
timeout: 300
bundled: true

prompt: |
Generate the main locustfile.py that orchestrates the load tests.

Structure:
```python
from locust import HttpUser, between, events
import os
from tasks.users_tasks import UsersTaskSet
from tasks.products_tasks import ProductsTaskSet
# ... import other TaskSets

class APIUser(HttpUser):
wait_time = between(1, 3)
host = "{{ base_url }}"

tasks = [UsersTaskSet, ProductsTaskSet] # Mix of all TaskSets

def on_start(self):
"""Called when a simulated user starts"""
{% if include_auth == "true" %}
# Perform login and store token
response = self.client.post("/auth/login", json={
"username": "test_user",
"password": "test_pass"
})
self.token = response.json().get("token")
self.client.headers.update({"Authorization": f"Bearer {self.token}"})
{% endif %}

def on_stop(self):
"""Called when a simulated user stops"""
pass

# Event hooks for custom behavior
@events.test_start.add_listener
def on_test_start(environment, **kwargs):
print("Load test starting...")

@events.test_stop.add_listener
def on_test_stop(environment, **kwargs):
print("Load test complete!")
```

{% if test_complexity == "advanced" %}
Include multiple user types with different behavior patterns:
- AdminUser: Has access to admin endpoints
- RegularUser: Normal user operations
- ReadOnlyUser: Only GET requests

Use task distribution weights for realistic traffic patterns.
{% endif %}

Add configuration for:
- Environment variables for credentials
- Custom headers
- Connection pooling settings
- Request/response hooks for logging

Save to {{ output_dir }}/locustfile.py

Also create a .env.example file with placeholder values for:
- API_BASE_URL
- AUTH_USERNAME
- AUTH_PASSWORD
- Any API keys or tokens needed
Loading
Loading