π‘οΈ Comprehensive E2E Testing Framework
Functional β’ Performance β’ Security Testing with Docker
- Tentang Proyek
- Fitur Utama
- Struktur Proyek
- Prasyarat
- Instalasi & Setup
- Cara Menjalankan Test
- Memilih Test Suite
- Melihat Report
- Konfigurasi
- Penjelasan Test Modules
Cypress Sentinel adalah framework automated testing yang comprehensive, dirancang untuk menjalankan:
- β Functional Testing (UI, Link, Form Validation)
- β‘ Performance Testing (TTFB, Lighthouse Audit)
- π Security Testing (Header Check, XSS Validation)
Semua test berjalan dalam Docker Container menggunakan headless Chrome browser dan menghasilkan laporan HTML tunggal dengan embedded screenshots.
| Fitur | Deskripsi |
|---|---|
| π³ Dockerized | Fully containerized menggunakan cypress/included image |
| π Mochawesome Report | HTML report dengan embedded screenshots & inline assets |
| π Modular Test Structure | Terpisah berdasarkan kategori: functional, performance, security |
| ποΈ Selective Execution | Pilih test suite via environment variable |
| πΈ Auto Screenshots | Screenshot otomatis pada failure + manual trigger |
| π¬ No Video Recording | Video dimatikan untuk menghemat space |
| β‘ Lighthouse Integration | Performance audit dengan threshold scoring |
| π Security Audit | Header validation & XSS testing |
cypress-sentinel/
βββ cypress/
β βββ e2e/
β β βββ functional/ # π’ Functional Tests
β β β βββ ui_test.cy.js
β β βββ performance/ # π‘ Performance Tests
β β β βββ perf_test.cy.js
β β βββ security/ # π΄ Security Tests
β β βββ sec_test.cy.js
β βββ fixtures/ # Test data
β β βββ example.json
β βββ screenshots/ # Auto-generated screenshots
β βββ support/
β βββ commands.js # Custom commands
β βββ e2e.js # Global config & plugins
βββ reports/ # π HTML Reports (generated)
βββ node_modules/ # Dependencies (auto-installed)
βββ .env.example # Environment config template
βββ cypress.config.js # Cypress configuration
βββ docker-compose.yml # Docker orchestration
βββ package.json # NPM dependencies
βββ README.md # This file
Pastikan sistem Anda telah terinstall:
- Docker (v20.10+)
- Docker Compose (v2.0+)
βΉοΈ Note: Tidak perlu install Node.js atau Cypress secara lokal. Semua dependencies akan di-handle oleh Docker container.
git clone <repository-url>
cd cypress-sentinelcp .env.example .envEdit file .env sesuai kebutuhan:
# Base URL untuk testing
BASE_URL=https://www.google.com
# Pilih test suite (lihat section "Memilih Test Suite" di bawah)
SPEC_PATTERN=cypress/e2e/**/*.cy.jsTidak ada langkah instalasi tambahan. Docker akan mengurus semuanya.
docker-compose up- Docker akan pull image
cypress/included:13.6.2(jika belum ada) - Install NPM dependencies secara otomatis
- Menjalankan Cypress test dalam headless Chrome
- Generate laporan HTML di folder
reports/ - Container akan stop otomatis setelah test selesai
docker-compose downAnda bisa memilih test mana yang akan dijalankan dengan mengubah environment variable SPEC_PATTERN di file .env:
SPEC_PATTERN=cypress/e2e/**/*.cy.jsdocker-compose upSPEC_PATTERN=cypress/e2e/functional/**/*.cy.jsdocker-compose upSPEC_PATTERN=cypress/e2e/performance/**/*.cy.jsdocker-compose upSPEC_PATTERN=cypress/e2e/security/**/*.cy.jsdocker-compose upSPEC_PATTERN=cypress/e2e/functional/**/*.cy.js docker-compose upSetelah test selesai, laporan HTML akan tersedia di:
reports/
βββ index.html
Option A: Langsung buka di browser
open reports/index.htmlatau pada Linux:
xdg-open reports/index.htmlOption B: Via HTTP Server
cd reports
python3 -m http.server 8080Kemudian buka: http://localhost:8080
Report berisi:
- β Test Results (Pass/Fail)
- πΈ Embedded Screenshots (langsung di HTML, tidak perlu file terpisah)
- β±οΈ Execution Time
- π Charts & Statistics
- π Inline Assets (bisa dikirim via email/PDF)
File konfigurasi utama Cypress:
| Konfigurasi | Nilai | Keterangan |
|---|---|---|
video |
false |
Video recording DIMATIKAN |
screenshotOnRunFailure |
true |
Screenshot otomatis saat test fail |
reporter |
cypress-mochawesome-reporter |
HTML reporter dengan embedded screenshots |
embeddedScreenshots |
true |
Screenshot embedded di HTML |
inlineAssets |
true |
Assets inline (single file HTML) |
| Environment Variable | Default | Keterangan |
|---|---|---|
BASE_URL |
https://www.google.com |
Target URL untuk testing |
SPEC_PATTERN |
cypress/e2e/**/*.cy.js |
Pattern test files yang dijalankan |
CYPRESS_video |
false |
Disable video recording |
Dependencies yang digunakan:
cypress- Core testing frameworkcypress-mochawesome-reporter- HTML reportingcypress-audit- Lighthouse integrationlighthouse- Performance auditingmochawesome- Base reportermochawesome-merge- Merge multiple reportsmochawesome-report-generator- HTML generator
Tujuan: Validasi UI dan interaksi user
Test Cases:
- Buka Google homepage
- Ketik keyword di search box
- Submit dan validasi hasil search
- Validasi elemen penting (logo, button)
- Screenshot setiap step
Command Custom:
cy.takeNamedScreenshot('screenshot-name');Tujuan: Mengukur performance website
Test Cases:
-
TTFB Check (Time To First Byte)
- Target: < 500ms
- Mengukur response time server
-
Lighthouse Audit
- Minimum score: 80
- Metrics:
- Performance
- Accessibility
- Best Practices
- SEO
-
Page Load Metrics
- Page load time
- DOM ready time
- DNS lookup time
Command Custom:
cy.checkTTFB(url, maxTTFB);
cy.lighthouse(thresholds);Tujuan: Validasi aspek keamanan website
Test Cases:
-
Security Headers Check
- X-Frame-Options
- X-Content-Type-Options
- Strict-Transport-Security
- Content-Security-Policy
-
HTTPS Validation
- Memastikan protokol HTTPS digunakan
-
XSS Input Validation
- Test dengan berbagai XSS payloads:
<script>alert("XSS")</script> <img src=x onerror=alert("XSS")> javascript:alert("XSS")
- Memastikan input di-sanitize dengan benar
- Test dengan berbagai XSS payloads:
-
Cookie Security
- Validate Secure flag
- Validate HttpOnly flag
- Validate SameSite attribute
Command Custom:
cy.checkSecurityHeaders(url);-
Edit Test Lokal
File test di foldercypress/bisa diedit langsung. Docker mount sebagai volume, jadi perubahan langsung terdeteksi. -
Debug Mode
Untuk melihat browser (non-headless), jalankan tanpa Docker:npm install npm run cy:open
-
Quick Test Single File
SPEC_PATTERN=cypress/e2e/functional/ui_test.cy.js docker-compose up
- Update
BASE_URLke target aplikasi - Sesuaikan threshold Lighthouse sesuai kebutuhan
- Tambahkan test cases sesuai business logic
- Setup CI/CD integration (Jenkins, GitLab CI, GitHub Actions)
- Configure email notification untuk report
Solusi: Hapus node_modules folder dan restart Docker:
rm -rf node_modules
docker-compose up --buildSolusi: Lighthouse butuh resource cukup. Tambah memory limit di docker-compose.yml:
deploy:
resources:
limits:
memory: 6GSolusi: Pastikan konfigurasi di cypress.config.js:
reporterOptions: {
embeddedScreenshots: true,
inlineAssets: true
}MIT License - Feel free to use and modify
Senior QA DevOps Engineer
π Happy Testing! π
Built with β€οΈ using Cypress + Docker