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

chore: compare cy.screenshot images in percy #21598

Merged
merged 13 commits into from
May 26, 2022
Merged

Conversation

marktnoonan
Copy link
Contributor

@marktnoonan marktnoonan commented May 23, 2022

The main change here is a circle.yml update, to use Percy to diff the screenshot images generated using the cy.screenshot() command from screenshot.cy.tsx. We do this currently on develop, so this ticket was just catch up.

When I did get these uploads working, there were some differences to investigate. Most were are result of global styles and only required changes to test code, not to the app itself.

After those changes to the test code, images only contained some differences in the presence/absences of scrollbars, so this PR includes changes to the app around overflow behavior, to fix those differences.

In addition to these Percy snapshots, I used ImageMagick to compare images generated by the screenshot system tests on both branches, confirming that none of these changes have altered those images.

User facing changelog

Scrollbars in screenshots will now be present/absent in the same situations in 9.x and 10.0. There were some situations where this previously was not the case in 10.0.

Additional details

The rest of the PR is:

  • a change to the screenshot.cy.tsx test itself to remove global styles. It's a component test, so it mounts in the context of the global app styles. Since global styles are different between 9.x and 10.0, there was some noise in the initial diffs caused by font and line height differences at the global level. Removing the 10.0 global styles in this test makes it much easier to diff with 10.0-release.
  • Some changes to overflow styles to bring the presence/absence of scrollbars into line between these screenshots when taken from 10.0 and 9.x. These differences hadn't shown up before due to the images being the same, apart from scrollbars. These changes involve taking a similar approach to the current is-screenshotting body class to add an screenshot-scrolling class. This allows us to conditionally add/remove CSS rules related to overflow without adding/removing classes with JavaScript in the nested Vue components. When managing the conditional classes in the Vue components, the styles were modified too late for the screenshot.
  • There's a tweak to the overflow of the specs-list-container which fixes another edge case that only appeared when scrollbars are present.

Since the latest Percy diff will compare this branch against 10.0-release, I've captured some diffs here between these screenshots on this branch and develop. What can be seen in these screenshots is a 1px shift to the left of all the content, since on 10.0-release (in this PR) we have previously fixed a 1px border bug in component test screenshots.

That means the 1px shifts, shown here in the diff with develop, are expected:

percy diff 4

percy diff 3

percy diff 2

percy diff 1

How has the user experience changed?

No UX changes.

PR Tasks

  • Have tests been added/updated?
  • [na] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?
  • [na] Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 23, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented May 23, 2022



Test summary

4874 0 59 0Flakiness 2


Run details

Project cypress
Status Passed
Commit 2dd755b
Started May 26, 2022 1:03 PM
Ended May 26, 2022 1:22 PM
Duration 18:42 💡
OS Linux Debian - 10.11
Browser Electron 100

View run in Cypress Dashboard ➡️


Flakiness

commands/net_stubbing.cy.ts Flakiness
1 network stubbing > intercepting request > can delay and throttle a StaticResponse
cypress/proxy-logging.cy.ts Flakiness
1 Proxy Logging > request logging > xhr log has response body/status code when xhr response is logged second

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

.is-screenshotting #resizable-panels-root {
overflow-x: visible;
overflow-y: visible;
}
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'd actually like to consolidate more of our screenshot css rules into this structure, instead of conditionally managing tailwind classes with JS. But to keep this PR focused, I'm not doing that here, just moving what's needed.

:class="{
'select-none': panel1IsDragging || panel2IsDragging,
'overflow-x-auto': !isFirefox
'overflow-x-hidden': isFirefox
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this lets the !important that comes with the utility class override the otherwise-preferred overflow.

@@ -13,7 +13,7 @@
/>
<ResizablePanels
v-else
:style="{width: `calc(100vw - ${collapsedNavBarWidth}px)`}"
:style="{width: `calc(100vw - ${screenshotStore.isScreenshotting ? 0 : collapsedNavBarWidth}px)`}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one was just a loose end with open-mode screenshots.

}
})

return cy.get('style').should('have.length', 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This now means that only the existing CSS injected by the component will be applied. Other CSS targeting body, HTML, global reset CSS etc will not apply here.

We may want to change this later, but for now this gives us the clearest diff with 10.0-release.

Copy link
Contributor

@rachelruderman rachelruderman May 23, 2022

Choose a reason for hiding this comment

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

This now means that only the existing CSS injected by the component will be applied.

This comment has great context!! What do you think about including it in the code?

@@ -1,7 +1,7 @@
<template>
<div
v-bind="containerProps"
class="pt-8px specs-list-container overflow-y-auto overflow-x-hidden"
class="pt-8px specs-list-container overflow-hidden"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the scrolling in the specs list takes place within a virtual list, the overflow-x value of auto was causing a weird empty space at the bottom of the parent, to do with how the vh works in the specs-list-container height calculation below.

@marktnoonan marktnoonan marked this pull request as ready for review May 23, 2022 15:46
@marktnoonan marktnoonan requested a review from a team as a code owner May 23, 2022 15:46
Comment on lines 58 to 60
removeGlobalStyles().then(() => {
cy.screenshot(`percy/component_testing_takes_a_screenshot_viewport_${capture}`, { capture })
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
removeGlobalStyles().then(() => {
cy.screenshot(`percy/component_testing_takes_a_screenshot_viewport_${capture}`, { capture })
})
removeGlobalStyles()
cy.screenshot(`percy/component_testing_takes_a_screenshot_viewport_${capture}`, { capture })

AFAIK you don't need .then because Cypress runs promises sequentially and you're not using the return value from removeGlobalStyles within cy.screenshot

cy.screenshot(`percy/large_component_hardcoded_size_viewport_${viewport[0]}_${viewport[1]}`, { capture: 'viewport' })
cy.screenshot(`percy/large_component_hardcoded_size_fullPage_${viewport[0]}_${viewport[1]}`, { capture: 'fullPage' })
removeGlobalStyles().then(() => {
cy.pause()
Copy link
Contributor

Choose a reason for hiding this comment

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

This pause is still hanging out here.

Copy link
Contributor

Choose a reason for hiding this comment

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

bump

Copy link
Contributor

@tbiethman tbiethman left a comment

Choose a reason for hiding this comment

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

I compared the generated screenshots to what's in develop, everything lines up how we'd expect. Also validated that they're showing up in Percy.

Great work on this @marktnoonan. It's nice to have regression coverage here, puts us in a good spot to refactor/condense some of these styles going forward.

@marktnoonan marktnoonan changed the base branch from 10.0-release to develop May 25, 2022 14:03
Copy link
Contributor

@ZachJW34 ZachJW34 left a comment

Choose a reason for hiding this comment

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

Other than the pause looks good to me!

@@ -98,6 +98,10 @@ const scrollOverrides = (win, doc) => {
// hide scrollbars
doc.documentElement.style.overflow = 'hidden'

// this body class is used to set some other overflow-related CSS
// around the resizable panels in the Runner
document.querySelector('body')?.classList.add('screenshot-scrolling')
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why TS is happy with this, if document.querySelector('body')? is ever null (which it shouldn't be) it would be safer to use document.querySelector('body')?.classList?.add('screenshot-scrolling')

I would just do document.body.classList.add('screenshot-scrolling')

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 got warnings in vscode when I did plain document.body so not sure what's up.

cy.screenshot(`percy/large_component_hardcoded_size_viewport_${viewport[0]}_${viewport[1]}`, { capture: 'viewport' })
cy.screenshot(`percy/large_component_hardcoded_size_fullPage_${viewport[0]}_${viewport[1]}`, { capture: 'fullPage' })
removeGlobalStyles().then(() => {
cy.pause()
Copy link
Contributor

Choose a reason for hiding this comment

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

bump

@marktnoonan marktnoonan merged commit 08e1682 into develop May 26, 2022
@marktnoonan marktnoonan deleted the UNIFY-1566-percy-ci branch May 26, 2022 14:08
tgriesser added a commit that referenced this pull request May 26, 2022
…ess into tgriesser/fix/UNIFY-1408

* 'tgriesser/fix/UNIFY-1408' of github.com:cypress-io/cypress:
  chore: compare `cy.screenshot` images in percy (#21598)
tgriesser added a commit that referenced this pull request May 27, 2022
…pack

* develop:
  fix: UNIFY-1408, warnings should be nested appropriately & clearable (#21630)
  chore: fix unit-tests-release job (#21652)
  chore(deps): update dependency eventsource to v2 [security] (#21639)
  fix: Add hover states for test titles in reporter (#21635)
  docs(CONTRIBUTING): Fix link to "good first issue" for newcomers (#21614)
  chore: compare `cy.screenshot` images in percy (#21598)
  fix: switching from ct to e2e (non-configured) does not go through setup (#21607)
  fix: issue with compilation failures in component testing (#21599)
  test: fix flaky launchpad test (#21637)
  docs: remove gitter link in contributing guide. (#21592)
  fix: order projects by most recently opened (#21589)
  fix: prevent crash on runs visit when offline (#21618)
  fix: pass family parameter to connect method (#21545)
  chore: clean up `debug` statements in preparation for 10.0 release, add `debug` docs (#21621)
  chore: add regression test for ts detection (#21578)
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.

4 participants