Contoh Repo Dummy Playwright
Tentu! Berikut ini adalah struktur dan isi lengkap dari sebuah repo dummy Playwright, yang bisa langsung kamu pakai untuk integrasi dengan Jenkins:
๐ Struktur Folder Dummy Project
playwright-dummy/
โโโ tests/
โ โโโ example.spec.ts
โโโ playwright.config.ts
โโโ package.json
โโโ .gitignore
โโโ Jenkinsfile
๐ฆ 1. package.json
{
"name": "playwright-dummy",
"version": "1.0.0",
"description": "Dummy Playwright project for Jenkins integration test",
"scripts": {
"test": "npx playwright test",
"report": "npx playwright show-report"
},
"devDependencies": {
"@playwright/test": "^1.45.0"
}
}
๐ 2. tests/example.spec.ts
import { test, expect } from '@playwright/test';
test('Dummy test - check example.com title', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle('Example Domain');
});
โ๏ธ 3. playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
timeout: 30000,
retries: 0,
use: {
headless: true,
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true
},
reporter: [['html', { outputFolder: 'playwright-report', open: 'never' }]]
});
๐งพ 4. .gitignore
node_modules/
playwright-report/
๐งช 5. Jenkinsfile
(Declarative Pipeline)
pipeline {
agent any
tools {
nodejs 'NodeJS 18'
}
environment {
CI = 'true'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install dependencies') {
steps {
sh 'npm ci'
sh 'npx playwright install --with-deps'
}
}
stage('Run tests') {
steps {
sh 'npm test'
}
}
stage('Publish report') {
steps {
publishHTML(target: [
reportDir: 'playwright-report',
reportFiles: 'index.html',
reportName: 'Playwright Report',
keepAll: true
])
}
}
}
}
๐ Cara Menggunakan
-
Copy semua isi di atas ke folder baru, misal:
playwright-dummy/
-
Jalankan:
npm install npx playwright install
-
Jalankan test lokal:
npm test npx playwright show-report
-
Push ke Git (misal GitHub atau GitLab)
-
Tambahkan ke Jenkins sebagai pipeline project
-
Klik "Build Now" โ Jenkins akan:
-
Install dep
-
Jalankan test
-
Generate report
-
Tampilkan link "Playwright Report"
-
Untuk ZIP Filenya bis di download playwright-dummy.zip
No Comments