Repository navigation
fix: scroll back to position 0 after an element screenshot - #1271
Open
theluckystrike wants to merge 1 commit into
Open
theluckystrike wants to merge 1 commit into
theluckystrike wants to merge 1 commit into
Conversation
With autoElementScroll enabled, takeElementScreenshot scrolls the element into view and then restores the old scroll position. The restore in packages/image-comparison-core/src/methods/takeElementScreenshots.ts was guarded by `options.autoElementScroll && currentPosition`, so a start position of 0 counted as missing and the page stayed scrolled. A later checkScreen then captured a scrolled page (webdriverio#1229). The guard is now `typeof currentPosition === 'number'` in all three paths (BiDi document origin, BiDi viewport origin, WebDriver classic). An undefined result still skips the restore. The scrollToPosition calls in screenshots.ts have no truthiness guard, so they stay as they are. One new unit test per path starts at position 0 and expects scrollToPosition with 0. A patch changeset covers @wdio/image-comparison-core. Tests I ran on macOS with Node 25.9.0 and pnpm 11.28.2 ``` $ npx vitest --run packages/image-comparison-core/src/methods/takeElementScreenshots.test.ts base source 187e076 Tests 3 failed | 25 passed (28) this commit Tests 28 passed (28) $ pnpm run build exit 0 $ pnpm run test:lint exit 0 $ pnpm run test:types exit 0 $ pnpm run test:unit Tests 1 failed | 1071 passed (1072) the failure is processDiffPixels.test.ts "should handle maximum diff pixels threshold" (5000 ms timeout under load), unrelated; rerun alone Tests 10 passed (10) ``` End to end with the reporter's long.html and spec, headless Chrome 155 and @wdio/visual-service from this workspace (webdriverio 10.0.0) ``` base 187e076 E2E start 0: after checkElement 1206 E2E start 100: after checkElement 100 this commit E2E start 0: after checkElement 0 E2E start 100: after checkElement 100 ``` Not run are the cloud provider suites and test.local.chrome.v10.
🦋 Changeset detectedLatest commit: 45f1d88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This branch has not been deployed
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.
Fixes #1229
checkElement(),saveElement()andtoMatchElementSnapshot()withautoElementScroll(the default) scroll the element into view and then restore the old position. The restore inpackages/image-comparison-core/src/methods/takeElementScreenshots.tscheckedoptions.autoElementScroll && currentPosition, so a page at the top (scrollY0) was never scrolled back. A latercheckScreen()then captured a scrolled page.The three restore guards (BiDi document origin, BiDi viewport origin, WebDriver classic) now check
typeof currentPosition === 'number'. An undefined result still skips the restore.screenshots.tsrestoresscrollYwithout a truthiness check, so it stays unchanged. A patch changeset covers@wdio/image-comparison-core.Tests I ran on macOS, Node 25.9.0, pnpm 11.28.2
End to end with the reporter's
long.htmland spec, headless Chrome 155,@wdio/visual-servicebuilt from this workspaceThe cloud provider suites and
test.local.chrome.v10were not run.