Skip to main content
No Result Found

Set custom metadata in Test Reporting & Analytics

Learn how to set custom metadata in Test Reporting & Analytics.

In addition to using build tags and test tags, you might want to assign key-value pairs to your tests for advanced categorization. Such custom metadata unlocks advanced use cases with Test Reporting & Analytics dashboards.

For example, you can set environment as a metadata category and have dev, staging, preprod, and prod as the possible values. Team-name could be another metadata category with possible values teamA, teamB, and teamC. Such key-value pairs provide a flexible option for you to categorize your tests the way you want them.

You can view custom metadata under the Info tab in the Timeline Debugging view of a test.

A set of key value pairs listed under custom fields in Info tab

You can also filter tests using custom metadata.

Follow these steps to filter tests based on custom metadata:

  1. When viewing the Test listing, click the filter button. A filter icon is highlighted on the test listing page of test Observability
  2. Scroll down and click Add in Custom fields filter.
    A filter titled Custom fields with a clickable button named Add
  3. Select any key name.
    Key names listed one after another
  4. Select the key values you want to include. You can use the search option to find all values available. Note that you can select multiple key values here.
    Key value selected in checkbox listed one after another
  5. Click Add Filter and Apply.

The tests get filtered based on the custom metadata filters you choose.

How to add custom metadata to tests

Select one of the following options for instructions to add custom metadata:

You can use console logs to add custom metadata. The exact syntax for console.log could be different for different languages.

We recommend to add metadata via SDK if it’s available for your framework.

Add custom metadata to tests using console logs

Use the following command to set custom metadata using console logs.

Add custom metadata
Copy icon Copy

Java Example

Java
Copy icon Copy

Python Example

Python
Copy icon Copy

Currently, you can add custom metadata for Java and Python frameworks. We will be adding this feature to other frameworks soon.

If you use other frameworks, you can use Console Logs until your framework is supported.

Add custom metadata to tests

Test Reporting & Analytics supports custom metadata on Java test suites which uses the TestNG framework.

Step 1. Import the BrowserStack library

import com.browserstack.v2.utils.BrowserStack; 

Step 2. Set custom metadata using the following method

BrowserStack.setCustomTag("keyName", "Value");

A few examples are given below:

Java Example 1
BrowserStack.setCustomTag("environment", "staging");
Java Example 2
BrowserStack.setCustomTag("environment", "staging, preprod, production");

Test Reporting & Analytics supports custom metadata on Python test suites which uses the Pytest framework.

Set custom metadata using the following method

driver.set_custom_tag("keyName", "keyValue1, keyValue2, keyValueN")
Python Example 1
driver.set_custom_tag("environment", "staging")
Python Example 2
driver.set_custom_tag("environment", "staging, preprod, production")

You can add custom metadata on your Allure or JUnit XML reports you want to upload to Test Reporting & Analytics.

For Allure and JUnit XML uploads, the instructions are different. Please select from the following tabs:

Add custom metadata to Allure tests

The syntax to add custom metadata to your Allure tests is different for each framework. You can refer to the Allure docs for your framework.

Example for Java framework

The following sample syntax is used for Java framework:

Allure.label("locale", "eu");
Allure.label("language", "german");

Add custom metadata to JUnit XML reports

You can use the <property> tag in JUnit XML reports to add custom metadata.

Example using property tag

The following sample syntax is used for JUnit XML reports:

<property name="locale" value="eu"/>
<property name="language" value="german"/>

Alternatively, you can also use <system-out> tag to add custom metadata in JUnit XML reports.

Example using system-out tag

<system-out>
    [[PROPERTY|locale=eu]]
    [[PROPERTY|language=german]]
</system-out>

Principles of custom metadata

  • Custom metadata keys can be dynamically updated throughout a test execution. This allows you to reflect changing information or states within your test case.

    For example, you could initialize a key named Campaign with the value Winter. Later in the test, you can overwrite the key with a value like Holiday by using the same method you used to set the original key. The key will be automatically overwritten with the latest assigned value. This mechanism ensures that your metadata always represents the most current state or information relevant to your test.

  • You can assign multiple values to a single metadata key by using a comma-separated string. This allows you to associate a test with several categories, modules, or attributes simultaneously.

    For example, you could set a key like User Permissions and have multiple values like Read, Write and Update associated with it by passing Read,Write, Update, while setting the key.

  • Key values are strings with a maximum of 512 characters.

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