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

Visual regression testing #319

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ jobs:
when: on_fail
- store_test_results:
path: test_results
- store_artifacts:
path: cypress/videos
- store_artifacts:
path: integration_tests/screenshots
- store_artifacts:
path: cypress-image-diff-screenshots
- store_artifacts:
path: ~/docker-logs

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ integration_tests/screenshots/
**/.DS_Store
.run

cypress/
cypress/
/cypress-image-diff-screenshots/comparison/
Copy link
Contributor

@alexw-moj alexw-moj Dec 16, 2024

Choose a reason for hiding this comment

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

There's more bits in the collapsed sections which we also want to compare?
Izzy found a nice .click({ multiple: true }) for the accordion sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think this is only the foundations - really the visual regression tests need integrating into the main tests in the same way as the accessibility ones I think.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions cypress-image-diff.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = {
FAILURE_THRESHOLD: 0.05, // 5% difference allowed
}

module.exports = config
6 changes: 5 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'cypress'
import getCompareSnapshotsPlugin from 'cypress-image-diff-js/plugin'
import { resetStubs } from './integration_tests/mockApis/wiremock'
import auth from './integration_tests/mockApis/auth'

Expand All @@ -13,7 +14,7 @@ export default defineConfig({
},
taskTimeout: 60000,
e2e: {
setupNodeEvents(on) {
setupNodeEvents(on, config) {
on('task', {
reset: resetStubs,
...auth,
Expand All @@ -23,6 +24,9 @@ export default defineConfig({
return null
},
})

// Add the visual regression plugin
return getCompareSnapshotsPlugin(on, config)
},
baseUrl: 'http://localhost:6789',
excludeSpecPattern: '**/!(*.cy).ts',
Expand Down
28 changes: 28 additions & 0 deletions integration_tests/e2e/visual-comparison.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe('Rendering of pages we can GET', () => {
before(() => {
cy.createSentencePlan().then(planDetails => {
cy.wrap(planDetails).as('plan')
cy.openSentencePlan(planDetails.oasysAssessmentPk)
})
})

it('take plan page screenshot', () => {
cy.visit('/plan')
cy.compareSnapshot('plan-page')
})

it('take create goal page screenshot', () => {
cy.visit('/create-goal/accommodation')
cy.compareSnapshot('create-goal-page')
})

it('take plan history page screenshot', () => {
cy.visit('/plan-history')
cy.compareSnapshot('plan-history-page')
})

it('take about page screenshot', () => {
cy.visit('/about')
cy.compareSnapshot('about-page')
})
})
3 changes: 3 additions & 0 deletions integration_tests/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import compareSnapshotCommand from 'cypress-image-diff-js/command'
import { addGoalToPlan, addStepToGoal, createSentencePlan, lockPlan, openSentencePlan } from './commands/backend'
import { checkAccessibility } from './commands/accessibility'
import 'cypress-axe'

compareSnapshotCommand()

// Handover/Auth
Cypress.Commands.add('openSentencePlan', openSentencePlan)
Cypress.Commands.add('createSentencePlan', createSentencePlan)
Expand Down
Loading