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

Add ability to whitelist visible elements in percy #45733

Merged
merged 17 commits into from
Sep 27, 2019

Conversation

nickofthyme
Copy link
Contributor

@nickofthyme nickofthyme commented Sep 13, 2019

Summary

Add the ability to whitelist OR blacklist visible elements in percy visual regression tests.

blacklist: select elements to ignore/hide default
whitelist: select only elements you want to show in the screenshot

Add SnapshotOptions to snapshot method in visual regression service.

interface SnapshotOptions {
    name?: string;
    add?: string[];
    remove?: string[];
}

The selectors options accept an array on testSubject selectors to identify which elements to hide or show.

Note when using the show option. You will not be able to hide children of the show elements.

See example Percy diff here. Notice the first whitelists only the chart and the second blacklists the side panel

@liza-mae are you ok with me un-skipping the discover tests to see if they are stable with these changes?

Checklist

For maintainers

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nickofthyme
Copy link
Contributor Author

@spalger could you take a look at this when you get a minute? Thanks

@cchaos
Copy link
Contributor

cchaos commented Sep 16, 2019

I think we should consider the risks this pose to the value of Percy. Visual testing is definitely important to purely visual components like graphs. However, it's also vital to ensure that the PR doesn't contain changes that affect the surrounding UI. By enabling white listing, you can more easily completely ignore what effects your changes have on the surrounding UI.

Take your screenshots for example, it not only ignores the outer UI, but the container the component sits in. Therefore, you'll miss the fact that the new graph's x-axis is actually extending beyond the container's bounds:

Another example is say, in your graph you wanted the text red. So you added .text { color: red } but didn't realize that the sidebar also has a .text selector and now all of a sudden all the text in the sidebar is red as well.

This won't be picked up by Percy because the test completely isolates only the component you've deemed necessary.

The nice thing about Percy, is that while it will indicate that there are differences, you can always accept them. It's a more manual process, but at the very least makes you consider your changes and how it affects other areas.

I am of course using the general "you" for all devs.

@nickofthyme
Copy link
Contributor Author

nickofthyme commented Sep 16, 2019

@cchaos Yup I agree entirely. I think of this as merely a temporary fix as we venture into the world of visual testing and work through all of the kinks.

TLDR;
This approach is an additive approach to build up to a more fully captured visual testing suite.

The issue we are facing right now is that the Percy tests are currently unstable. The maps tests are removing everything but the canvas element from the page to avoid erroneous or minor diffs.

The discover page is facing similar issues on top of the general issue of Percy not completely loading assets, such as font-awesome, before taking the screenshot.

I think the approach of whitelisting will help us build up to a final standard of the visual testing, while in the meantime not skipping tests because the current implementation needs to be fine-tuned. Also given we are charged per screenshot per PR per push, it would be ideal to test as much as we can in one shot as you have pointed out.

You pointed out another issue related to canvas elements which is that the chart is shifted in the full discovery page. This is again an implementation issue as the canvas elements are swapped with imgs then the screenshot is taken. If the browser widths are different, it skews the layout around canvas elements. We need to refine this approach and come up with a stable way of doing this.

@spalger
Copy link
Contributor

spalger commented Sep 16, 2019

@nickofthyme these failing checks aren't run on draft PRs, if you want to start with a draft in the future. Otherwise please resolve them?

@nickofthyme nickofthyme added release_note:skip Skip the PR/issue when compiling release notes v8.0.0 labels Sep 16, 2019
@spalger spalger added the v7.5.0 label Sep 16, 2019
@cchaos
Copy link
Contributor

cchaos commented Sep 17, 2019

Gotcha, thank you for the background. My concerns aren't meant to hinder progress for sure. I mainly wanted to raise them to consider why we're using Percy in the first place. But I see there's still a ways to go before full utilization, like fixing the font issue.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

This looks great, but I just saw this article and now I'm wondering if we could accomplish the same functionality with a call signature like:

takePercySnapshot({ show: ['foo'], hide: ['bar'] })

The idea would be that when show.length > 0 the .percyHideByDefault class would be added to the body, hide selectors would always be applied.

@nickofthyme
Copy link
Contributor Author

@spalger yeah I saw you mention deciding to whitelist or blacklist. I'll take a look at the article.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nickofthyme
Copy link
Contributor Author

@spalger Are you ok with me merging this?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nickofthyme
Copy link
Contributor Author

nickofthyme commented Sep 27, 2019

@elastic/kibana-design could someone take a look at this before merging, please? Thanks!

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Removal from SASS looks fine

@nickofthyme nickofthyme merged commit 858ad4d into elastic:master Sep 27, 2019
@nickofthyme nickofthyme deleted the fix/percy-flackyness branch September 27, 2019 17:07
liza-mae pushed a commit to liza-mae/kibana that referenced this pull request Oct 31, 2019
* add ability to whitelist visible elements in percy

* allow white and blacklisting elements in visual tests

* remove unnecessary webElement methods

* refactor snapshot options to use show and hide

* refactor add/remove and visual test helpers

* [percy] rework css rules to allow hiding inside shown elements

* [percy] adjust logic to support showing inside hiding

* attach styles to hide percy when capturing the snapshot

* refactor in order to make sure all logic is executed if snapshot fails

* remove sleeps

* add back skipFirefox tag
liza-mae pushed a commit to liza-mae/kibana that referenced this pull request Oct 31, 2019
* add ability to whitelist visible elements in percy

* allow white and blacklisting elements in visual tests

* remove unnecessary webElement methods

* refactor snapshot options to use show and hide

* refactor add/remove and visual test helpers

* [percy] rework css rules to allow hiding inside shown elements

* [percy] adjust logic to support showing inside hiding

* attach styles to hide percy when capturing the snapshot

* refactor in order to make sure all logic is executed if snapshot fails

* remove sleeps

* add back skipFirefox tag
liza-mae added a commit that referenced this pull request Oct 31, 2019
* add ability to whitelist visible elements in percy

* allow white and blacklisting elements in visual tests

* remove unnecessary webElement methods

* refactor snapshot options to use show and hide

* refactor add/remove and visual test helpers

* [percy] rework css rules to allow hiding inside shown elements

* [percy] adjust logic to support showing inside hiding

* attach styles to hide percy when capturing the snapshot

* refactor in order to make sure all logic is executed if snapshot fails

* remove sleeps

* add back skipFirefox tag
liza-mae added a commit that referenced this pull request Oct 31, 2019
* add ability to whitelist visible elements in percy

* allow white and blacklisting elements in visual tests

* remove unnecessary webElement methods

* refactor snapshot options to use show and hide

* refactor add/remove and visual test helpers

* [percy] rework css rules to allow hiding inside shown elements

* [percy] adjust logic to support showing inside hiding

* attach styles to hide percy when capturing the snapshot

* refactor in order to make sure all logic is executed if snapshot fails

* remove sleeps

* add back skipFirefox tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Visual Testing release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants