Skip to main content

Setting Test Statuses

What You'll Learn

  • How to use the JavaScript Executor to update the status of your test at the end of the session.
  • How to use the Sauce Labs REST API to update the status of your test after it has already completed.

Update Test Status in Session

You can use the Selenium JavaScript Executor to annotate your test in the @after hook. This is the ideal means of writing your tests to interpret the results as a pass/fail and update the status accordingly.

JavaScript Executor

The JavaScript Executer commands can only be run while the test is in session. Once the test is complete, the JavaScript Executor commands are no longer applicable and you must use the REST API to update the test.

Video: Setting Test Status to Pass Fail

Watch this video for a demonstration of using the Selenium JavaScript Executor to annotate your test result with a Passed/Failed status.

Code Examples

The annotation for calling the JavaScript Executor in your test differs slightly for each framework and language, which are provided in the following code snippet examples. Refer to our Sauce Labs Demonstration Code Repositories on GitHub for further information, and more context, on annotating your tests to record the pass/fail status.

  • JUnit 5
Test Reporting with JUnit 5 Test Watcher
loading...
  • TestNG
Test Reporting with TestNG
loading...

Updating Test Status After Completion

If you did not use the JavaScript Executor to update the status of your test as an assertion in the test code, you can still use the Sauce Labs REST API to update the test status.

What You'll Need

Call the update_jobs REST API and pass the parameter "passed" with a value of "true" or "false".

Update Test Status
curl PUT -X -u USERNAME:ACCESS_KEY \'https://saucelabs.com/rest/v1/USERNAME/jobs/JOB_ID' \
--header 'Content-Type: application/json' \
--data-raw '{
"data": {
"passed": "true"
}
}'

You can obtain the JOB_ID either by:

  • Collecting and storing the web driver SessionId for the test, which Sauce Labs uses as the JOB_ID
  • testFinding the Id value in the test's Metadata tab on Sauce Labs, as shown in the following figure
Test results metadata - JOB_ID