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

Backport about Playwright tags and Cypress migration #5244

Merged
merged 2 commits 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 @@ -160,11 +163,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-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 @@ -201,7 +211,7 @@ jobs:
- name: Cypress run
id: test-cypress
# Always run, even if playwright has failed
if: always()
if: success() || steps.test-playwright-read-only.conclusion == 'failure' || steps.test-playwright-not-read-only.conclusion == 'failure'
uses: cypress-io/[email protected]
with:
browser: chrome
Expand Down
12 changes: 7 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +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 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.

209 changes: 0 additions & 209 deletions tests/end2end/cypress/integration/requests-metadata-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
41 changes: 20 additions & 21 deletions tests/end2end/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import { test as setup } from '@playwright/test';
// @ts-ignore
import path from 'path';
import { Page } from '@playwright/test';

const user_in_group_aFile = path.join(__dirname, './.auth/user_in_group_a.json');

setup('authenticate as user_in_group_a', async ({ page }) => {
/**
* Performs the authentication steps
* @param {Page} page The page object
* @param {string} login The login
* @param {string} password The password
* @param {string} user_file The path to the file where the cookies will be stored
*/
export async function auth_using_login(page: Page, login: string, password: string, user_file: string) {
// Perform authentication steps. Replace these actions with your own.
await page.goto('admin.php/auth/login?auth_url_return=%2Findex.php');
await page.locator('#jforms_jcommunity_login_auth_login').fill('user_in_group_a');
await page.locator('#jforms_jcommunity_login_auth_password').fill('admin');
await page.locator('#jforms_jcommunity_login_auth_login').fill(login);
await page.locator('#jforms_jcommunity_login_auth_password').fill(password);
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL('index.php');

// End of authentication steps.
await page.context().storageState({ path: user_file });
}

await page.context().storageState({ path: user_in_group_aFile });
setup('authenticate as user_in_group_a', async ({ page }) => {
await auth_using_login(page, 'user_in_group_a', 'admin', path.join(__dirname, './.auth/user_in_group_a.json'));
});

const adminFile = path.join(__dirname, './.auth/admin.json');

setup('authenticate as admin', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto('admin.php/auth/login?auth_url_return=%2Findex.php');
await page.locator('#jforms_jcommunity_login_auth_login').fill('admin');
await page.locator('#jforms_jcommunity_login_auth_password').fill('admin');
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL('index.php');

// End of authentication steps.
await auth_using_login(page, 'admin', 'admin', path.join(__dirname, './.auth/admin.json'));
});

await page.context().storageState({ path: adminFile });
setup('authenticate as publisher', async ({ page }) => {
await auth_using_login(page, 'publisher', 'admin', path.join(__dirname, './.auth/publisher.json'));
});
Loading
Loading