From 492a6cb73a41af77fd4b4989a11336188cfce523 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 20 Jan 2025 15:28:09 +0100 Subject: [PATCH] Tests - Improve Playright tests with works and tags --- .github/workflows/e2e_tests.yml | 18 ++++++++--- tests/README.md | 13 ++++---- .../integration/dataviz-api-ghaction.js | 20 ------------ .../integration/error_occurred-ghaction.js | 12 ------- tests/end2end/playwright.config.ts | 4 +-- .../playwright/requests-dataviz-api.spec.js | 31 +++++++++++++++++++ 6 files changed, 54 insertions(+), 44 deletions(-) delete mode 100644 tests/end2end/cypress/integration/error_occurred-ghaction.js create mode 100644 tests/end2end/playwright/requests-dataviz-api.spec.js diff --git a/.github/workflows/e2e_tests.yml b/.github/workflows/e2e_tests.yml index 1693679c8e..2119526d1d 100644 --- a/.github/workflows/e2e_tests.yml +++ b/.github/workflows/e2e_tests.yml @@ -27,6 +27,9 @@ jobs: working-directory: tests env: CYPRESS_CI: TRUE + PLAYWRIGHT_FORCE_TTY: true + PLAYWRIGHT_LIST_PRINT_STEPS: true + FORCE_COLOR: true # For testing only # PHP_VERSION: 8.3 # LZMPOSTGISVERSION: 16-3 @@ -162,11 +165,18 @@ jobs: cd end2end npx playwright install --with-deps chromium - - name: Run Playwright tests - id: test-playwright + - name: Run Playwright tests read-only + id: test-playwright-read-only run: | cd end2end - npx playwright test --project=end2end + npx playwright test --grep @readonly --project=end2end + + - name: Run Playwright tests not tagged read-only + id: test-playwright-not-read-only + if: success() || steps.test-playwright-not-read-only.conclusion == 'failure' + run: | + cd end2end + npx playwright test --workers 1 --grep-invert @readonly --project=end2end # - name: Generate PG dump from Playwright # if: failure() @@ -203,7 +213,7 @@ jobs: - name: Cypress run id: test-cypress # Always run, even if playwright has failed - if: always() + if: success() || steps.test-playwright-not-read-only.conclusion == 'failure' || steps.test-playwright-not-read-only.conclusion == 'failure' uses: cypress-io/github-action@v6.7.8 with: browser: chrome diff --git a/tests/README.md b/tests/README.md index 70f98187de..63be726fed 100644 --- a/tests/README.md +++ b/tests/README.md @@ -251,12 +251,13 @@ Output colors can be kept with `--tty` parameter, but it won't work with `--grou You have to install the browsers with `npx playwright install` (only the first time or after an update) You can then : -- execute `npx playwright test --ui --project=chromium` to open a UI as in Cypress which ease testing -- execute `npx playwright test` to execute all tests with all browsers -- execute `npx playwright test --project=chromium` to execute all tests with the Chromium browser -- execute `npx playwright test --project=chromium --grep-invert "test_a|test_b"` to execute all tests but "test_a" and "test_b" with the Chromium browser -- execute `npx playwright test mytest.spec.js --project=chromium` to execute one test with the Chromium browser -- execute `npx playwright test mytest.spec.js --project=chromium --debug` to execute one test with the Chromium browser in debug mode +- `npx playwright test --ui --project=chromium` to open a UI as in Cypress which ease testing +- `npx playwright test` to execute all tests with all browsers +- `npx playwright test --grep @readonly --workers 4` to run tests with 4 workers for tests which are read-only +- `npx playwright test --project=chromium` to execute all tests with the Chromium browser +- `npx playwright test --project=chromium --grep-invert "test_a|test_b"` to execute all tests but "test_a" and "test_b" with the Chromium browser +- `npx playwright test mytest.spec.js --project=chromium` to execute one test with the Chromium browser +- `npx playwright test mytest.spec.js --project=chromium --debug` to execute one test with the Chromium browser in debug mode - other command line : https://playwright.dev/docs/intro#command-line You can also install the handy [Playwright extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright) on VSCode. diff --git a/tests/end2end/cypress/integration/dataviz-api-ghaction.js b/tests/end2end/cypress/integration/dataviz-api-ghaction.js index 18a6b2fadc..0eb26fbfb0 100644 --- a/tests/end2end/cypress/integration/dataviz-api-ghaction.js +++ b/tests/end2end/cypress/integration/dataviz-api-ghaction.js @@ -1,24 +1,4 @@ describe('Dataviz API tests', function () { - it('Test JSON data for plot 0 - Municipalities', function () { - cy.request({ - method: 'GET', - url: '/index.php/dataviz/service?repository=testsrepository&project=dataviz', - qs: { - 'request': 'getPlot', - 'plot_id': '0' - }, - }).then((resp) => { - expect(resp.status).to.eq(200) - expect(resp.headers['content-type']).to.contain('application/json') - expect(resp.body).to.have.property('title', 'Municipalities') - expect(resp.body).to.have.property('data') - expect(resp.body.data).to.have.length(1) - expect(resp.body.data[0]).to.have.property('type', 'bar') - expect(resp.body.data[0]).to.have.property('x').to.have.same.members(["Grabels", "Clapiers", "Montferrier-sur-Lez", "Saint-Jean-de-Védas", "Lattes", "Montpellier", "Lavérune", "Juvignac", "Le Crès", "Castelnau-le-Lez"]) - expect(resp.body.data[0]).to.have.property('y').to.have.same.members([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - expect(resp.body).to.have.property('layout') - }) - }) it('Test JSON data for plot 2 - Pie bakeries by municipalities', function () { cy.request({ diff --git a/tests/end2end/cypress/integration/error_occurred-ghaction.js b/tests/end2end/cypress/integration/error_occurred-ghaction.js deleted file mode 100644 index 00c1b537b0..0000000000 --- a/tests/end2end/cypress/integration/error_occurred-ghaction.js +++ /dev/null @@ -1,12 +0,0 @@ -describe('Check if an error occurred', function () { -// it('Test to have an error', function () { -// cy.gotoMap('/index.php/view/map/?repository=testsrepository&project=invalid_layer', false) -// -// // Remove the log from the invalid layer. -// cy.exec('./../lizmap-ctl docker-exec rm -f /srv/lzm/lizmap/var/log/errors.log', {failOnNonZeroExit: false}) -// }) - - it('Test to not have an error', function () { - cy.gotoMap('/index.php/view/map/?repository=testsrepository&project=attribute_table') - }) -}) diff --git a/tests/end2end/playwright.config.ts b/tests/end2end/playwright.config.ts index bf4f05bd1a..11c1a2ca2b 100644 --- a/tests/end2end/playwright.config.ts +++ b/tests/end2end/playwright.config.ts @@ -19,9 +19,9 @@ export default defineConfig({ /* Retry on CI only */ retries: process.env.CI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: process.env.CI ? 5 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', + reporter: [['list', { printSteps: true }]], /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ diff --git a/tests/end2end/playwright/requests-dataviz-api.spec.js b/tests/end2end/playwright/requests-dataviz-api.spec.js new file mode 100644 index 0000000000..9825ca8695 --- /dev/null +++ b/tests/end2end/playwright/requests-dataviz-api.spec.js @@ -0,0 +1,31 @@ +// @ts-check +import { test, expect } from '@playwright/test'; + +test.describe('Dataviz API tests', + { + tag: ['@requests', '@readonly'], + }, () => { + + test('Test JSON data for plot 0 - Municipalities', async ({request}) => { + const response = await request.get( + '/index.php/dataviz/service?repository=testsrepository&project=dataviz', + { + params:{ + 'request': 'getPlot', + 'plot_id': '0', + } + }); + expect(response.status()).toBe(200); + expect(response.headers()['content-type']).toBe('application/json'); + const json = await response.json(); + expect(json).toHaveProperty('title', 'Municipalities'); + expect(json).toHaveProperty('data'); + expect(json.data).toHaveLength(1); + expect(json.data[0]).toHaveProperty('type', 'bar'); + expect(json.data[0]).toHaveProperty('x'); + expect(json.data[0].x).toStrictEqual(["Grabels", "Clapiers", "Montferrier-sur-Lez", "Saint-Jean-de-Védas", "Lattes", "Montpellier", "Lavérune", "Juvignac", "Le Crès", "Castelnau-le-Lez"]); + expect(json.data[0]).toHaveProperty('y'); + expect(json.data[0].y).toStrictEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + expect(json).toHaveProperty('layout') + }); + });