Playwright Tags

How to tag Playwright executions in Currents

Note

A tag is limited to 128 characters

Using tags is a common technique for better classifying recorded test results and getting relevant insights about the test suite. Here are several examples of how software teams use tags:

  • manage ownership - e.g. use the team name as a tag

  • categorize product features - e.g. tagging onboarding flow tests

  • manage tests lifecycle - e.g. tag newly introduced tests as ustable

The tags are available for producing meaningful reports, exploring metrics, narrowing down Slack notifications, filtering the results, API responses and more.

Playwright Tags

@currents/playwright version 0.10.0+ is required for test title tags

Test title tags

Currents parses the test titles and recognizes the conventional Playwright Tags that appear in test definitions. For example, recording the results of the following tests to Currents:

test('Test login page @fast', async ({ page }) => {
  // ...
});

test('Test full report @slow', async ({ page }) => {
  // ...
});

...will create a run with tags: fast and slow

Test group tags

Tagging a test group (test.describe) will "apply" the tag to every included individual test, as well as to the created run. For example, given the following test definition:

test.describe("test group @groupTag", () => { // 👈🏻 note the test group tag

  test('Test login page @fast', async ({ page }) => {
    // ...
  });
  test('Test full report @slow', async ({ page }) => {
    // ...
  });
})

Currents will assign the following tags to the created items:

ItemTags

Run

groupTag, fast, slow

Test login page @fast

groupTag, fast

Test full report @slow

groupTag, slow

Tags with --grep applied

If certain tags are excluded from the execution, for example by using --grep CLI option, only the included tests (and their tags) will be used for tagging.

$ npx playwright test --grep @fast

Removing tags from test titles

It is often desired to ignore the tags included in the test title to have a consistent view of the test history or preserve the metrics.

For example, let's say you have a test named Test login page @slow , eventually, you add another tag and the test title becomes Test login page @slow @login. However, adding the tag will change the test name - as a result, the history of previous executions and metrics will be lost.

To remove the tags from the recorded test titles, add --pwc-remove-title-tags CLI option or removeTitleTags reporter configuration. Activating the removal will strip the tags from test titles (including test group names) when recording to Currents dashboard.

In the example above, Test login page @slow and Test login page @slow @login will be recorded as Test login page and tags slow + login will be attached to the test recording.

Disabling parsing test title tags

You can disable parsing test title tags altogether by adding --pwc-disable-title-tags CLI option. See @currents/playwright for additional configuration options, available in versions 0.11.0+ .

Run-level Tags

@currents/playwright version 0.7.0+ is required to use run-level tags

In addition to encoding tags in test titles, you can explicitly tag the whole run (or a playwright project). There are multiple ways to explicitly tag a run.

Tagging a run using pwc CLI option

If you're using pwc executable script to run the tests, use --tag CLI option:

npx pwc --tag tagA,tagB --tag tagC

You can provide a comma-separated list of tags, provide multiple --tag options, or use both.

Tagging a run using Reporter configuration

You can tag playwright execution by providing a list of tag values to Currents Reporter in your playwright.config.ts file. For example:

import { currentsReporter } from '@currents/playwright';

// ...
reporter: [
  currentsReporter({
    ciBuildId: process.env.CURRENTS_CI_BUILD_ID,
    recordKey: process.env.CURRENTS_RECORD_KEY,
    projectId: process.env.CURRENTS_PROJECT_ID,
    tag: ["runTagA", "runTagB"],
  }),
  /* other reporters, if exist, e.g.:
  ["html"]
  */
]

Tagging a run using CURRENTS_TAG environment variable

You can tag playwright execution by setting the CURRENTS_TAG environment variable value to a comma-separated list of tags, for example, with @currents/playwright reporter configured:

CURRENTS_TAG=tagA,tagB npx playwright run ...

Precedence of configuration options

If there are multiple definitions of run-level tags, Currents will pick the tags as follows:

  • Use comma-separated tags of CURRENTS_TAG environment variable, if provided; otherwise

  • Use --tag CLI option values, if provided; otherwise

  • Use reporter configuration values, if provided; otherwise

  • add no run tags

Project-level Tags

@currents/playwright version 0.10.0+ is required for project-level tags

You can tag Playwright projects by using metadata.pwc.tags field in the project's configuration. For example, given the following Playwright project configuration:

// playwright.config.ts

// ...
{
   projects: [
      {
        name: "Desktop Chrome",
        metadata: {
          pwc: {
            tags: ["desktop", "chrome"], // 👈🏻 note the tags
          },
        },
        use: {
          ...devices["Desktop Chrome"],
        },
      },
      // ...
  ]
}

Currents will create a run tagged with desktop, chrome + all the tags extracted from individual tests.

How Tags are Applied

Currents stores the recorded results as Runs, Groups, Spec Files and Tests. The items are available in the dashboard and also in Introduction responses.

  • Run - is a high-level abstraction that represents a CI execution of a test suite

  • Group - is a subset of recorded tests - representing a playwright project

  • Spec File - a recorded execution of tests in a file

  • Test Recording - a recorded execution of a test case

Each of the items can have multiple tags attached, and tagging a particular item can affect the tags of another item. When applying tags, Currents follows the rules below:

  • Apply explicit run-level and project-level tags "downwards" to all the included items

  • Apply individual test tags "upwards" to spec files, projects and runs

The table below shows the details of how the tags are applied:

ItemTags Applied

Run

  • Own run-level tags

  • Tags of all the included projects

  • Tags of all the included test cases

Group/Project

  • Run-level tags

  • Own project-level tags

  • Tags of all the included test cases

Spec File Recording

  • Run-level tags

  • Project-level tags

  • Tags of all the included test cases

Test Case Recording

  • Run-level tags

  • Project-level tags

  • Own test title tags

For example, given the following tests:

test('Test login A @tagA', async ({ page }) => {
  // ...
});
test('Test login B @tagB', async ({ page }) => {
  // ...
});

And adding a run-level tag runTag01 using the command: pwc ... --tag runTag01 will result in the following tags:

ItemApplied Tags

Run

runTag01, tagA, tagB

Test login A

runTag01, tagA

Test login B

runTag01, tagB

Last updated