From 378a046f74a2b4d87ded2ace2566d488d995f454 Mon Sep 17 00:00:00 2001 From: kleinwave Date: Mon, 16 Dec 2024 11:59:52 +0200 Subject: [PATCH] Configure CI workflow for Playwright tests --- .github/workflows/playwright-tests.yaml | 39 +++++++-- frontend/tests/README.md | 3 +- frontend/tests/e2e/workflow2.test.ts | 2 +- frontend/tests/global-setup.ts | 19 ++-- frontend/tests/package-lock.json | 112 ++++++++++++++++++++++++ frontend/tests/playwright.config.ts | 20 +---- 6 files changed, 154 insertions(+), 41 deletions(-) create mode 100644 frontend/tests/package-lock.json diff --git a/.github/workflows/playwright-tests.yaml b/.github/workflows/playwright-tests.yaml index d4a8411..6a4387a 100644 --- a/.github/workflows/playwright-tests.yaml +++ b/.github/workflows/playwright-tests.yaml @@ -1,4 +1,4 @@ -# CI configuration for Playwright +# CI configuration for Playwright with Python and Qualibrate setup name: Playwright Tests on: @@ -19,18 +19,39 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + - name: Install Python and Create Environment + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m venv .venv + source .venv/bin/activate + pip install --upgrade pip + pip install qualibrate # Install Qualibrate package + pip install quam # Install Quam package + # pip install quam_libs # Install Quam libraries + # pip install quam_libs.components # Install Quam components + + - name: Create Qualibrate Configuration + run: | + source .venv/bin/activate + # qualibrate config --create + yes | qualibrate config # Create the Qualibrate configuration file + + - name: Install Node.js uses: actions/setup-node@v3 with: node-version: '18' - - name: Install dependencies - run: npm ci - - - name: Install Playwright Browsers - run: npx playwright install --with-deps + - name: Install Playwright Dependencies + run: | + npm ci + npx playwright install --with-deps - name: Run Playwright Tests - env: - PLAYWRIGHT_GLOBAL_SETUP: './tests/global-setup.ts' - run: npx playwright test + run: | + source .venv/bin/activate + npx playwright test --config=playwright.config.ts diff --git a/frontend/tests/README.md b/frontend/tests/README.md index 79f413a..a6297eb 100644 --- a/frontend/tests/README.md +++ b/frontend/tests/README.md @@ -1,7 +1,6 @@ # End to End Workflow Navigation Testing -![Playwright Tests](https://github.com/qua-platform/qualibrate-app/actions/workflows/playwright-tests.yaml/badge.svg) - +[![Playwright Tests](https://github.com/qua-platform/qualibrate-app/actions/workflows/playwright-tests.yaml/badge.svg)](https://github.com/qua-platform/qualibrate-app/actions/workflows/playwright-tests.yaml) ### Overview This is a front-end testing suite for integration workflows for the QUAlibrate Application. The following tests are designed to validate the functionality and correctness of [user workflows](https://quantum-machines.atlassian.net/wiki/spaces/hlsw/pages/3223912481/QAPP+UX+Design+Brief#User-workflows) section of the online documentation. diff --git a/frontend/tests/e2e/workflow2.test.ts b/frontend/tests/e2e/workflow2.test.ts index 18949df..128ab2f 100644 --- a/frontend/tests/e2e/workflow2.test.ts +++ b/frontend/tests/e2e/workflow2.test.ts @@ -9,7 +9,7 @@ test('Workflow2', { }, }, async ({ page }) => { - + // 1. Navigate to the Graph Library: // Ensure the application is running at http://127.0.0.1:8001/. await page.goto('http://localhost:8001/'); diff --git a/frontend/tests/global-setup.ts b/frontend/tests/global-setup.ts index 5c8e5de..d00b4ab 100644 --- a/frontend/tests/global-setup.ts +++ b/frontend/tests/global-setup.ts @@ -2,22 +2,17 @@ import { FullConfig } from '@playwright/test'; import { exec } from 'child_process'; async function globalSetup(config: FullConfig) { - console.log('Starting QUAlibrate server...'); - - // Start the server as a child process - const server = exec('qualibrate start', (error, stdout, stderr) => { + console.log('Starting Qualibrate server...'); + exec('source .venv/bin/activate && qualibrate start', (error, stdout, stderr) => { if (error) { - console.error(`Error starting server: ${error.message}`); - return; + console.error(`Error starting Qualibrate server: ${error.message}`); + process.exit(1); } if (stderr) { - console.error(`Server stderr: ${stderr}`); + console.error(`Qualibrate start stderr: ${stderr}`); } - console.log(`Server stdout: ${stdout}`); + console.log(`Qualibrate start stdout: ${stdout}`); }); - - // Store server reference for teardown, if needed - (global as any).__SERVER__ = server; } -export default globalSetup; \ No newline at end of file +export default globalSetup; diff --git a/frontend/tests/package-lock.json b/frontend/tests/package-lock.json new file mode 100644 index 0000000..acd0fa1 --- /dev/null +++ b/frontend/tests/package-lock.json @@ -0,0 +1,112 @@ +{ + "name": "qualibrate", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "qualibrate", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "playwright": "^1.49.0" + }, + "devDependencies": { + "@playwright/test": "^1.49.0", + "@types/node": "^22.10.1", + "typescript": "^5.7.2" + } + }, + "node_modules/@playwright/test": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.0.tgz", + "integrity": "sha512-DMulbwQURa8rNIQrf94+jPJQ4FmOVdpE5ZppRNvWVjvhC+6sOeo28r8MgIpQRYouXRtt/FCCXU7zn20jnHR4Qw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.49.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "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==", + "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.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.0.tgz", + "integrity": "sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A==", + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.49.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.0.tgz", + "integrity": "sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA==", + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/typescript": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "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/frontend/tests/playwright.config.ts b/frontend/tests/playwright.config.ts index 26df138..4b7f501 100644 --- a/frontend/tests/playwright.config.ts +++ b/frontend/tests/playwright.config.ts @@ -3,31 +3,21 @@ import { defineConfig } from '@playwright/test'; export default defineConfig({ testDir: './tests', // Test directory - /* 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, timeout: 30000, // Test timeout in milliseconds - /* Retry on CI only */ + globalSetup: './tests/global-setup.ts', // Path to global setup file + globalTeardown: './tests/global-teardown.ts', // Path to global teardown file 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', headless: true, - baseURL: 'http://127.0.0.1:8001/', // Update base URL for your app - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + baseURL: 'http://127.0.0.1:8001/', // base URL for the QUAlibrate app trace: 'on-first-retry', screenshot: 'only-on-failure', // Take screenshots only on failure video: 'retain-on-failure', // Record videos only for failed tests }, - globalSetup: './tests/global-setup.ts', // Path to your global setup file - globalTeardown: './tests/global-teardown.ts', // Path to your global teardown file projects: [ { @@ -42,9 +32,5 @@ export default defineConfig({ name: 'WebKit', use: { browserName: 'webkit' }, }, - // { - // name: 'Microsoft Edge', - // use: { channel: 'msedge' }, - // }, ], });