Skip to main content

SetReportStatus - Automation Command

Description

The setReportStatus command allows you to override the final report status. This command is particularly useful for ensuring that the final status of the test report accurately reflects the actual test outcome.

info

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

Parameters

Parameter NameValueDescription
messageStringA custom message to be displayed in the final report, providing more context or additional details about the test outcome
statusStringSpecifies the final status of the test. You can pass one of the following values:
Failed, Skipped, Passed
stacktrace (Optional)StringIf the test fails, you can pass a stack trace to be included in the report. This helps in diagnosing the failure by providing detailed error information

Code Example

The setReportStatus command can be executed using the executeScript function:

Java- driver.executeScript("seetest:client.setReportStatus", status, message);

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

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

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

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

Practical Example

In a typical scenario, you may wrap up the end of a test execution like this:

@AfterMethod
public void tearDown(ITestResult result) {

if (result.getStatus() == ITestResult.SUCCESS) {
logger("Test Passed");
} else if (result.getStatus() == ITestResult.FAILURE) {
logger("Test Failed");
} else if (result.getStatus() == ITestResult.SKIP) {
logger("Test Skipped");
}

driver.quit();
}

When enhanced with the setReportStatus command, it would look like this:

@AfterMethod
public void tearDown(ITestResult result) {

if (result.getStatus() == ITestResult.SUCCESS) {
logger("Test Passed");
driver.executeScript("seetest:client.setReportStatus", "Passed", "Test Passed");
} else if (result.getStatus() == ITestResult.FAILURE) {
logger("Test Failed");
driver.executeScript("seetest:client.setReportStatus", "Failed", "Test Failed", String.valueOf(result.getThrowable()));
} else if (result.getStatus() == ITestResult.SKIP) {
logger("Test Skipped");
driver.executeScript("seetest:client.setReportStatus", "Skipped", "Test Skipped");
}

driver.quit();
}

Depending on the status, the corresponding test result will be reflected in the generated report: