Skip to content

Conversation

@AtofStryker
Copy link
Contributor

@AtofStryker AtofStryker commented Jul 12, 2022

User facing changelog

Fixes a regression in 9.6 where absolute elements that are blacked out with cy.screenshot are positioned off the container element and not the body.

Additional details

This PR attempts to fix a regression when screenshots were refactored for cy.origin in #20949 where element dimensions are calculated from the screenshotted element. This works in most cases, but causes some trouble with absolute elements. To fix this, since we no longer have access to the AutIframe class, is to reference the body to calculate dimensions for elements.

Steps to test

See changes to the screenshot_viewport_capture_spec.js

How has the user experience changed?

Before code changes with added regression test in screenshot_viewport_capture_spec.js

After code changes with added regression test in screenshot_viewport_capture_spec.js

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 12, 2022

Thanks for taking the time to open a PR!

return before($el)
// get the current body of the AUT to accurately calculate screenshot blackouts
// as well as properly enable/disable CSS animations while screenshotting is happening
const $body = Cypress.$('body')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there possibly a cleaner way to reference the body here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prob isn't what you are looking for, but I think we store the AUT frame on the cypress instance
$autIframe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine - since the Cypress instance is injected to the AUT, and you can only have one instance of HTMLBodyElement (or the browser will raise an error) this seems safe to me.

blackout: ['.blue'],
onBeforeScreenshot () {
const blackedOutElementCoordinates = Cypress.$(
'#__cypress-animation-disabler+div.__cypress-blackout',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to better selectors here. This seems to be a bit of a coincidence that our blacked out elements are adjacent to the animation disabler element. Also the test assertions below aren't great, but at least should guarantee that the blacked out element is very close to the thing it's trying to black out.

@AtofStryker AtofStryker self-assigned this Jul 12, 2022
@cypress
Copy link

cypress bot commented Jul 12, 2022



Test summary

4375 0 51 0Flakiness 0


Run details

Project cypress
Status Passed
Commit 1002b5a
Started Jul 13, 2022 6:53 PM
Ended Jul 13, 2022 7:05 PM
Duration 11:39 💡
OS Linux Debian - 10.11
Browser Firefox 98

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@AtofStryker AtofStryker marked this pull request as ready for review July 12, 2022 21:55
@AtofStryker AtofStryker requested review from a team as code owners July 12, 2022 21:55
@AtofStryker AtofStryker requested review from BlueWinds, chrisbreiding, emilyrohrbough, mjhenkes and mschile and removed request for a team and BlueWinds July 12, 2022 21:55
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit around types - probably a quick win, but going to approve.

}

const before = ($el) => {
const before = ($body, $container) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we incrementally ad types as we go? HTMLBodyElement and HTMLElement, in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to create a follow up PR to add types to the screenshot files since it's quite a bit of changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened #22768 against this branch and will rebase it once I merge this in

return before($el)
// get the current body of the AUT to accurately calculate screenshot blackouts
// as well as properly enable/disable CSS animations while screenshotting is happening
const $body = Cypress.$('body')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine - since the Cypress instance is injected to the AUT, and you can only have one instance of HTMLBodyElement (or the browser will raise an error) this seems safe to me.

@AtofStryker AtofStryker merged commit e16820b into develop Jul 13, 2022
@AtofStryker AtofStryker deleted the bugfix/screenshot-blackouts branch July 13, 2022 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blackout area is offset from where it should be when upgrading to 9.7.0 from 9.5.4

7 participants