fix: snapshot fails with ClassCastException on decorated drivers since 1.0.7 - #67
Open
shrinishLT wants to merge 1 commit into
Open
shrinishLT wants to merge 1 commit into
shrinishLT wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A customer (org 486308) reported that every SDK version after 1.0.6 fails with only
[lambdatest-java-sdk] SmartUI snapshot failedin the logs, while 1.0.6 works. Their CLI debug log shows, per snapshot, a/healthcheckand a/domserializerrequest and then no/snapshotPOST; the build finalises with "No snapshots processed".Their driver is
Decorated {RemoteWebDriver: …}, i.e. wrapped with Selenium'sEventFiringDecorator. Since #13 (1.0.7, 13 March 2025)smartuiSnapshotdoes((RemoteWebDriver) driver).getSessionId()inside the try block. The decorated proxy implementsJavascriptExecutor(so the earlier check passes) andWrapsDriver, but is not aRemoteWebDriver, so the cast throwsClassCastException. 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
RemoteWebDriverreportsinstanceof RemoteWebDriver: false,instanceof WrapsDriver: true, and the cast throws.smartuiResultshas the same cast.Fix
SmartUIUtil.unwrapRemoteWebDriver(WebDriver): followsWrapsDriver.getWrappedDriver()/Decorated.getOriginal()(bounded) until aRemoteWebDriveris found, elsenull.SmartUISnapshot: uses the helper; if noRemoteWebDriveris found the snapshot is sent withoutsessionId(logged at FINE) instead of failing.SmartUIResults: uses the helper; throws the sameIllegalArgumentExceptionas before only when nothing to unwrap.SmartUI snapshot failed for '<name>': <exception>).Out of scope: the
(RemoteWebDriver) drivercasts inElementBoundingBoxUtilandFullPageScreenshotUtil(app-screenshot path) have the same shape and can reuse the helper in a follow-up.Verification
mvn compileclean.EventFiringDecoratoron aRemoteWebDriverinstance: old cast throwsClassCastException;unwrapRemoteWebDriverreturns the original instance.🤖 Generated with Claude Code