Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-23788 Setup for visual regression testing #5783

Conversation

saturninoabril
Copy link
Member

@saturninoabril saturninoabril commented Jun 23, 2020

Summary

Integrate visual regression testing using Applitools with Cypress.

How to run visual regression testing?

The feature is disabled by default.
To be able to run, you may get API key from Applitools and set into your env variable, and then run:

ENABLE_VISUAL_TEST=true node run_tests.js --group='@visual_regression'

Note:

  1. On CI, visual regression testing will run separately from functional testing.
  2. It's recommended to separate visual regression tests (into a dedicated folder /visual_regression) from functional tests:
  • to avoid flaky tests by directly going into the UI and do snapshot instead of mixing with other tests/actions
  • to not incur long duration to current overall tests since visual regression will take some time to process snapshots/results

How to get screenshot from the spec file?

There are three steps to get the screenshot.

  1. Open the window by cy.visualEyesOpen()
  2. Save snapshot by cy.visualSaveSnapshot()
  3. Then close the window cy.visualEyesClose()

Ticket Link

JIRA ticket: https://mattermost.atlassian.net/browse/MM-23788

@saturninoabril saturninoabril added 2: Dev Review Requires review by a core commiter 3: QA Review Requires review by a QA tester labels Jun 23, 2020
Copy link
Contributor

@josephbaylon josephbaylon left a comment

Choose a reason for hiding this comment

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

LGTM. All tests passed. Just a quick question, though, about applitools config file (see comment in e2e/applitools.config.js).

I used this locally to run several times,
APPLITOOLS_API_KEY=XXXXXXXX APPLITOOLS_BATCH_NAME="Webapp - master" ENABLE_VISUAL_TEST=true node run_tests.js --group='@visual_regression'

Also, I'm seeing this warning when I run the test locally. I haven't looked much into it but just curious if this is a security issue when running with a specific node version (I use v10.19.0)

(node:87342) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.

module.exports = {
appName: 'Mattermost Webapp UI',
accessibilityValidation: {level: 'AA', guidelinesVersion: 'WCAG_2_0'},
batchName: 'Webapp - master (dev)',
Copy link
Contributor

@josephbaylon josephbaylon Jun 23, 2020

Choose a reason for hiding this comment

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

Quick question: is batchName here supposed to be a default value? Reason I asked is when I don't set APPLITOOLS_BATCH_NAME, the value of the batch name in the UI reports is undefined.

Screen Shot 2020-06-23 at 2 14 41 PM

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, good catch. Yes, that should be the default value. Should be fixed now, PTAL.

Copy link
Contributor

@prapti prapti left a comment

Choose a reason for hiding this comment

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

This is awesome!
All tests passed as expected.
Thanks Saturn!

@saturninoabril
Copy link
Member Author

@josephbaylon re: NODE_TLS_REJECT_UNAUTHORIZED, I'm not particularly sure what's causing it and the implication of it. I'm seeing that too locally but not in CircleCI, even if both are on the same version of node @v10.20.1.

Copy link
Member

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

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

This is really cool! 🎉

In case my experience running this for the first time helps:

  • For some reason I had not executed npm i, so on the first run I was getting really weird errors. Maybe it's interesting to put it in the docs.
  • Then the tests failed because Chrome was not installed, although Cypress has always worked with Chromium for me. I installed Chrome and everything worked smoothly.
  • After the test run, I checked Applitools and I saw that I only had the snapshots of three batch runs, which was a bit confusing because I had run 4 tests. Then I realized that the System Console - Enterprise test has no snapshots whatsoever. I left a comment there.

I'm not an expert here, but the code looks good, so I'm approving. Thank you!

Comment on lines +96 to +122
before(() => {
// * Check if server has license for feature
cy.requireLicenseForFeature('Elasticsearch');

// # Go to system admin then verify admin console URL and header
cy.visit('/admin_console/about/license');
cy.url().should('include', '/admin_console/about/license');
cy.get('.admin-console', {timeout: TIMEOUTS.HALF_MIN}).should('be.visible').within(() => {
cy.get('.admin-console__header').should('be.visible').and('have.text', 'Edition and License');
});
});

testCases.forEach((testCase) => {
it(`${testCase.section} - ${testCase.header}`, () => {
// # Click the link on the sidebar
cy.get('.admin-sidebar').should('be.visible').within(() => {
cy.findByText(testCase.sidebar).scrollIntoView().should('be.visible').click();
});

// * Verify that it redirects to the URL and matches with the header
cy.url().should('include', testCase.url);
cy.get('.admin-console').should('be.visible').within(() => {
cy.get('.admin-console__header').should('be.visible').and(testCase.headerContains ? 'contain' : 'have.text', testCase.header);
});
});
});
});
Copy link
Member

Choose a reason for hiding this comment

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

There is no visual snapshot in this file. Should it be outside of the @visual_regression group?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I also realized that this was unintentionally checked in since I have it on my on going dev but it's fine to remain as is. I will have follow up PRs and will add corresponding metadata and visual tests.

@saturninoabril
Copy link
Member Author

@agarciamontoro Thanks for running the tests and valuable inputs.

  • npm i - we have it in the docs but maybe there's something we can improve?
  • Chromium - unfortunately it's not due to Cypress but Applitools. It's not currently supported per their list at the moment.
  • the last point (see in the comment itself)

@agarciamontoro
Copy link
Member

npm i - we have it in the docs but maybe there's something we can improve?

Probably not, when I first run an e2e test I followed that guide and everything was clear. I added that comment in case we have different docs for the visual regression testing. But if that's the entry point, it's perfect the way it is now. Thanks!

@saturninoabril saturninoabril added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core commiter 3: QA Review Requires review by a QA tester labels Jun 24, 2020
@saturninoabril saturninoabril merged commit 90d0647 into mattermost:master Jun 24, 2020
@saturninoabril saturninoabril deleted the MM-23788_visual_regression_setup branch June 24, 2020 10:25
@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants