From be63d7c6ed4f48943a8ca7000315eb9ac06ee81e Mon Sep 17 00:00:00 2001 From: sipayrt Date: Fri, 6 Sep 2024 16:56:04 +0300 Subject: [PATCH] fix(assertView): do not fall when trying to take screenshot of the viewport --- src/browser/client-scripts/index.js | 5 +++-- src/browser/commands/assert-view/index.js | 2 +- test/src/browser/commands/assert-view/index.js | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/browser/client-scripts/index.js b/src/browser/client-scripts/index.js index fd0f59fa..5cdc2bd5 100644 --- a/src/browser/client-scripts/index.js +++ b/src/browser/client-scripts/index.js @@ -112,12 +112,13 @@ function prepareScreenshotUnsafe(areas, opts) { } else if (allowViewportOverflow && viewPort.rectIntersects(rect)) { rect.overflowsTopBound(viewPort) && rect.recalculateHeight(viewPort); rect.overflowsLeftBound(viewPort) && rect.recalculateWidth(viewPort); - } else if (!captureElementFromTop && !viewPort.rectIntersects(rect)) { + } else if (!captureElementFromTop && !allowViewportOverflow && !viewPort.rectIntersects(rect)) { return { error: "OUTSIDE_OF_VIEWPORT", message: "Can not capture element, because it is outside of viewport. " + - 'Try to set "captureElementFromTop=true" to scroll to it before capture.' + 'Try to set "captureElementFromTop=true" to scroll to it before capture' + + ' or to set "allowViewportOverflow=true" to ignore viewport overflow error.' }; } diff --git a/src/browser/commands/assert-view/index.js b/src/browser/commands/assert-view/index.js index 2c0c22e1..93beba35 100644 --- a/src/browser/commands/assert-view/index.js +++ b/src/browser/commands/assert-view/index.js @@ -175,7 +175,7 @@ module.exports.default = browser => { }; const assertViewByViewport = async (state, opts) => { - opts = _.defaults(opts, { + opts = Object.assign(opts, { allowViewportOverflow: true, compositeImage: false, captureElementFromTop: false, diff --git a/test/src/browser/commands/assert-view/index.js b/test/src/browser/commands/assert-view/index.js index a3d34357..f222b197 100644 --- a/test/src/browser/commands/assert-view/index.js +++ b/test/src/browser/commands/assert-view/index.js @@ -283,7 +283,7 @@ describe("assertView command", () => { }); it('from "assertView" command even if it is set in "assertViewOpts"', async () => { - await fn(browser, null, null, { [option]: true }); + await fn(browser, null, "selector", { [option]: true }); assert.calledOnceWith( browser.prepareScreenshot, @@ -422,7 +422,7 @@ describe("assertView command", () => { }); const browser = await initBrowser_({ browser: stubBrowser_(config) }); - await fn(browser, null, null, { [option]: "value-3" }); + await fn(browser, null, "selector", { [option]: "value-3" }); assert.calledWithMatch(ScreenShooter.prototype.capture, sinon.match.any, { [option]: "value-3",