Use the test builder
The Test Builder is a graphical tool to author k6 test scripts. You can use it to learn the k6 API or to make or prototype tests without needing to write a script.
To use the test builder, go to the k6 app in your Grafana instance. Then, follow these steps:
- From k6, select Create new test.
- Select the Test Builder.
From here, you have a single interface to configure different aspects of a load test:
- Make scenarios to model user behavior and real-world load. For some conceptual background, read About scenarios.
- Use thresholds to assert that the test meets its performance goals.
- Distribute load across global geographical locations.
Make requests and check values
To add HTTP requests to your tests, find the scenario, then select Requests. As you build a test, the application creates a script file. To view the script file, use the toggle at any time.
Add a request
- Select Request.
- Select the HTTP method you want to use.
- Name the request and enter the target URL.
- Fill in the relevant query params and bodies.
Evaluate response values
As a load test runs, systems start to return unexpected responses. You can add checks to your requests to evaluate responses.
To add a check, follow these steps:
- From the request, select Checks.
- Choose the check type, then Add new check.
- Write in the expressions that k6 evaluates for in the response.
Pass data from responses to requests
With variables, you can take a value from a response and pass it to a new request. For example, you could select a JSON value that the system returns, then add the value in the body of a subsequent POST request.
To use variables, follow these steps:
In the request, select Variables.
Add variable. Choose the variable type and enter its expression.
Make a new request, and then drag it under the request where you declared a variable.
Use the variable in your request. For example, it could be in a query param or request body. The syntax is as follows:
${variable_name}
Group requests
Each request has unique tags, which increase the cardinality of your data. If your test makes requests to many URLs, it may be impractical to have so many unique URLs.
With groups, you can organize your requests in categories. This makes filtering easier, and it can be a way to organize requests in categories that correspond to the application’s business logic.
To group requests, follow these steps:
- Select Group. This creates a new Group.
- Give the Group a name and description.
- Drag your requests under the group. Order them in the sequence that they should run.
The app displays how many requests and how much sleep is in the group. You can use this to confirm that the group is correctly populated.
To learn about using Groups in your scripts, refer to Groups in the k6 OSS docs.Model load patterns
Along with modeling user behavior, you can also model traffic patterns for each scenario:
- In the scenario, select Options.
- Choose the executor and enter values.
In short, you con model traffic in the following paradigms:
- Whether traffic is dynamic or changing (
constant
orramping
). - Whether virtual users execute one after another, or at a simultaneous rate (as with the
arrival-rate
executors).
Set load zones
Real-world traffic comes from different locations. To simulate this, you can choose the load zones where the test runs (tests can run from one or many regions).
To configure load zones, follow these steps:
- Under Options, go to Load zones.
- Choose the load zone you want.
- Optionally add more load zones.
If you want to distribute load non-uniformly, use the Manual switch and enter percentages.
Assert for performance goals
Before you test, you should have a goal for how the system behaves under load. To set criteria for your system, you can use the threshold option.
- Under Options, go to Thresholds.
- Choose the metrics and conditions. Enter a value.
- Choose whether a crossed threshold should abort execution with Stop Test.