Set custom metadata in Test Observability
Learn how to set custom metadata in Test Observability.
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 Observability 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.
You can also filter tests using custom metadata.
Follow these steps to filter tests based on custom metadata:
- When viewing the Test listing, click the filter button.
- Scroll down and click Add in Custom fields filter.
- Select any key name.
- 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.
- Click Add Filter and Apply.
The tests get filtered based on the custom metadata filters you choose.
How to add custom metadata to tests
Currently, you can add custom metadata for Java and Python frameworks. We will be adding this feature to other frameworks soon.
Add custom metadata to Java tests
Test Observability supports custom metadata on Java test suites which uses the TestNG framework.
Add the following code to your Java tests to add custom metadata:
Import the BrowserStack library
import com.browserstack.v2.utils.BrowserStack;
Set custom metadata using the following method
BrowserStack.setCustomTag("keyName", "Value");
Example 1
BrowserStack.setCustomTag("environment", "staging");
Example 2
BrowserStack.setCustomTag("environment", "staging, preprod, production");
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 valueWinter
. Later in the test, you can overwrite the key with a value likeHoliday
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 likeRead
,Write
andUpdate
associated with it by passingRead
,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
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!