Add frontend testing - Playwright
This commit is contained in:
112
.github/workflows/playwright.yml
vendored
Normal file
112
.github/workflows/playwright.yml
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
name: Playwright E2E Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
paths:
|
||||
- 'frontend/**'
|
||||
- '.github/workflows/playwright.yml'
|
||||
pull_request:
|
||||
branches: [main, develop]
|
||||
paths:
|
||||
- 'frontend/**'
|
||||
- '.github/workflows/playwright.yml'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: frontend/package-lock.json
|
||||
|
||||
- name: Install frontend dependencies
|
||||
run: npm ci
|
||||
working-directory: ./frontend
|
||||
|
||||
- name: Install Playwright browsers
|
||||
run: npx playwright install --with-deps
|
||||
working-directory: ./frontend
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: npx playwright test
|
||||
working-directory: ./frontend
|
||||
env:
|
||||
CI: true
|
||||
# Add test user credentials as secrets
|
||||
TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }}
|
||||
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
|
||||
|
||||
- name: Upload test results
|
||||
uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: frontend/playwright-report/
|
||||
retention-days: 30
|
||||
|
||||
- name: Upload test videos
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: playwright-videos
|
||||
path: frontend/test-results/
|
||||
retention-days: 7
|
||||
|
||||
- name: Upload screenshots
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: playwright-screenshots
|
||||
path: frontend/test-results/**/*.png
|
||||
retention-days: 7
|
||||
|
||||
- name: Comment PR with test results
|
||||
uses: actions/github-script@v7
|
||||
if: github.event_name == 'pull_request' && always()
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
try {
|
||||
// Read test results
|
||||
const resultsPath = path.join('frontend', 'test-results', 'results.json');
|
||||
|
||||
if (fs.existsSync(resultsPath)) {
|
||||
const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
|
||||
|
||||
const passed = results.stats?.expected || 0;
|
||||
const failed = results.stats?.unexpected || 0;
|
||||
const skipped = results.stats?.skipped || 0;
|
||||
const total = passed + failed + skipped;
|
||||
|
||||
const comment = `## 🎭 Playwright Test Results
|
||||
|
||||
- ✅ **Passed:** ${passed}
|
||||
- ❌ **Failed:** ${failed}
|
||||
- ⏭️ **Skipped:** ${skipped}
|
||||
- 📊 **Total:** ${total}
|
||||
|
||||
${failed > 0 ? '⚠️ Some tests failed. Check the workflow artifacts for details.' : '✨ All tests passed!'}
|
||||
`;
|
||||
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: comment
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Could not post test results comment:', error);
|
||||
}
|
||||
Reference in New Issue
Block a user