Mark tests as passed or failed
Mark your Selenium & Playwright tests as passed or failed from within the test script or after the test has been completed.
Use BrowserStack SDK to run your Selenium and Playwright tests. The SDK will auto-identify test status based on configured assertions and mark the tests as passed
or failed
to simplify your debugging on the Builds Dashboard.
This guide will provide detailed information on how to mark your tests as passed
or failed
.
Once you have completed your test run, you will be able to view the status of your tests on the Builds Dashboard as shown below:
You can mark the status of your test along with the reason using the following methods:
Mark test status from the test script using Javascript Executor
Your test script can contain many assertions. You may choose to mark the status of the test based on these assertions using Javascript Executor.
Used the following arguments in the JavaScript method to set the status and the corresponding reason for the test:
Argument | Description | Accepted values |
---|---|---|
status |
Status of the test | A string. passed or failed
|
reason |
Test Pass or Fail reason | A string. |
Use the following code snippet to set the status of the test:
final JavascriptExecutor jse = (JavascriptExecutor) driver;
JSONObject executorObject = new JSONObject();
JSONObject argumentsObject = new JSONObject();
argumentsObject.put("status", "<passed/failed>");
argumentsObject.put("reason", "<reason>");
executorObject.put("action", "setSessionStatus");
executorObject.put("arguments", argumentsObject);
jse.executeScript(String.format("browserstack_executor: %s", executorObject));
const executorConfig = {
"action": "setSessionStatus",
"arguments": {
"status": "<passed/failed>",
"reason": "<reason>"
}
};
await driver.executeScript('browserstack_executor: ' + JSON.stringify(executorConfig), []);
using System.Text.Json.Nodes;
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
JsonObject executorObject = new JsonObject();
JsonObject argumentsObject = new JsonObject();
argumentsObject.Add("status", "<passed/failed>");
argumentsObject.Add("reason", "<reason>");
executorObject.Add("action", "setSessionStatus");
executorObject.Add("arguments", argumentsObject);
jse.ExecuteScript("browserstack_executor: " + executorObject.ToString());
$web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"<passed/failed>", "reason": "<reason>"}}' );
import json
executor_object = {
'action': 'setSessionStatus',
'arguments': {
'status': "<passed/failed>",
'reason': "<reason>"
}
}
browserstack_executor = 'browserstack_executor: {}'.format(json.dumps(executor_object))
driver.execute_script(browserstack_executor)
executor_config = {
action: "setSessionStatus",
arguments: {
status: "<passed/failed>",
reason: "<reason>"
}
}
json = executor_config.to_json
script = 'browserstack_executor: ' + json
driver.execute_script(script)
Mark test status after test completion using REST API
You can also mark your test as as passed
or failed
on BrowserStack after the test script has completed its run, however, you will not be able to follow the above-mentioned approach.
In such cases, it is recommended that you mark your tests using our REST API endpoint to mark the status of a test as passed
or failed
. You can also provide a reason to explain why you’re marking a test as failed (or passed).
Use the following arguments in the REST API call to set the test status, and the corresponding reason:
Argument | Description | Accepted values |
---|---|---|
status |
Status of the test | A string. passed or failed
|
reason |
Test Pass or Fail reason | A string. |
The following REST API can be used to achieve this:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -X PATCH -H "Content-Type: application/json" \
-d "{\"status\":\"<new-status>\", \"reason\":\"<reason text>\"}" \
https://api.browserstack.com/automate-turboscale/v1/sessions/<session-id>.json
Read more about how to fetch the <session-id>
of your session which you want to mark and use it in the REST API call.
Related topics
Check this page for a list of various JavaScript Executors supported on Automate TurboScale.
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!