Skip to main content

Test Case ID Tagging

Learn about Test Case ID tagging for automated test cases.

The tagged test case results are recorded in the test run of Test Management whenever the automation suite is run. These test cases can be both manual or automated type in the Test Management repository.

Test case ID tagging is currently supported only for JUNIT-XML-based reports with TestNG and PyTest.

Integrate test case ID tagging with test suites

Prerequisite

Ensure you have a project and some test cases created in your Test Management account.

Add Test Case ID in the test suite

You can add a test case ID to your test suite with Reporter.log("[[PROPERTY|id=<test-case-id>]]\n", true); in TestNG, record_property("id", "<test-case-id>") in PyTest, and console.log(`[[PROPERTY|id=${id}]]`); in Playwright.

Following are the sample code snippets to add test case ID in the test suites.

package com.browserstack;

import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;

public class BStackDemoTest {
  @Test
  public void testUpdateUserEmail() {
    Reporter.log("[[PROPERTY|id=TC-1]]\n", true);
    // [..]
  }

  @Test
  public void addToCart() {
    Reporter.log("[[PROPERTY|id=TC-2]]\n", true);
    // [..]
  }
} 
import pytest

def test_div_zero_exception(record_property):
    """
    pytest.raises can assert that exceptions are raised (catching them)
    """
    with pytest.raises(ZeroDivisionError):
        record_property("id", "TC-52628")
        x = 1 / 0

def test_keyerror_details(record_property):
    """
    The raised exception can be referenced, and further inspected (or asserted)
    """
    record_property("id", "TC-52629")
    my_map = {"foo": "bar"}

    with pytest.raises(KeyError) as ke:
        baz = my_map["baz"]

    # Our KeyError should reference the missing key, "baz"
    assert "baz" in str(ke)

def test_approximate_matches(record_property):
    """
    pytest.approx can be used to assert "approximate" numerical equality
    (compare to "assertAlmostEqual" in unittest.TestCase)
    """
    record_property("id", "TC-52630")
    assert 0.1 + 0.2 == pytest.approx(0.3)
// Import the necessary Playwright testing library components
const { test, expect } = require('@playwright/test');

test.describe('Playwright Demo Tests', () => {
  test('testUpdateUserEmail', async ({ page }) => {
    console.log(`[[PROPERTY|id=TC-1]]`); // Add log test case ID

    // Your test code here, e.g., navigating to a page, interacting with elements, etc.
    await page.goto('https://example.com');
    // Assertions to verify test case, e.g.:
    // await expect(page).toHaveURL('https://example.com/updated');
  });

  test('addToCart', async ({ page }) => {
    console.log(`[[PROPERTY|id=TC-2]]`); // Add log test case ID

    // Your test code for adding an item to the cart
    await page.goto('https://example.com');
    // Additional actions and assertions
  });
}); 

Execute the test suite

Run your test suite using one of the following.

  1. CI/CD pipeline using Azure DevOps or Jenkins.
  2. CLI.

Reports

Following are the sample test run reports.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by org.testng.reporters.JUnitReportReporter -->
<testsuite hostname="Sh*****" failures="0" tests="2" name="com.browserstack.BStackDemoTest" time="0.006" errors="0" timestamp="2023-04-20T10:46:28 IST" skipped="0">
   <testcase classname="com.browserstack.BStackDemoTest" name="testUpdateUserEmail" time="0.000" />
   <system-out><![CDATA[[[PROPERTY|id=TC-1]]]]></system-out>
   <testcase classname="com.browserstack.BStackDemoTest" name="addToCart" time="0.006" />
   <system-out><![CDATA[[[PROPERTY|id=TC-2]]]]></system-out>
</testsuite>
<!-- com.browserstack.BStackDemoTest -->
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
   <testsuite name="pytest" errors="0" failures="0" skipped="0" tests="7" time="0.017" timestamp="2023-04-18T18:10:07.535667" hostname="Sh*****">
      <testcase classname="00_empty_test" name="test_empty" time="0.000" />
      <testcase classname="01_basic_test" name="test_example" time="0.000" />
      <testcase classname="02_special_assertions_test" name="test_div_zero_exception" time="0.000">
         <properties>
            <property name="id" value="TC-52628" />
         </properties>
      </testcase>
      <testcase classname="02_special_assertions_test" name="test_keyerror_details" time="0.000">
         <properties>
            <property name="id" value="TC-52629" />
         </properties>
      </testcase>
      <testcase classname="02_special_assertions_test" name="test_approximate_matches" time="0.000">
         <properties>
            <property name="id" value="TC-52630" />
         </properties>
      </testcase>
      <testcase classname="03_simple_fixture_test" name="test_with_local_fixture" time="0.000" />
      <testcase classname="03_simple_fixture_test" name="test_with_global_fixture" time="0.000" />
   </testsuite>
</testsuites>
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="Playwright Demo Tests" tests="2">
  <testcase name="testUpdateUserEmail" classname="Playwright Demo Tests" time="2.345">
    <system-out>
      <![CDATA[[[PROPERTY|id=TC-1]]]>
    </system-out>
  </testcase>
  <testcase name="addToCart" classname="Playwright Demo Tests" time="1.567">
    <system-out>
      <![CDATA[[[PROPERTY|id=TC-2]]]>
    </system-out>
  </testcase>
</testsuite>

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