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

Tests - Improve Playright tests with works and tags #5239

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 14 additions & 4 deletions .github/workflows/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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/[email protected]
with:
browser: chrome
Expand Down
13 changes: 7 additions & 6 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 0 additions & 20 deletions tests/end2end/cypress/integration/dataviz-api-ghaction.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
12 changes: 0 additions & 12 deletions tests/end2end/cypress/integration/error_occurred-ghaction.js

This file was deleted.

4 changes: 2 additions & 2 deletions tests/end2end/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down
31 changes: 31 additions & 0 deletions tests/end2end/playwright/requests-dataviz-api.spec.js
Original file line number Diff line number Diff line change
@@ -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')
});
});
Loading