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

Tag tests with test case IDs

Link the scripts that Test Companion writes to BrowserStack Test Management test cases, check the last run of a test case, and tag tests you wrote earlier.

A test case ID tag is a Test Management identifier, such as TC-1234, written into a test script. When the tagged script runs on BrowserStack, the result attaches to that test case. Test Management then shows the run status and the automation coverage of the test case from real runs.

Test Companion writes the tag into each script it generates and checks the tag after the write. It can also report the last automated run of a test case. For tests that you wrote earlier, it finds the matching test case and writes the ID.

Tagging works with BrowserStack Test Management only. With Zephyr, Xray, TestRail, or Azure Test Plans, Test Companion writes scripts without a tag and skips the tag check.

Prerequisites

You need the following before you start:

  • A BrowserStack Test Management project selected in Test Companion. The tag check, the last run result, and linking all use the selected project.
  • A version of Test Companion that supports the capability you need. See Availability.

Tag new scripts

When Test Companion writes a test file, it adds one test case ID tag to the file. It uses an ID that it already has:

  • The ID of the test case that you asked it to automate.
  • The ID of a test case that it added to Test Management for you.
  • The ID that it finds in the project when you give only the title of a test case.

Test Companion does not invent an ID. Without an ID for a script, it writes the file untagged and says so in the chat.

Tag forms

The file type decides the tag form. Each test file carries one tag.

File type Placement Example
JavaScript or TypeScript test At the end of the test title. An ID at the start of the title does not link. test('logs in TC-1234', ...)
Cucumber .feature file In a @TCID_ tag on the line above the scenario. @TCID_TC-1234
Cucumber .feature file in a BrowserStack SDK run At the end of the scenario name. Scenario: logs in TC-1234
pytest In a record_property call, as the first statement of the test. record_property("id", "TC-1234")
pytest in a BrowserStack SDK run In a set_custom_tag call, as the first statement of the test. driver.set_custom_tag("ID", "TC-1234")
Java with TestNG In a Reporter.log property, as the first statement of the test method. Reporter.log("[[PROPERTY\|id=TC-1234]]\n", true);
Java with TestNG in a BrowserStack SDK run In a setCustomTag call, as the first statement of the test method. BrowserStack.setCustomTag("ID", "TC-1234");
Kotlin In a backticked test name, because a plain method name cannot hold the hyphen. fun `logs in TC-1234`()
C# and Swift In a marker printed as the first statement of the test. print("[[PROPERTY\|id=TC-1234]]")

A project with a browserstack.yml file in its root runs tests through the BrowserStack SDK. In these runs, only three forms link to a test case:

  • The ID at the end of a test title.
  • The ID at the end of a scenario name.
  • A setCustomTag or set_custom_tag call.

BrowserStack reads the other forms, but the run creates a new test case instead of attaching to yours. The build still passes, so the mismatch is easy to miss. The tag check reports it.

For how BrowserStack reads each form, see Test case ID tagging in Test Management.

Tag check after each write

After Test Companion writes a full test file, it checks the tag against the selected project. The check never blocks the write. When it finds a problem, Test Companion fixes the tag before it runs the test. It also posts a notice in the chat that starts with Test case tagging notice.

The check reports the following problems:

Problem Meaning
Missing tag The file contains a test but no test case ID.
Tag form that does not link The project has a browserstack.yml file, and the file uses a form that creates a new test case instead of attaching to yours.
ID not found The ID does not exist in the selected Test Management project. A wrong ID attributes the run to another test case.
Conflicting tags The file contains two tag forms with two different IDs. The same ID in two forms is not a conflict.

Review the corrected tag before you run the test yourself.

The check has two limits. It runs only on a full file write. An edit to part of a file does not report a missing tag. If a lookup fails, for example after a network error, Test Companion does not warn about that ID.

Check the last run result of a test case

Give Test Companion the test case ID, such as TC-1234, or the numeric ID from the test case URL. It reports the last automated run of that test case.

Example prompt

What was the result of the last run of TC-1234?

The answer starts with Last Automate run for TC-1234: followed by one of these states:

State Meaning
Covered The most recent automated run passed.
Failing The most recent automated run failed.
Never run The test case is set up for automation but has not run yet.
Only manual results The latest result came from a manual run. There is no automated run on record.
No runs No run results are recorded for the test case.

The answer also lists the verdict, run type, build, run time, and result on each platform. It ends with a link to the evidence when one exists. You can ask for a run result in Plan mode.

A test without a test case ID does not count toward automation coverage. Linking adds the ID to tests that you wrote before you used tags. Test Companion matches each untagged test with a test case in the selected project. It then writes the ID into the test, in the tag form of the framework.

Linking changes only your test code. It does not create or edit test cases in Test Management.

Supported frameworks

The framework of a test decides where you start and where Test Companion writes the ID.

