Skip to main content
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Filter k6 tests by tag

Run a subset of a k6 load test by filtering on request-level or group-level tags defined in your script.

k6 tags are short labels you add to requests and groups in your script. This filter saves time by running only the tagged subset of requests you care about, instead of the full script every time.

To add organizational tags to a load test or run in BrowserStack instead, see Add tags.

This filter applies to k6 scripts only. For JMeter, Gatling, Playwright, and other frameworks, it has no effect.

Prerequisites

Before you start, confirm the following:

  • Your k6 script has tags at the request level, group level, or both. If not, you are ready to add them.
  • You have an active BrowserStack Load Testing account.
  • You can access the BrowserStack Load Testing dashboard, or the BrowserStack CLI if you prefer YAML-driven runs.

Where k6 tags come from

A k6 script can have tags at two levels that this filter recognizes.

Request-level tags

Request-level tags are added inside params.tags on any http.* call, such as http.get or http.post. They label individual HTTP requests so you can target them by name.

http.get("https://example.com/", { tags: { name: "01_Homepage_Get" } });

The name tag is the standard way to label a request in k6, but the filter matches any value in params.tags. For example, a request tagged { name: "Login_Get", category: "smoke" } matches a filter for either Login_Get or smoke.

Group-level tags

Group-level tags come from the name you pass to group("name", () => { ... }). They label a block of requests as a logical unit, such as a checkout flow or an API workflow. When groups are nested, their names join with :: to form a path.

group("ABC", () => {
  group("heavy", () => {
    http.get("https://example.com/api/products");
  });
});

In this example, the inner http.get lives at the group path ABC::heavy.

When you set up a filter, BrowserStack skips every request whose tags do not match. Skipped requests are not sent over the network, do not record any metrics, and do not appear in the report.

How matching works

Filter matches are exact. Use the exact string from your script when you enter a filter value. The filter does not remove @ prefixes, ignore upper or lower case, or split values on spaces.

Level How matching works
Request Looks for an exact match between any value in params.tags and a tag you entered. Most users filter on the name tag value.
Group Matches group paths as a prefix, with :: between nested groups. For example, filter ABC runs every request inside group("ABC", …) and all nested groups inside it, such as group("ABC", () => group("PQR", …)). Filter ABC::PQR runs only requests inside ABC::PQR, not requests directly inside ABC.

If you set filters at both levels, BrowserStack uses OR to combine them. In include mode, a request runs when a match is found at any level you set.

Common group path typos

You do not need to worry about small typos in group paths. The filter cleans these up before matching:

  • Extra :: at the start or end. For example, ::checkout::payment:: becomes checkout::payment.
  • Three or more colons in a row. For example, checkout::::payment becomes checkout::payment.
  • Extra spaces around segments. For example, checkout :: payment becomes checkout::payment.

A filter that has no real segments, such as just "::", is not allowed.

Configure the filter

Choose include mode to run only the matching tests, or exclude mode to run everything except the matching tests. You can use only one mode per run.

Depending on your preferred method, select any one of the following to configure the filter:

Configure the filter in UI Builder

Open the BrowserStack Load Testing dashboard and start the Create Load Test flow, or select Edit on an existing load test.

On the Load Sources step (Step 2/3), upload your k6 script.

Scroll to the Filter k6 tests by tag (Optional) section below the script upload area, and turn on the toggle. The filter is off by default, so every test in the script runs.

In the Filter mode dropdown, select Include to run only the matching tests, or Exclude to run everything except the matching tests. You can use only one mode per run.

Enter tag values as a comma-separated list in the Request-level tags field, the Group-level tags field, or both. Leave a field empty to skip that level.

Select Configure Load to continue to Step 3/3, then save or run the load test as usual to apply the filter.

Filter k6 tests by tag section on the Load Sources step, with the toggle enabled and Filter mode, Request-level tags, and Group-level tags fields visible

The dashboard checks each tag as you type. If a tag is too long, contains invalid characters, or has an invalid group path, an error message appears below the field.

Configure the filter in YAML

Add the filter to your browserstack-load.yml under the testScriptTags key. Place it at the top level, next to vus, duration, and the other load test parameters.

Each level (test, group) accepts either a YAML list or a comma-separated string. Both forms work the same way; pick whichever you find easier to read.

List form

browserstack-load.yml

Comma-separated string form

browserstack-load.yml

You can also mix the two forms, with one level as a list and the other as a string:

browserstack-load.yml

Exclude mode

To skip matching tests instead of running only them, use exclude in place of include. You can use only one of include or exclude per run. Each level inside is optional; leave out a level to skip filtering on it.

browserstack-load.yml

Run your test

After you update the YAML file, run your load test with the BrowserStack CLI:

Terminal
browserstack-load run --config browserstack-load.yml

Example script and filter outcomes

The following k6 script defines requests at multiple group levels:

sample-test.js

With this script, different filters run the following requests:

Filter Requests that run
Request-level: 01_Homepage_Get 01_Homepage_Get
Request-level: 01_Homepage_Get, 04_Checkout_Post 01_Homepage_Get, 04_Checkout_Post
Group-level: homepage 01_Homepage_Get, 02_Products_API_Get (all requests in the homepage group)
Group-level: ABC 05_ABC_Direct_Get, 06_ABC_Heavy_Products_Get, 07_ABC_Cleanup_Homepage_Get (all requests in ABC and its nested groups)
Group-level: ABC::heavy 06_ABC_Heavy_Products_Get (only requests in the heavy nested group)
Group-level: ABC in Exclude mode 01_Homepage_Get, 02_Products_API_Get, 03_Sign_In_Post, 04_Checkout_Post (everything except ABC and its nested groups)
Request-level: 01_Homepage_Get and Group-level: ABC 01_Homepage_Get, 05_ABC_Direct_Get, 06_ABC_Heavy_Products_Get, 07_ABC_Cleanup_Homepage_Get (a request runs if either filter matches it)

What happens when you run the test

When the load test runs:

  • Every matching request runs normally, with the same metrics, dashboard rows, and response data as a non-filtered run.
  • Every non-matching request is skipped before it is sent. No HTTP traffic is generated, no request count or duration metrics are recorded, and no rows appear in the report.
  • The k6 iteration loop, scenarios, ramp-up, and virtual user (VU) pacing all work the same as a non-filtered run. Only individual requests are skipped.

Limitations

  • Skipped requests leave no trace: Skipped requests do not appear in dashboards, exports, or downloaded reports. It is as if the script never reached that line.
  • Other code still runs: Only http.* calls are skipped. Any other JavaScript in the iteration still runs, including sleep calls, calculations, and console.log statements.
  • Tag limits: Each tag can be up to 64 characters long. Allowed characters are letters, numbers, underscores (_), hyphens (-), periods (.), colons (:), the at symbol (@), forward slashes (/), and spaces. The slash and space let you use HTTP-route-style tags like GET /api/users. You can add up to 50 tags per level for each run.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle