webdriverio session deleted error: how to fix
Fixes WebdriverIO 'session deleted' errors from timeouts and crashes. Use when commands fail because the session is gone. Not for launch failures.
TL;DR
The session ended while commands were still queued: the driver timed out, crashed, or a previous command killed it. Find which command ended the session, fix that, and keep sessions alive for the test duration.
Error
Error: A session is either terminated or not startedSteps
- Look at the last command before the failure in the logs. Expected: the session-killer identified.
- Common killer: a navigation that crashed the tab, or a
browser.close()in a helper. Fix or remove it. Expected: session survives. - Raise driver timeouts if the session idles out during long waits. Expected: no idle timeout.
- Check for parallel tests sharing one session; give each test its own. Expected: no cross-test kills.
- Re-run. Expected: session lasts the whole test.
When to use
session deleted/terminatedmid-test.- After crashes or long idle waits.
When not to use
- Session never starts (launch issue).
- Grid queue timeouts (infrastructure).
Tool compatibility
- WebdriverIO 8.x; any driver.
Variant phrasings
WebdriverIO session terminated
Same event; find the killer command.
No active session in WebdriverIO
The session ended before the command ran.
Why it happens
Sessions are stateful and fragile. Anything that kills the browser or times out the driver ends them, and queued commands then fail.
Edge cases
browser.reloadSession()recovers but loses state; prefer not needing it.- Mobile sessions are slower to establish; timeouts need raising there first.
- After hooks that close the session can race the last command.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstiVKKpPk2pQ6UhvAGtymwQ
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.