Skip to content

Commit

Permalink
test: ✅ Add package playwright for test e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Carolinedanslesnuages committed Dec 23, 2024
1 parent ae91371 commit 87de8bf
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 64 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"

- name: Install pnpm
run: npm install -g pnpm

- name: Install dependencies
run: pnpm install

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps

- name: Run Playwright tests
run: pnpm exec playwright test

- name: Upload Playwright Report
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
5 changes: 5 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
clientnode_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "^3.0.0",
"@playwright/test": "^1.46.1",
"@playwright/test": "^1.48.0",
"@rushstack/eslint-patch": "^1.10.4",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/vue": "^8.1.0",
Expand Down
88 changes: 27 additions & 61 deletions client/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,76 @@
import process from "node:process";
import { defineConfig, devices } from "@playwright/test";
import { defineConfig, devices } from '@playwright/test';

// For CI, you may want to set BASE_URL to the deployed application.
const baseURL = process.env["BASE_URL"] || "http://localhost:5173";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./e2e",
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
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",
reporter: 'html',
/* 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). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://localhost:5173",
baseURL,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",

/* Only on CI systems run the tests headless */
headless: !!process.env.CI,
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
},
},
{
name: "firefox",
use: {
...devices["Desktop Firefox"],
},
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: "webkit",
use: {
...devices["Desktop Safari"],
},
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: {
// ...devices['Pixel 5'],
// },
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: {
// ...devices['iPhone 12'],
// },
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
webServer: {
/**
* Use the dev server by default for faster feedback loop.
* Use the preview server on CI for more realistic testing.
* Playwright will re-use the local server if there is already a dev-server running.
*/
command: process.env.CI ? "vite preview --port 5173" : "vite dev",
port: 5173,
reuseExistingServer: !process.env.CI,
},
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
2 changes: 1 addition & 1 deletion client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {};
export {}

/* prettier-ignore */
declare module 'vue' {
Expand Down
22 changes: 22 additions & 0 deletions client/tests/homePage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// tests/homePage.spec.js
import { test, expect } from '@playwright/test';

test.describe('Home Page', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:5173'); // URL de votre application
});

test('should display the header elements', async ({ page }) => {
const headerLogo = page.locator('[data-testid="header-logo"]');
await expect(headerLogo).toBeVisible();
await expect(headerLogo).toContainText('Ministère');

const serviceTitle = page.locator('.fr-header__service-title');
await expect(serviceTitle).toBeVisible();
await expect(serviceTitle).toContainText('Référentiel des Applications');

const serviceTagline = page.locator('.fr-header__service-tagline');
await expect(serviceTagline).toBeVisible();
await expect(serviceTagline).toContainText('Une application pour les réunir toutes');
});
});

0 comments on commit 87de8bf

Please sign in to comment.