#!/bin/bash # Playwright Setup and Test Runner Script # This script installs Playwright and runs tests for Tasks 1-10 set -e echo "================================================" echo "Tilbudgivern - Playwright Test Suite Setup" echo "================================================" echo "" # Check if Node.js is installed if ! command -v node &> /dev/null; then echo "❌ Node.js is not installed" exit 1 fi echo "✅ Node.js version: $(node --version)" echo "" # Install Playwright if not already installed if ! npm list @playwright/test &> /dev/null; then echo "📦 Installing Playwright..." npm install --save-dev @playwright/test echo "✅ Playwright installed" else echo "✅ Playwright already installed" fi echo "" echo "================================================" echo "Available Commands:" echo "================================================" echo "" echo "1. Run all tests:" echo " npm run test:pw" echo "" echo "2. Run tests in UI mode (recommended for development):" echo " npm run test:pw:ui" echo "" echo "3. Run tests in headed mode (see browser):" echo " npm run test:pw:headed" echo "" echo "4. Run tests for specific task:" echo " npm run test:pw -- --grep 'Task 1'" echo "" echo "5. View test results:" echo " npm run test:pw:report" echo "" echo "6. Debug tests:" echo " npm run test:pw:debug" echo "" echo "================================================" echo "" # Add scripts to package.json if they don't exist if ! grep -q '"test:pw"' package.json; then echo "📝 Adding test scripts to package.json..." # Backup original cp package.json package.json.backup # Add scripts (using sed) sed -i '/"scripts": {/a\ "test:pw": "playwright test",\ "test:pw:ui": "playwright test --ui",\ "test:pw:headed": "playwright test --headed",\ "test:pw:report": "playwright show-report",\ "test:pw:debug": "playwright test --debug",' package.json echo "✅ Test scripts added" else echo "✅ Test scripts already present" fi echo "" echo "Ready to run tests! 🚀" echo "" echo "Start with: npm run test:pw:ui"