Skip to content

fix(selenium-devtools): quiet teardown screenshots and keep the mobile demo open in live mode - #447

Merged
vishnuv688 merged 2 commits into
mainfrom
fix/selenium-mobile-teardown
Oct 23, 2026
Merged

vishnuv688 merged 2 commits into
mainfrom
fix/selenium-mobile-teardown

Conversation

@vishnuv688

Copy link
Copy Markdown
Member

What & why

Two problems found while checking the Selenium adapter against Appium on an Android emulator.

Screenshot warnings at quit. Each command row's screenshot is taken in the background, and the driver patcher does not await a command's capture. The last commands' screenshots were therefore still in flight when driver.quit() stopped the session under them, and on Appium each one logged a warning:

WARN @wdio/selenium-devtools:SessionCapturer: [screenshot] Failed: Could not proxy command to the remote server. Original error: socket hang up
WARN @wdio/selenium-devtools:SessionCapturer: [screenshot] Failed: 'GET /screenshot' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed)

Now:

  • The Selenium SessionCapturer tracks each command's capture and its row screenshot, dropping each one as it settles.
  • Before quit, while the session is still alive, onDriverEnd waits for that work, including any screenshot a settling capture queues, under core's 5 s PENDING_SETTLE_TIMEOUT_MS.
  • If the wait times out it logs one warning and forgets the stuck work, so a capture that never settles cannot slow every later quit.
  • A screenshot that still reaches the driver being quit is skipped and logged at debug level. A new driver is not affected.
  • A failing command capture is now logged instead of being left as an unhandled rejection.

The Selenium mobile demo closed before you could use the dashboard. example:mobile passed mocha --exit, which force-exits when the tests end, past the timer that keeps the process alive until the dashboard is closed. Dropped; the desktop Selenium examples already run without it.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

Packages touched

  • shared (types and contracts)
  • core (framework-agnostic capture/reporting)
  • elements (published element/snapshot API — @wdio/elements)
  • service (WebdriverIO adapter)
  • nightwatch-devtools (Nightwatch adapter)
  • selenium-devtools (Selenium adapter)
  • selenium-devtools-py (Selenium Python adapter)
  • backend (server)
  • app (UI)
  • script (page-injected runtime)
  • trace (Trace mode)

Notes for reviewers

  • core only exports what it already had: settlePending and PENDING_SETTLE_TIMEOUT_MS from trace-finalizer.ts, so the adapter reuses the same bounded wait and ceiling rather than a second copy. Its test now imports the constant instead of mirroring it.
  • The in-flight work is tracked in its own set on the capturer, not in the existing snapshotCaptures list. That list lasts the whole run and is what per-test slices wait on, so putting row screenshots in it would make one test's late screenshot hold up the next test's slice, and one stuck capture would add 5 s to every later quit.
  • Only Selenium needs this: the WDIO service awaits its row screenshots inline, and Nightwatch's teardown noise comes from its screencast poller, not from this race.
  • pnpm test: 2822 passed. pnpm lint: 0 errors. pnpm typecheck and pnpm build clean. The new tests in selenium-devtools/tests/teardown-settle.test.ts fail without the change.
  • Verified on an Android emulator (Android 16) with Appium 3: DEVTOOLS_MODE=live pnpm demo:selenium:mobile keeps the dashboard open until it is closed, pnpm demo:selenium:mobile (trace mode) exits on its own, and neither logs a [screenshot] Failed line.

Screenshots / recordings

n/a (no UI change)

🤖 Generated with Claude Code

…r quits

Row screenshots and command captures run unawaited, so the last commands'
captures were still in flight when quit stopped the session under them, and
on Appium each one logged a [screenshot] Failed warning.
mocha --exit force-exits when the tests end, past the timer that keeps the
process alive until the dashboard is closed.
@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR waits for background command captures and row screenshots before Selenium quits, with a shared five-second limit.

  • Driver quit waits for Selenium capture work before it ends the session.
  • The mobile demo stays open until you close the live dashboard.

No actionable issues were found. Tests were inspected, not run.

Diagram

sequenceDiagram
  participant Test
  participant Plugin
  participant Capturer
  participant Driver
  Test->>Plugin: Command completes
  Plugin->>Capturer: Track command capture
  Capturer->>Driver: Take row screenshot
  Test->>Plugin: Quit requested
  Plugin->>Capturer: settleBeforeQuit()
  Note over Capturer: Wait for tracked work, up to five seconds
  Capturer->>Capturer: Mark driver as ending
  Plugin->>Driver: Drain remaining page data
  Plugin->>Driver: Quit session
Loading

Reviews (1) · Last reviewed commit: "fix(examples): keep the Selenium mobile ..." · Reviewed by Greptile

@vishnuv688
vishnuv688 merged commit fdb6026 into main Oct 23, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant