Skip to content

Repository files navigation

SwagLab Playwright Test Automation

Automated E2E testing for SauceDemo's SwagLab application using Playwright with TypeScript, featuring encrypted credentials, video recording, and comprehensive artifact management.

πŸš€ Features

  • Cross-browser testing - Chromium, Firefox, WebKit
  • TypeScript - Type-safe test code
  • Encrypted credentials - AES-256 encryption for sensitive data
  • Video recording - Full test execution videos (WebM format)
  • Screenshot capture - Timestamped screenshots at key test points
  • HTML reports - Interactive test reports with embedded assets
  • Timestamped artifacts - Organized test results with historical preservation
  • CI/CD ready - GitHub Actions integration for automated testing

πŸ“‹ Project Structure

SwagLab/
β”œβ”€β”€ .github/workflows/
β”‚   └── playwright.yml          # GitHub Actions CI/CD pipeline
β”œβ”€β”€ config/
β”‚   └── credentials.ts          # Encrypted credential management (AES-256)
β”œβ”€β”€ hooks/
β”‚   └── setup.ts                # Playwright setup hooks
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ Navigate.spec.ts        # Login and checkout tests
β”‚   └── AddAllItems.spec.ts     # Full cart checkout test
β”œβ”€β”€ Screenshots/                # Timestamped screenshot folders
β”‚   └── [DDMMYY_HHMMSS]/
β”œβ”€β”€ Videos/                     # Timestamped video folders
β”‚   └── [DDMMYY_HHMMSS]/
β”œβ”€β”€ Reports/                    # Timestamped HTML reports
β”‚   └── [DDMMYY_HHMMSS]/
β”œβ”€β”€ playwright.config.ts        # Playwright configuration
β”œβ”€β”€ tsconfig.json              # TypeScript configuration
β”œβ”€β”€ package.json               # Dependencies
β”œβ”€β”€ archiveReports.ts          # Report archival utility
└── organizeVideos.ts          # Video organization utility

πŸ› οΈ Installation

Prerequisites

  • Node.js 18+
  • Git
  • Windows 10+ (or Linux/macOS with appropriate adjustments)

Setup

  1. Clone the repository
git clone https://github.com/Kumarg3/swaglabtest.git
cd SwagLab
  1. Install dependencies
npm install
  1. Install Playwright browsers
npx playwright install
  1. Configure credentials (optional) Edit config/credentials.ts to update encrypted credentials as needed.

πŸ” Security

Encrypted Credentials

Credentials are encrypted using AES-256-CBC with SHA-256 key derivation:

  • Default credentials stored in: config/credentials.ts
  • Encrypted format: IV:ENCRYPTED_DATA (base64-encoded)
  • Access at runtime: Use getCredentials() function
import { getCredentials } from './config/credentials';

const { username, password } = getCredentials();
// Credentials are only decrypted at runtime

πŸ§ͺ Running Tests

Run all tests

npm test

Run specific test file

npx playwright test tests/Navigate.spec.ts

Run with headed browser

npx playwright test --headed

Run with debug mode

npx playwright test --debug

Generate and view HTML report

npm run show:report

πŸ“Š Test Artifacts

Organization Structure

All test artifacts are organized by execution timestamp (format: DDMMYY_HHMMSS):

Screenshots/
β”œβ”€β”€ DDMMYY_HHMMSS/          # Test run folder
β”‚   β”œβ”€β”€ DDMMYY_HHMMSS_Login_PASS.png
β”‚   β”œβ”€β”€ DDMMYY_HHMMSS_Checkout_PASS.png
β”‚   └── ...

Videos/
β”œβ”€β”€ DDMMYY_HHMMSS/
β”‚   └── DDMMYY_HHMMSS_video.webm

Reports/
β”œβ”€β”€ DDMMYY_HHMMSS/
β”‚   β”œβ”€β”€ index.html          # Interactive HTML report
β”‚   └── data/              # Report assets (screenshots, videos)

Post-Test Utilities

Archive reports:

npx ts-node archiveReports.ts

Organize videos:

npx ts-node organizeVideos.ts

πŸ”„ CI/CD Pipeline

GitHub Actions automatically:

  1. On every push/PR:

    • Checks out code
    • Installs dependencies
    • Installs Playwright browsers
    • Runs all tests
    • Organizes videos and reports
    • Uploads artifacts (30-day retention)
    • Comments on PRs with test results
  2. Scheduled daily runs:

    • Runs at 2 AM UTC
    • Maintains historical test data

View Pipeline

πŸ“ Test Files

Navigate.spec.ts

  • Test 1: Login to SauceDemo
  • Test 2: Login and checkout single item (Bike Light)
  • Features: Encrypted credentials, screenshots, report attachment

AddAllItems.spec.ts

  • Test: Add all 6 items to cart and complete checkout
  • Features: Full video recording, multiple checkpoints, random checkout info
  • Artifacts: 5 checkpoint screenshots + full test video

πŸ“ˆ Playwright Configuration

  • Browser: Chromium (configurable in playwright.config.ts)
  • Video: Enabled for all tests (WebM format)
  • Screenshots: On failure + key test points
  • Trace: On first retry
  • Timeout: 30 seconds per test
  • Retries: 0 (configurable)

πŸ› Troubleshooting

Credentials not decrypting

  • Check config/credentials.ts encryption key
  • Verify environment variable is set (if using custom key)

No screenshots in reports

  • Ensure embedAssets: true in playwright.config.ts
  • Check screenshot directory permissions

Videos not organizing

  • Run: npx ts-node organizeVideos.ts manually
  • Verify test-results/ directory exists

Tests timing out

  • Increase timeout in playwright.config.ts
  • Check network connectivity
  • Verify SauceDemo site is accessible

πŸ“¦ Dependencies

  • @playwright/test - Test framework
  • typescript - Type safety
  • Node.js built-ins - crypto, fs, path for encryption & file management

πŸ“š Resources

πŸ‘€ Author

Kumar G (kumarg3)
Email: fastkumar09@gmail.com

πŸ“„ License

Private Repository - All rights reserved


Last Updated: April 4, 2026
Test Framework: Playwright v1.40+
TypeScript: v5.0+

About

test framework for playwright TS

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages