Map test tags to Test Case IDs
Map pytest BDD scenarios to test cases in BrowserStack Test Management using @TCID_ tags, and tag a test with multiple test case IDs.
You can tag your BDD scenarios with @TCID_<tc-id> to map test results to the corresponding test cases in Test Management.
Prerequisites
- BrowserStack SDK
v1.33.13or later installed in your project. - An existing Test Management account with defined test cases.
- A pytest BDD test suite, for the
@TCID_tag method only. The other methods described on this page work with Java, Python, and any framework that writes console output, JUnit XML reports, or Allure reports.
How it works
When you add the @TCID_<tc-id> tag to a BDD scenario in your .feature file, the SDK captures the entire TCID_<tc-id> string as a tag for that scenario. After the test runs, the SDK checks for a test case in Test Management whose ID matches <tc-id>. If a match is found, the scenario result is automatically mapped to that test case.
Test tag mapping to test case ID is only supported for the pytest-bdd framework.
Tag a pytest BDD scenario
Add the @TCID_<tc-id> decorator directly before a Scenario block in your .feature file. Replace <tc-id> with the actual test case ID from Test Management (for example, TC-5848).
Tag format
You can use the following format to tag a test case ID:
@TCID_<tc-id>
Example .feature file
After the tests complete, the SDK reads the @TCID_ tag from each scenario and maps its result to the matching test case in Test Management. If no test case is found for the given ID, no mapping occurs for that scenario.
Map a test to multiple test case IDs
Multiple test case ID tagging is enabled by default in every Test Management project. When you tag a test with more than one test case ID, Test Management applies its result to every matching test case in the run. If you don’t want a single test execution to map to multiple test cases, disable the setting per project.
Disable multiple test case ID tagging
You need project admin access to change this setting. Turn it off in each project where a test must map to only one test case:
- Sign in to Test Management and open your project.
- Click Settings in the project sidebar. The General tab opens.
- Turn off the Multiple Test Case ID Tagging toggle.
Changing the setting affects test runs that Test Management ingests after the change. Existing test runs remain unchanged.
The setting is project-specific. If you disable it in one project, tagging in your other Test Management projects is unaffected.
Choose a tagging method
Add every test case ID you want the test to map to. Pick the method that matches your framework:
| Setup | Tagging method |
|---|---|
pytest-bdd .feature files |
BDD tags (@TCID_) |
| Java or Python with the BrowserStack SDK | SDK setCustomTag or set_custom_tag
|
| Any framework, via console output | Console log statement |
| JUnit XML or Allure reports | Report-based |
| Test name contains the ID | Title-based tagging |
BDD tags for pytest-bdd
Add one @TCID_ tag on its own line for each test case ID, directly before the Scenario block in your .feature file.
When this scenario passes, Test Management applies the result to TC-17538, TC-17539, and TC-17540.
SDK method for Java and Python
Call setCustomTag in Java or set_custom_tag in Python with the key ID and a space-separated list of test case IDs.
import com.browserstack.v2.utils.BrowserStack;
BrowserStack.setCustomTag("ID", "TC-17538 TC-17539 TC-17540");
Console log statement
Print a log statement in the [[BSTACK_SET_CUSTOM_TAG||ID=...]] format anywhere in your test, with a space-separated list of test case IDs.
System.out.println("[[BSTACK_SET_CUSTOM_TAG||ID=TC-17538 TC-17539 TC-17540]]");
Report-based: JUnit XML and Allure
Add a custom metadata key named id with a space-separated list of test case IDs. This method works with any framework that generates JUnit XML or Allure report files.
Multiple IDs in the id property are honored only for reports ingested through the BrowserStack SDK or Test Reporting & Analytics. Reports uploaded through the Test Management CLI read id as a single identifier and link the test to one test case.
<testcase name="Complete a purchase on the demo site">
<properties>
<property name="id" value="TC-17538 TC-17539 TC-17540"/>
</properties>
</testcase>
Title-based tagging
Add the test case IDs at the start or end of the test title, separated by spaces. Test Management reads the IDs from the title and updates every matching test case, regardless of where the test case sits in your project’s folder structure.
const { test, expect } = require('@playwright/test');
test('completeCheckout TC-17538 TC-17539 TC-17540', async ({ page }) => {
await page.goto('https://www.bstackdemo.com');
// Add a product to the cart, fill in the shipping address, and confirm payment.
});
If the test also carries IDs from a @TCID_ tag, the SDK custom tag, or a report property, Test Management uses those and ignores the IDs in the title. It doesn’t combine the two sources.
Limits and rules
-
Separator: separate the IDs with a single space, for example
TC-1 TC-2 TC-3. -
ID format: use the full test case ID with its prefix, for example
TC-5848, not5848. - ID placement in titles: for title-based tagging, keep the IDs at the start or end of the title. Test Management doesn’t read IDs from the middle of a title.
- Non-existent IDs: if some test case IDs don’t match a test case in your project, Test Management skips those IDs. If none of the IDs match, Test Management creates a test case from the test name instead.
View results
After a successful test run, Test Management automatically imports and associates the results. Navigate to the Test Runs section in your Test Management project to view the mapped test case results.
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
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!