Set name and status of Appium tests
Learn how to set the name and status of Appium tests running on BrowserStack App Automate using JavaScript executors.
BrowserStack App Automate provides custom JavaScript executor methods that let you set the name and status for a test while it is running. This helps you debug your test cases quickly. Alternatively, you can set the test name and status using the REST API.
Set a test name
Use setSessionName to assign a name to your test. Naming a test makes it easier to locate on the App Automate dashboard.
The argument passed in the JavaScript executor method for setting a name is name, and it accepts a value in string datatype.
Use the following syntax to set a name for the test in different languages:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {\"action\": \"setSessionName\", \"arguments\": {\"name\": \"<test-name>\"}}");
driver.execute('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"<test-name>"}}');
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {\"action\": \"setSessionName\", \"arguments\": {\"name\":\"<test-name>\"}}");
$driver->executeScript('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"<test-name>"}}' );
driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"<test-name>"}}')
driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"<test-name>"}}')
If you use the BrowserStack SDK, the SDK automatically manages the setSessionName and setSessionStatus methods. However, this is applicable only for language frameworks. For vanilla implementations, you must manually set the session name and status using the JavaScript executor.
Set the test status
Use setSessionStatus to set the status of your test as passed or failed, along with the reason for that status. For vanilla implementations, BrowserStack infrastructure is unaware whether your test assertions passed or failed, so you must set the status explicitly based on your test logic.
The arguments passed in the JavaScript executor method for setting the status and its corresponding reason are status and reason:
-
statusaccepts eitherpassedorfailedas the value. -
reasonaccepts a value in string datatype.
Use the following syntax to set the status of the test in different languages:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"<passed/failed>\", \"reason\": \"<reason>\"}}");
driver.execute('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"<passed/failed>","reason": "<reason>"}}');
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\":\"<passed/failed>\", \"reason\": \" <reason> \"}}");
$driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"<passed/failed>", "reason": "<reason>"}}' );
driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"<passed/failed>", "reason": "<reason>"}}')
caps["javascriptEnabled"] = "true" #Additionally, include this capability for JavaScript Executors to work
driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"<passed/failed>", "reason": "<reason>"}}')
For a complete sample test script, and to mark a test’s status after it finishes running using the REST API, see the mark Appium tests as passed or failed guide.
Related topics
Check the list of JavaScript executors that BrowserStack App Automate offers.
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!