From 8fa35997bbec6a95699dff195856e4221f90a0a0 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 +- 2 files changed, 4 insertions(+), 3 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,