---
title: "End the active test on a device session"
method: POST
path: "/sessions/{sessionId}/endTest"
tags: ["Test Results"]
---

# End the active test on a device session

`POST /sessions/{sessionId}/endTest`

## Request

- Base URL: `https://api.us-west-1.saucelabs.com/rdc/v2`
- URL: `https://api.us-west-1.saucelabs.com/rdc/v2/sessions/{sessionId}/endTest`
- Auth: HTTP basic
- TypeScript: <https://skmtc.dev/saucelabs/apis/real-device-access-api-reference/docs/sessions/:sessionId/endTest/post.ts> (a function with typed inputs; its response is checked against the schema)

Ends the test that is currently active on the session and reports its result. Any artifact recordings
started by [`startTest`](#operation/startTest) are stopped and collected. Collection happens asynchronously, so
the artifacts appear on the test shortly after the call returns.

Once the test is ended, the session is free to start the next one. The session itself stays active; closing
the session while a test is running ends that test automatically.

The request body is optional. Omit it, or omit `status`, and the test is stored without a pass/fail
result.

## Path parameters

- `sessionId` string, required

## Request body

- EndTestRequest: The result to store on the test. Optional — omit it to leave the result undefined.
  - `status` 'passed' | 'failed': The test result. Case insensitive. Omit to leave the result undefined.

## Response `200`

Test ended

- EndTestResponse
  - `jobId` string: The Sauce Labs job id of the test that was ended.
  - `status` string: The status stored on the test.

## Other responses

- `400`: Bad Request
- `401`: Not Authorized
- `404`: Not Found
- `409`: The test could not be started or ended in the session's current state. This covers: - `Test already active.` — a test is still running on the session; call `endTest` before starting another. The response carries the offending id in `activeTestId`. - `Test limit reached.` — the session already holds the maximum of 500 tests; start a new session to record more. - `No active test.` — `endTest` was called on a session that has no running test. - `Test is not ready.` — the test is still being created; retry shortly.

---

[API](https://skmtc.dev/saucelabs/apis/real-device-access-api-reference.md) - [All operations](https://skmtc.dev/saucelabs/apis/real-device-access-api-reference/llms.txt) - [OpenAPI document](https://skmtc.dev/saucelabs/apis/real-device-access-api-reference/revisions/f845a4b66e37?raw)
