Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/latest/javascript-api/k6/group.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/latest/javascript-api/k6/group/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
group( name, fn )
Note
For details about using the
check()function with async values, refer to the jslib utils check.
Run code inside a group. Groups are used to organize results in a test.
| Parameter | Type | Description |
|---|---|---|
| name | string | Name of the group. |
| fn | function | Group body - code to be executed in the group context. |
Returns
| Type | Description |
|---|---|
| any | The return value of fn. |
Limitations
Warning
Avoid using
groupwith async functions or asynchronous code. If you do, k6 might apply tags in an unreliable or unintuitive way.
If you start promise chains or use await within group, some code within the group will be waited for and tagged with the proper group tag, but others won’t be.
To avoid confusion, async functions are forbidden as group() arguments. That still lets users make and chain promises within a group, but doing so is unsupported and not recommended.
For more information, refer to k6 #2728, which tracks possible solutions and provides detailed explanations.
Example
import { group } from 'k6';
export default function () {
group('visit product listing page', function () {
// ...
});
group('add several products to the shopping cart', function () {
// ...
});
group('visit login page', function () {
// ...
});
group('authenticate', function () {
// ...
});
group('checkout process', function () {
// ...
});
}The above code will present the results separately depending on the group execution.
Learn more on Groups and Tags.
Was this page helpful?
Related resources from Grafana Labs