Framework Starting point Matching input Tag placement
Playwright Banner or chat box Test title and test code At the end of the test title.
Cypress Chat box Test title and test code At the end of the test title.
pytest Chat box Test name In a record_property call or a set_custom_tag call.
Java with TestNG Chat box Test name In a Reporter.log property or a setCustomTag call.
Cucumber Chat box Scenario name In a @TCID_ tag on the line above the scenario.

Test Companion compares the matching input with the title and steps of each test case. For the syntax of each tag, see Tag forms.

Test Companion skips a test file in any other framework. It names the framework in the chat as not supported.

Start linking

You can start from the banner, the chat box, or the Test Companion CLI.

From the banner

After you select a Test Management project, Test Companion counts the untagged Playwright tests in the workspace. When it finds at least one, the Increase automation coverage banner appears on the Test Cases tab. The banner shows the number of tests that are not linked.

Test Cases tab with the Increase automation coverage banner above the folder tree, showing the Link button and the close icon

Click Link to start linking in the chat. Click the Dismiss icon, shown as an X, to hide the banner until you select a project again. Click Don’t show again to turn off the banner for every project in the workspace.

The banner counts Playwright tests only. To link tests in the other supported frameworks, start from the chat box.

From the chat box

Enter a prompt that asks Test Companion to link your tests. The Link button on the banner sends the following prompt:

Link my existing automated tests in this workspace to their Test Management cases.

From the Test Companion CLI

When you select a project with tc tm use --project, the CLI prints the number of untagged Playwright tests. It shows no banner. It prints the command that starts linking instead:

tc run "Link my existing automated tests in this workspace to their Test Management cases."

Linking process

After you start, Test Companion does the following:

  1. Finds the test files in the workspace and counts the tests without a test case ID. It skips tests that already carry an ID in any form.
  2. Compares each untagged test with the test cases in the project. A progress card in the chat reads Matching tests to Test Management cases while this runs.
  3. Writes the ID into each test that it matched with confidence. The changes appear as a normal file diff for you to review.
  4. Posts a summary with three sections: Matched, Needs review, and No match found.

When a test has the same title as exactly one test case, Test Companion matches it on the title. This comparison ignores letter case and punctuation. For every other test, Test Companion also compares the test with the steps of the closest test cases.

Test Companion never guesses an ID. It writes only the IDs that the matching step returned.

Review the summary

Each section of the summary lists the tests in one state:

Section Meaning Next action
Matched Test Companion found one confident match and wrote the ID into the test. Review the file diff before you keep the change.
Needs review Two test cases matched the test almost equally well. The test stays untagged. Compare the test with the test case ID that the summary shows. Add the ID yourself if it is correct.
No match found No test case matched the test with confidence. The test stays untagged. Add the ID yourself if the test case exists. If it does not exist, create the test case first.

Two untagged tests with the same title in one Playwright or Cypress file are not linked. Both tests appear under No match found. Give each test a different title, then start linking again.

In the CLI, the summary is one line, such as TM-ID tagging: 12 matched · 3 need review · 2 no match.

Check the tag form in BrowserStack SDK projects

A project with a browserstack.yml file in its root runs tests through the BrowserStack SDK. In these runs, a record_property call, a Reporter.log property, and a @TCID_ tag do not link. The run creates a new test case instead of attaching to yours.

After linking, check the tag in each changed pytest, TestNG, and Cucumber file. When a file carries a form that does not link, change the tag as follows:

  • In a pytest test, use a set_custom_tag call.
  • In a TestNG test, use a setCustomTag call.
  • In a Cucumber scenario, move the ID to the end of the scenario name.

Playwright and Cypress tests need no change. An ID at the end of a test title links in SDK runs.

Run the linked tests

Linking does not change the Automation Status of a test case. That status changes after the tagged test runs on BrowserStack and passes. So run the tagged tests after you link them.

Availability

IDE or CLI Tag check after each file write Last run result of a test case Link existing tests
Visual Studio Code 1.29.7 and later 1.33.0 and later 1.35.0 and later
JetBrains IDEs 1.6.8 and later 1.10.0 and later Not supported
Test Companion CLI Supported Supported Supported
Visual Studio Not supported Not supported Not supported
Eclipse Not supported Not supported Not supported

In Visual Studio and Eclipse, Test Companion adds the tag when it writes a script. It does not check the tag afterward.

Linking existing tests is not available in Cloud mode.

Best practices

  • Select the Test Management project before you ask for a script. The tag check and linking use the selected project.
  • Keep one tag form in each test file. Two forms with two different IDs are reported as a conflict.
  • Put the ID at the end of the test title. In JavaScript and TypeScript tests, an ID at the start of the title does not link.
  • Write the ID with a hyphen. TC_1234 does not link.
  • Give a test the same title as its test case when you can. If no other test case has that title, the test links on the title alone.
  • Review linked tests before you merge them. Check the tests under Needs review and the tests with no match.
  • Run the tagged tests. Automation coverage updates from runs, not from the tag alone.

Next steps

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