Skip to content

Commit 17df44b

Browse files
Playwright setup
1 parent 1c339a1 commit 17df44b

27 files changed

+2539
-204
lines changed

.github/actions/docker-compose-app.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ services:
44
image: "ghcr.io/glpi-project/${PHP_IMAGE:-githubactions-php-apache:8.3}"
55
environment:
66
CODE_COVERAGE: "${CODE_COVERAGE:-false}"
7+
CI: true # Will be used to alter some configuration when running on github vs locally.
8+
PLAYWRIGHT_BROWSERS_PATH: /opt/pw-browsers # Custom browser path to prevent some rights issues.
9+
GLPI_BASE_URL: http://localhost:80 # Default URL for GLPI. Used for e2e tests.
710
volumes:
811
- type: "bind"
912
source: "${APPLICATION_ROOT}"

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,64 @@ jobs:
275275
with:
276276
name: cypress-screenshots
277277
path: tests/cypress/screenshots
278+
279+
playwright:
280+
# Do not run scheduled tests on tier repositories
281+
if: github.repository == 'glpi-project/glpi' || github.event_name != 'schedule'
282+
name: "Playwright tests using latest PHP and MariaDB versions"
283+
runs-on: "ubuntu-latest"
284+
timeout-minutes: 60
285+
env:
286+
COMPOSE_FILE: ".github/actions/docker-compose-app.yml:.github/actions/docker-compose-services.yml"
287+
APPLICATION_ROOT: "${{ github.workspace }}"
288+
DB_IMAGE: "githubactions-mariadb:10.11"
289+
PHP_IMAGE: "githubactions-php-apache:8.3"
290+
UPDATE_FILES_ACL: true
291+
steps:
292+
- name: "Set env"
293+
run: |
294+
echo "APP_CONTAINER_HOME=${{ runner.temp }}/app_home" >> $GITHUB_ENV
295+
- name: "Checkout"
296+
uses: "actions/checkout@v4"
297+
- name: "Restore dependencies cache"
298+
uses: actions/cache@v4
299+
with:
300+
path: |
301+
${{ env.APP_CONTAINER_HOME }}/.composer/cache/
302+
${{ env.APP_CONTAINER_HOME }}/.npm/_cacache/
303+
key: "app_home_deps-8.3-${{ hashFiles('composer.lock', 'package-lock.json') }}"
304+
restore-keys: |
305+
app_home_deps-8.3-
306+
app_home_deps-
307+
- name: "Initialize containers"
308+
run: |
309+
.github/actions/init_containers-start.sh
310+
- name: "Show versions"
311+
run: |
312+
.github/actions/init_show-versions.sh
313+
- name: "Build GLPI's dependencies and translations"
314+
run: |
315+
docker compose exec -T app .github/actions/init_build.sh
316+
- name: Install Playwright dependencies
317+
run: docker compose exec -T app npm ci
318+
- name: Install Playwright Browsers
319+
run: docker compose exec -T --user=root app sudo -E npx playwright install chromium --with-deps
320+
- name: "Install DB tests"
321+
if: ${{ !cancelled() }}
322+
run: |
323+
docker compose exec -T app .github/actions/test_install.sh
324+
- name: Lint tests
325+
if: ${{ !cancelled() }}
326+
run: docker compose exec -T app npx tsc -p tsconfig.json --noEmit
327+
- name: Run Playwright tests
328+
if: ${{ !cancelled() }}
329+
run: docker compose exec -T app npx playwright test
330+
- uses: actions/upload-artifact@v4
331+
if: ${{ !cancelled() }}
332+
with:
333+
name: playwright-report
334+
path: playwright-report/
335+
retention-days: 30
336+
- name: Publish test summary results
337+
if: ${{ !cancelled() }}
338+
run: npx github-actions-ctrf ctrf/ctrf-report.json

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ phpstan.neon
4949
*.phar
5050
.env
5151
/resources/.illustrations_translations.php
52+
53+
# Playwright
54+
ctrf/
55+
/tests/playwright/test-results/
56+
/playwright-report/
57+
/blob-report/
58+
/playwright/.cache/
59+
/tests/playwright/.env.local
60+
!/tests/playwright/.env

eslint.config.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import globals from "globals";
33
import vue from "eslint-plugin-vue";
44
import js from "@eslint/js";
55
import cypress from "eslint-plugin-cypress/flat";
6+
import playwright from 'eslint-plugin-playwright';
7+
import tsParser from "@typescript-eslint/parser";
68

79
export default [
810
{
@@ -23,6 +25,20 @@ export default [
2325
],
2426
},
2527
js.configs.recommended,
28+
{
29+
files: ["tests/playwright/**/*.ts"],
30+
languageOptions: {
31+
parser: tsParser,
32+
parserOptions: {
33+
project: "./tsconfig.json",
34+
ecmaVersion: 'latest',
35+
sourceType: "module"
36+
},
37+
globals: {
38+
...globals.node,
39+
}
40+
},
41+
},
2642
{
2743
languageOptions: {
2844
ecmaVersion: 13,
@@ -159,5 +175,14 @@ export default [
159175
"rules": {
160176
"prefer-template": "off",
161177
}
178+
},
179+
{
180+
...playwright.configs['flat/recommended'],
181+
files: ['tests/playwright/**'],
182+
rules: {
183+
...playwright.configs['flat/recommended'].rules,
184+
"playwright/no-force-option": "error",
185+
"playwright/no-raw-locators": "error",
186+
},
162187
}
163188
];

0 commit comments

Comments
 (0)