In Appium, what does DELETE /session/:sessionId actually tear down on the device?
answer
- it unwinds the driver, not the device
- the driver's own footprint only
- device settings outlive the session
- frees the slot, not the state
basics
~20 sIt ends the driver's own session: the conversation with the device-side agent, the per-session host plumbing, and the server slot the session held. It does not uninstall the app or undo device state the run changed.
solid answer
~50 s`DELETE /session/:sessionId` is the W3C command a client binding sends when your code quits the driver, and its scope is the **driver's footprint, not your test's**. The driver ends the session it holds with its device-side agent — the helper server the UiAutomator2 driver started on Android, the WebDriverAgent session on Apple platforms — releases the host-side plumbing and per-session ports it opened, and frees the server slot so another session can take the device. What survives is everything your run changed on the device: permissions it granted, a simulated location it set, connectivity or system settings it altered, files it wrote. Whether the app under test is removed or its data cleared is decided by the session's reset capabilities, not by the delete. On a pooled device that means a suite may only assume what it seeds for itself.
go deeper
Know that quitting the driver sends DELETE /session/:sessionId, and that it ends the automation session rather than uninstalling the app or resetting the device you were driving.
Explain what the driver unwinds — its agent session, its per-session ports, the server slot — and name concrete things that plainly survive, such as a permission the run granted.
Show how you keep pooled devices usable: say which state a suite must seed for itself because the previous session's delete never restored it, and how you find out what was left.
Own the contract between suites that share hardware, deciding what a run may assume about a device it did not provision and who is accountable when that assumption breaks.
## The request, and what sends it `DELETE /session/:sessionId` is the W3C WebDriver command that ends a session. It carries no body, it names the session in its URL, and in practice you never type it — a client binding sends it when your code quits the driver. Its job is narrower than most suites assume, and the gap between what it does and what people believe it does is exactly where "the device was dirty" bugs come from. ## What the driver unwinds The delete ends **the driver's session**, and the driver undoes the setup it performed during the handshake: - **The session with the device-side agent.** On Android the UiAutomator2 driver ends its conversation with the helper server it started on the device; on Apple platforms the XCUITest driver ends the WebDriverAgent session it was driving. - **The host-side plumbing opened for this session**, including the per-session ports the session was given. - **The server-side slot**, so a new session can be created against the same device. That list is the driver's own footprint. Notice what is not on it: anything your test did. ## What survives the delete | What survives | Why it survives | |---|---| | The app under test's installation | The delete says nothing about the app; the session's reset capabilities decide whether a build is replaced or its data cleared | | Permissions the run granted | A granted permission is device state held by the operating system, not session state held by the driver | | A simulated location, altered connectivity, changed system settings | Same reason — the driver changed the device, and it does not journal those changes in order to reverse them | | The agent on the device | Nothing in the delete promises that WebDriverAgent or the Android helper packages are uninstalled afterwards | | Files the run produced | Screenshots, recordings and pulled logs stay wherever they were written | ## Why Appium cannot simply roll the device back To restore a device, something would have to record every change made during the session and know how to reverse each one — including changes the app under test made on its own, which no driver observed. That is not a session's job and no driver claims it. The delete promises only that the automation session is over and that the resources the driver itself acquired are released. ## The device is shared even when the session is not Picture the birdwatching sightings suite on a pooled phone. It grants location permission so the sightings map can centre itself, sets a simulated location at a nature reserve, records a video of a tricky scroll, then quits. The delete returns the phone to the pool. The next suite gets a phone with location permission already granted for that app and a simulated location still applied. Nothing has failed. The second suite simply did not start where it assumed it would — and if one of its cases depends on being *asked* for permission, it fails in a way that reads like a product bug. The discipline that follows is short: 1. **A session may only assume what it seeds itself.** If a case needs a permission denied, it seeds that state; if it needs a real location, it clears the simulated one. 2. **If a case needs a genuinely fresh app, the session's capabilities say so.** That decision lives in the capabilities the handshake sent, not in how the previous session ended. 3. **Treat the device as shared inventory.** Write down what your run leaves behind, so the next team is not debugging your side effects as if they were their own. ## When the delete never arrives If the client process dies — killed by a pipeline timeout, crashed, or simply stopped — no delete is sent, and the server keeps holding that session until its idle budget expires and the server ends it. The device comes back either way. It comes back later, and the run learns nothing on the way out. ## Reading a delete in a log The ending of a session is one of the more informative lines in a server log, because there are only a few shapes it can take: - A clean run shows the delete arriving right after the last command. - A run with no delete at all was killed rather than finished — look at the runner, not at the app. - A delete arriving long after the last command means the session sat idle in that gap, which is device time nobody used and is worth explaining. - A delete that fails because the session id is unknown means something already ended that session before the client got there. None of those four is a device problem, and telling them apart takes seconds once you hold on to the one fact that governs the command: its scope is the driver, and nothing else.
- After the delete, is the birdwatching app still installed on the device?Normally yes. The delete ends the automation session, not the app's presence. Whether the build is removed, replaced, or has its data cleared is decided by the session's reset capabilities; the delete itself makes no promise about the app either way.
- Two suites share one phone. What does a delete actually hand the second suite?The driver slot, the device-side agent and the per-session ports — enough for it to create its own session. It does not hand over a clean device: granted permissions, a simulated location and altered connectivity all survive, so the second suite must seed whatever it depends on.
saying these in an interview costs you the question
- Believes the delete uninstalls the app under test
- Expects DELETE to restore permissions and simulated location
- Thinks the delete stops the Appium server process itself
- Assumes the device-side agent is removed on every delete
- Treats a shared device as clean because a session ended