What are scenarios?
Scenarios configure how VUs (virtual users) and iterations are scheduled during test execution. Each scenario can:- Execute a different JavaScript function
- Use a different executor to control workload patterns
- Run in parallel or sequence with other scenarios
- Have independent environment variables and tags
Why use scenarios?
Scenarios provide several benefits over simple VU/duration configuration:Realistic traffic patterns
Model different user behaviors with arrival rates, iterations, or ramping patterns.
Multiple workloads
Run different test functions in parallel or sequence within one test.
Better organization
Separate different test phases or user types into distinct scenarios.
Granular analysis
Tag and analyze each scenario independently with scenario-specific metrics.
Basic scenario configuration
Define scenarios in theoptions.scenarios object:
- A unique name (
my_scenario) - An
executorproperty specifying the workload pattern - Executor-specific configuration (like
vusandduration)
Scenario executors
Executors determine how k6 schedules VUs and iterations. Choose the executor that best matches your workload:By iterations
By VUs
- constant-vus
- ramping-vus
A constant number of VUs for a duration.Use when: You want steady load with 50 VUs for 1 minute.
By arrival rate
- constant-arrival-rate
- ramping-arrival-rate
Fixed iteration rate (open model).Use when: You need exactly 100 requests per second, regardless of response time.
Scenario options
All scenarios support these common options:| Option | Type | Description | Default |
|---|---|---|---|
executor | string | Executor type (required) | - |
startTime | string | Delay before starting | "0s" |
gracefulStop | string | Time to wait for iterations to finish | "30s" |
exec | string | Function name to execute | "default" |
env | object | Scenario-specific environment variables | {} |
tags | object | Scenario-specific tags | {} |
Multiple scenarios
Run multiple scenarios in parallel:Scenario-specific tags and environment
Tag metrics by scenario:Complete example
Here’s a realistic scenario combining multiple patterns:Scenario execution output
When running scenarios, k6 displays scenario information:Best practices
Choose the right executor
Use VU-based executors for closed models, arrival-rate executors for open models.
Use meaningful names
Name scenarios descriptively: “warmup”, “load_test”, “spike” not “scenario1”.
Tag for analysis
Add scenario-specific tags to enable granular threshold and analysis.
Sequence with startTime
Use startTime to create sequential test phases within one test run.
Next steps
Executors Reference
Detailed documentation for each executor type with advanced options