Skip to content

fix: snapshot fails with ClassCastException on decorated drivers since 1.0.7 - #67

Open
shrinishLT wants to merge 1 commit into
LambdaTest:stagefrom
shrinishLT:fix-decorated-driver-session-id
Open

shrinishLT wants to merge 1 commit into
LambdaTest:stagefrom
shrinishLT:fix-decorated-driver-session-id

Conversation

@shrinishLT

Copy link
Copy Markdown

Problem

A customer (org 486308) reported that every SDK version after 1.0.6 fails with only [lambdatest-java-sdk] SmartUI snapshot failed in the logs, while 1.0.6 works. Their CLI debug log shows, per snapshot, a /healthcheck and a /domserializer request and then no /snapshot POST; the build finalises with "No snapshots processed".

Their driver is Decorated {RemoteWebDriver: …}, i.e. wrapped with Selenium's EventFiringDecorator. Since #13 (1.0.7, 13 March 2025) smartuiSnapshot does ((RemoteWebDriver) driver).getSessionId() inside the try block. The decorated proxy implements JavascriptExecutor (so the earlier check passes) and WrapsDriver, but is not a RemoteWebDriver, so the cast throws ClassCastException. The catch block prints a fixed string and returns, so nothing else is logged and no debug flag helps.

Reproduced against Selenium 4.27.0: a decorated RemoteWebDriver reports instanceof RemoteWebDriver: false, instanceof WrapsDriver: true, and the cast throws. smartuiResults has the same cast.

Fix

  • SmartUIUtil.unwrapRemoteWebDriver(WebDriver): follows WrapsDriver.getWrappedDriver() / Decorated.getOriginal() (bounded) until a RemoteWebDriver is found, else null.
  • SmartUISnapshot: uses the helper; if no RemoteWebDriver is found the snapshot is sent without sessionId (logged at FINE) instead of failing.
  • SmartUIResults: uses the helper; throws the same IllegalArgumentException as before only when nothing to unwrap.
  • The snapshot catch block now logs the exception (SmartUI snapshot failed for '<name>': <exception>).

Out of scope: the (RemoteWebDriver) driver casts in ElementBoundingBoxUtil and FullPageScreenshotUtil (app-screenshot path) have the same shape and can reuse the helper in a follow-up.

Verification

  • mvn compile clean.
  • Scratch check with EventFiringDecorator on a RemoteWebDriver instance: old cast throws ClassCastException; unwrapRemoteWebDriver returns the original instance.

🤖 Generated with Claude Code

Since 1.0.7 (LambdaTest#13) smartuiSnapshot casts the driver to RemoteWebDriver to read the
session id. A driver wrapped with Selenium's EventFiringDecorator is a proxy that
implements JavascriptExecutor and WrapsDriver but is not a RemoteWebDriver, so the
cast throws ClassCastException inside the try block and the only output is
"SmartUI snapshot failed". No snapshot is ever posted to the CLI.

Unwrap through WrapsDriver / Decorated until a RemoteWebDriver appears; send the
snapshot without a session id when none is found. smartuiResults uses the same
helper. The catch block now logs the exception so the next failure explains itself.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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