Skip to content

Commit

Permalink
Merge pull request #816 from geonetwork/e2e-screenshots
Browse files Browse the repository at this point in the history
Take screenshots in Cypress tests & upload them on the PR
  • Loading branch information
jahow authored Mar 20, 2024
2 parents 463b60b + 31d7091 commit c9f3c31
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 95 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ jobs:
cypress-run:
name: End-to-end tests
runs-on: ubuntu-latest
outputs:
screenshotsUrl: ${{ steps.upload-screenshots.outputs.artifact-url }}
steps:
- uses: actions/checkout@v4

Expand All @@ -167,6 +169,23 @@ jobs:
- name: Run tests
run: npx nx run-many --target=e2e

- uses: actions/upload-artifact@v4
if: always()
id: upload-screenshots
with:
name: cypress-screenshots
path: |
apps/datahub-e2e/cypress/screenshots/**/*
apps/metadata-editor-e2e/cypress/screenshots/**/*
- uses: thollander/actions-comment-pull-request@v2
if: always() && github.event_name == 'pull_request' && steps.upload-screenshots.outputs.artifact-url
with:
message: '📷 Screenshots are [here](${{ steps.upload-screenshots.outputs.artifact-url }})!'
comment_tag: screenshots-url
pr_number: ${{ github.event.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-npm-package:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
name: Attempt to build the NPM package
Expand Down
18 changes: 18 additions & 0 deletions apps/datahub-e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'cypress'
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'
import { cypressBrowserPermissionsPlugin } from 'cypress-browser-permissions'
import { fileURLToPath } from 'url'
import { configureCommonPlugins } from '../../tools/e2e/plugins.js'

export default defineConfig({
e2e: {
...nxE2EPreset(fileURLToPath(import.meta.url)),
video: false,
downloadsFolder: 'cypress/downloads',
screenshotsFolder: 'cypress/screenshots',
setupNodeEvents(on, config) {
cypressBrowserPermissionsPlugin(on, config)
configureCommonPlugins(on, config)
},
},
})
10 changes: 0 additions & 10 deletions apps/datahub-e2e/cypress.config.ts

This file was deleted.

3 changes: 3 additions & 0 deletions apps/datahub-e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
5 changes: 3 additions & 2 deletions apps/datahub-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"e2e": {
"executor": "@nx/cypress:cypress",
"options": {
"cypressConfig": "apps/datahub-e2e/cypress.config.ts",
"cypressConfig": "apps/datahub-e2e/cypress.config.js",
"devServerTarget": "datahub:serve:development",
"testingType": "e2e"
"testingType": "e2e",
"browser": "chrome"
},
"configurations": {
"production": {
Expand Down
8 changes: 8 additions & 0 deletions apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('dataset pages', () => {
cy.get('datahub-header-record')
.children('header')
.find('gn-ui-navigation-button')
cy.screenshot({ capture: 'fullPage' })
})
it('should display the data type, last update and status', () => {
cy.visit('/dataset/01491630-78ce-49f3-b479-4b30dabc4c69')
Expand Down Expand Up @@ -201,6 +202,7 @@ describe('dataset pages', () => {
.find('gn-ui-button')
.click()
cy.get('.basicLightbox--visible')
cy.screenshot({ capture: 'viewport' })
})
})

Expand All @@ -217,6 +219,7 @@ describe('dataset pages', () => {
cy.get('gn-ui-metadata-quality gn-ui-progress-bar')
.eq(0)
.should('have.attr', 'ng-reflect-value', 75)
cy.screenshot({ capture: 'fullPage' })
})
})
})
Expand Down Expand Up @@ -258,6 +261,7 @@ describe('dataset pages', () => {
.find('tbody')
.children('tr')
.should('have.length.gt', 0)
cy.screenshot({ capture: 'fullPage' })
})
it('should display the chart & dropdowns', () => {
cy.get('@previewSection')
Expand All @@ -280,6 +284,7 @@ describe('dataset pages', () => {
.find('button')
.should('have.length.greaterThan', 0)
})
cy.screenshot({ capture: 'fullPage' })
})
})
describe('features', () => {
Expand Down Expand Up @@ -386,6 +391,7 @@ describe('dataset pages', () => {
expect(formatOutput).to.eq(filterFormat)
})
})
cy.screenshot({ capture: 'fullPage' })
})
it('downloads a file on click', () => {
cy.get('datahub-record-downloads')
Expand Down Expand Up @@ -509,6 +515,7 @@ describe('record with file distributions', () => {
.children('button')
.then((options) => options.toArray().map((el) => el.innerText.trim()))
.should('deep.eq', ['csv (csv)', 'json (json)', 'geojson (geojson)'])
cy.screenshot({ capture: 'viewport' })
})
})

