Skip to main content

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

  1. Copy semua isi di atas ke folder baru, misal: playwright-dummy/

  2. Jalankan:

    npm install
    npx playwright install
    
  3. Jalankan test lokal:

    npm test
    npx playwright show-report
    
  4. Push ke Git (misal GitHub atau GitLab)

  5. Tambahkan ke Jenkins sebagai pipeline project

  6. Klik "Build Now" โ†’ Jenkins akan:

    • Install dep

    • Jalankan test

    • Generate report

    • Tampilkan link "Playwright Report"


Untuk ZIP Filenya bis di download playwright-dummy.zip