No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.46. Go to the latest version.

group( name, fn )

Run code inside a group. Groups are used to organize results in a test.

ParameterTypeDescription
namestringName of the group.
fnfunctionGroup body - code to be executed in the group context.

Returns

TypeDescription
anyThe return value of fn.

Working with async functions

Avoid using group with async functions or asynchronous code. If you do, k6 might apply tags in a way that is unreliable or unintuitive.

If you start promise chains or even 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. This 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.