Expand All @@ -527,6 +534,7 @@ describe('api cards', () => {
it('should open and close the panel on click on open panel button', () => {
cy.get('@firstCard').click()
cy.get('gn-ui-record-api-form').should('be.visible')
cy.screenshot({ capture: 'fullPage' })
cy.get('@firstCard').click()
cy.get('gn-ui-record-api-form').should('not.be.visible')
})
Expand Down
7 changes: 7 additions & 0 deletions apps/datahub-e2e/src/e2e/datasets.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('datasets', () => {
.find('[data-cy=filters-expand]')
.filter(':visible')
.should('have.length', 1)
cy.screenshot({ capture: 'viewport' })
})
it('should sort by relevance initially', () => {
cy.get('@sortBy')
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('datasets', () => {
.find('a')
.invoke('attr', 'href')
.should('include', 'catalog.signin')
cy.screenshot({ capture: 'viewport' })
})
})
describe('when logged in', () => {
Expand All @@ -125,6 +127,7 @@ describe('datasets', () => {
.then((text) => {
cy.get('@initialCount').should('not.eq', text)
})
cy.screenshot({ capture: 'viewport' })
})
})
})
Expand Down Expand Up @@ -190,6 +193,7 @@ describe('datasets', () => {
'resourceType',
'representationType',
])
cy.screenshot({ capture: 'viewport' })
})

describe('publisher filter', () => {
Expand Down Expand Up @@ -294,6 +298,7 @@ describe('datasets', () => {
'Service public de Wallonie (SPW) (2)',
"Société Publique de Gestion de l'Eau (SPGE) (1)",
])
cy.screenshot({ capture: 'viewport' })
})
})

Expand Down Expand Up @@ -480,6 +485,7 @@ describe('datasets', () => {
'eql',
'Cartographie des sols agricoles de la plaine du Rhône'
)
cy.screenshot({ capture: 'viewport' })
})
})
})
Expand Down Expand Up @@ -560,6 +566,7 @@ describe('datasets', () => {
cy.get('gn-ui-progress-bar')
.eq(0)
.should('have.attr', 'ng-reflect-value', 100)
cy.screenshot({ capture: 'viewport' })
})
})
})
Expand Down
2 changes: 2 additions & 0 deletions apps/datahub-e2e/src/e2e/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('header', () => {
.find('a')
.first()
.should('have.attr', 'title', 'Accroches vélos MEL')
cy.screenshot({ capture: 'viewport' })
})
it('should display the search results on enter touch', () => {
cy.get('gn-ui-fuzzy-search').type('velo{enter}')
Expand Down Expand Up @@ -138,6 +139,7 @@ describe('header', () => {
.getActiveDropdownOption()
.invoke('attr', 'data-cy-value')
.should('equal', 'desc,createDate')
cy.screenshot({ capture: 'viewport' })
})
it('should filter results by popularity', () => {
cy.get('gn-ui-fuzzy-search').next().find('button').eq(1).click()
Expand Down
5 changes: 5 additions & 0 deletions apps/datahub-e2e/src/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe('home', () => {
})
it('should display the "show more" button', () => {
cy.get('[data-cy="addMoreBtn"]').should('be.visible')
cy.get('body').then((body$) => {
cy.viewport(body$.width(), body$.height())
cy.screenshot({ capture: 'viewport' })
})
})
it('should display the orga and dataset link buttons', () => {
cy.get('gn-ui-figure').should('have.length', 2)
Expand Down Expand Up @@ -108,6 +112,7 @@ describe('home', () => {
.then(function (resultTitle) {
expect(resultTitle).to.eql(this.favoriteTitle)
})
cy.screenshot({ capture: 'viewport' })
})
})
})
2 changes: 2 additions & 0 deletions apps/datahub-e2e/src/e2e/organizations.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('organizations', () => {
cy.get('@organizationsRecordsCount')
.its('text')
.should('have.length.above', 0)
cy.screenshot({ capture: 'viewport' })
})
it('should display organization information', () => {
cy.get('@organizationsName')
Expand Down Expand Up @@ -182,6 +183,7 @@ describe('organizations', () => {
.eq(0)
.invoke('text')
.should('contain', 'Géo2France')
cy.screenshot({ capture: 'viewport' })
})
})
})
14 changes: 0 additions & 14 deletions apps/datahub-e2e/src/plugins/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions apps/datahub-e2e/src/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import { VIEWPORT_SIZE } from '../../../../tools/e2e/settings.js'

