Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(assertView): do not fall when trying to take screenshot of the vi… #1010

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/browser/client-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/commands/assert-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/src/browser/commands/assert-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
Loading