Skip to main content

AddTestProperty - Automation Command

Description

The addTestProperty command allows you to add custom properties to your automated tests. These properties serve as tags or identifiers, making it easier to search for test results later or analyze trends over time.

By using this command, you can enhance the ability to filter and categorize your test results based on dynamic criteria such as build numbers, environment variables, or other contextual information from your testing environment.

info

This automation command is supported for both Appium (Mobile Devices) & Selenium (Desktop Browsers).

Parameters

Parameter NameValueDescription
propertyStringThe name of the property that will appear in the report
valueStringThe value associated with the property, used for filtering or searching specific results

Code Example

The addTestProperty command can be executed using the executeScript function:

Java- driver.executeScript("seetest:client.addTestProperty", property, value);

Python-self.driver.execute_script("seetest:client.addTestProperty", message, status);

C#- driver.ExecuteScript("seetest:client.addTestProperty", message, status);

JavaScript- driver.executeScript("seetest:client.addTestProperty", message, status); |

Ruby- driver.execute_script("seetest:client.addTestProperty", message, status)

Practical Example

Adding custom properties to tests can significantly improve test management and analysis, especially when combined with other tools. For example, in a CI/CD pipeline like Jenkins, you can leverage built-in parameters such as the build ID or job name:

String Jenkins_Build_Number = System.getenv("CI_JOB_ID");

Imagine running a nightly Jenkins job that triggers hundreds of automated tests. You can programmatically fetch the ID of the executed job from Jenkins and then use the AddTestProperty command to associate this ID as a custom property for all tests in that particular job. This allows you to filter the results later based on the Jenkins build number.

if (System.getenv("CI_JOB_ID") != null) {
driver.executeScript("seetest:client.addTestProperty", "Jenkins_Build_Number", System.getenv("CI_JOB_ID"));
}

When viewing your test reports, you can filter results by this property. This makes it much easier to track the performance of tests across multiple builds.

info

The properties added via the addTestProperty command can also be leveraged using our Get Test Counts REST API. An example cURL based API call may look like this (Based on URL Encoding):

{{cloud_url}}/reporter/api/testView/{{test_view_id}}/summary?filter=%7B%22Jenkins_Build_Number%22%3A%229%22%7D When decoded, the query filter looks like this:

{"Jenkins_Build_Number":"9"}