beforeEach(() => {
cy.viewport(1900, 1400)
cy.viewport(VIEWPORT_SIZE[0], VIEWPORT_SIZE[1])

// all tests should show english translations
window.localStorage.setItem('geonetwork-ui-language', 'en')
Expand Down
4 changes: 2 additions & 2 deletions apps/datahub-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"allowJs": false,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js", "cypress.config.ts"]
"include": ["src/**/*.ts"]
}
18 changes: 18 additions & 0 deletions apps/metadata-editor-e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'cypress'
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'
import { configureCommonPlugins } from '../../tools/e2e/plugins'
import { cypressBrowserPermissionsPlugin } from 'cypress-browser-permissions'
import { fileURLToPath } from 'url'

export default defineConfig({
e2e: {
...nxE2EPreset(fileURLToPath(import.meta.url)),
video: false,
downloadsFolder: 'cypress/downloads',
screenshotsFolder: 'cypress/screenshots',
setupNodeEvents(on, config) {
cypressBrowserPermissionsPlugin(on, config)
configureCommonPlugins(on, config)
},
},
})
10 changes: 0 additions & 10 deletions apps/metadata-editor-e2e/cypress.config.ts

This file was deleted.

3 changes: 3 additions & 0 deletions apps/metadata-editor-e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
5 changes: 3 additions & 2 deletions apps/metadata-editor-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"e2e": {
"executor": "@nx/cypress:cypress",
"options": {
"cypressConfig": "apps/metadata-editor-e2e/cypress.config.ts",
"cypressConfig": "apps/metadata-editor-e2e/cypress.config.js",
"devServerTarget": "metadata-editor:serve:development",
"testingType": "e2e"
"testingType": "e2e",
"browser": "chrome"
},
"configurations": {
"production": {
Expand Down
14 changes: 0 additions & 14 deletions apps/metadata-editor-e2e/src/plugins/index.js

This file was deleted.

8 changes: 8 additions & 0 deletions apps/metadata-editor-e2e/src/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@

// Import commands.js using ES2015 syntax:
import './commands'
import { VIEWPORT_SIZE } from '../../../../tools/e2e/settings'

beforeEach(() => {
cy.viewport(VIEWPORT_SIZE[0], VIEWPORT_SIZE[1])

// all tests should show english translations
window.localStorage.setItem('geonetwork-ui-language', 'en')
})
3 changes: 1 addition & 2 deletions apps/metadata-editor-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js", "cypress.config.ts"]
"include": ["src/**/*.ts"]
}
Loading

0 comments on commit c9f3c31

Please sign in to comment.