From 88fd31d1117f7a4682dc22220e06731eb703e79a Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 22 Jan 2025 11:26:42 +0100 Subject: [PATCH] init end-to-end tests with playwright --- tests/end-to-end/.gitignore | 8 +++ tests/end-to-end/package-lock.json | 97 +++++++++++++++++++++++++++ tests/end-to-end/package.json | 15 +++++ tests/end-to-end/playwright.config.ts | 77 +++++++++++++++++++++ tests/end-to-end/run.sh | 21 ++++++ tests/end-to-end/tests/tests.spec.ts | 20 ++++++ 6 files changed, 238 insertions(+) create mode 100644 tests/end-to-end/.gitignore create mode 100644 tests/end-to-end/package-lock.json create mode 100644 tests/end-to-end/package.json create mode 100644 tests/end-to-end/playwright.config.ts create mode 100755 tests/end-to-end/run.sh create mode 100644 tests/end-to-end/tests/tests.spec.ts diff --git a/tests/end-to-end/.gitignore b/tests/end-to-end/.gitignore new file mode 100644 index 0000000..6ac3680 --- /dev/null +++ b/tests/end-to-end/.gitignore @@ -0,0 +1,8 @@ +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ + +test-examples +example.spec.ts diff --git a/tests/end-to-end/package-lock.json b/tests/end-to-end/package-lock.json new file mode 100644 index 0000000..6214677 --- /dev/null +++ b/tests/end-to-end/package-lock.json @@ -0,0 +1,97 @@ +{ + "name": "end-to-end", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "end-to-end", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@playwright/test": "^1.49.1", + "@types/node": "^22.10.7" + } + }, + "node_modules/@playwright/test": { + "version": "1.49.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.1.tgz", + "integrity": "sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.49.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.10.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.7.tgz", + "integrity": "sha512-V09KvXxFiutGp6B7XkpaDXlNadZxrzajcY50EuoLIpQ6WWYCSvf19lVIazzfIzQvhUN2HjX12spLojTnhuKlGg==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.20.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.49.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.1.tgz", + "integrity": "sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.49.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.49.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.1.tgz", + "integrity": "sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/tests/end-to-end/package.json b/tests/end-to-end/package.json new file mode 100644 index 0000000..2d4864c --- /dev/null +++ b/tests/end-to-end/package.json @@ -0,0 +1,15 @@ +{ + "name": "end-to-end", + "version": "1.0.0", + "main": "index.js", + "scripts": {}, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "description": "", + "devDependencies": { + "@playwright/test": "^1.49.1", + "@types/node": "^22.10.7" + } +} diff --git a/tests/end-to-end/playwright.config.ts b/tests/end-to-end/playwright.config.ts new file mode 100644 index 0000000..301801e --- /dev/null +++ b/tests/end-to-end/playwright.config.ts @@ -0,0 +1,77 @@ +import { defineConfig, devices } from '@playwright/test'; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); diff --git a/tests/end-to-end/run.sh b/tests/end-to-end/run.sh new file mode 100755 index 0000000..5a5fbf9 --- /dev/null +++ b/tests/end-to-end/run.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# SPDX-License-Identifier: AGPL-3.0-or-later + +set -e +set -u +# DEBUG +set -x + +main() { + cd "$(dirname "${0}")" + browser="${browser:-firefox}" + project="${project:-firefox}" + headed="${headed:---headed}" + npx playwright test --project "${project}" "${headed}" +} + +main "${@}" + +# written in emacs +# -*- mode: shell-script; -*- diff --git a/tests/end-to-end/tests/tests.spec.ts b/tests/end-to-end/tests/tests.spec.ts new file mode 100644 index 0000000..578b7be --- /dev/null +++ b/tests/end-to-end/tests/tests.spec.ts @@ -0,0 +1,20 @@ +import { test, expect } from '@playwright/test'; + +// TODO after the tests, put again demo.ereuse.org as default +const TEST_SITE = process.env.TEST_SITE || 'https://lab1.ereuse.org' +const TEST_USER = 'user@example.org' +const TEST_PASSWD = '1234' + +async function login(page, date, time) { + await page.goto(TEST_SITE); + await page.getByPlaceholder('Email address').click(); + await page.getByPlaceholder('Email address').fill(TEST_USER); + await page.getByPlaceholder('Password').fill(TEST_PASSWD); + await page.getByPlaceholder('Password').press('Enter'); + await page.getByRole('button', { name: 'Next' }).click(); +} + +test('example', async ({ page }) => { + await login(page); + await page.pause(); +});