#!/usr/bin/env python3 """ E2E Test Scaffolder Scans Next.js pages/app directory and generates Playwright test files with common interactions, Page Object Model classes, and configuration. Usage: python e2e_test_scaffolder.py src/app/ --output e2e/ python e2e_test_scaffolder.py pages/ --include-pom --routes "/login,/dashboard" """ import os import sys import json import argparse import re from pathlib import Path from typing import Dict, List, Optional, Tuple, Set from dataclasses import dataclass, field, asdict from datetime import datetime @dataclass class RouteInfo: """Information about a detected route""" path: str # URL path e.g., /dashboard file_path: str # File system path route_type: str # 'page', 'layout', 'api', 'dynamic' has_params: bool params: List[str] has_form: bool has_auth: bool interactions: List[str] @dataclass class TestSpec: """A Playwright test specification""" route: RouteInfo test_cases: List[str] imports: Set[str] = field(default_factory=set) @dataclass class PageObject: """Page Object Model class definition""" name: str route: str locators: List[Tuple[str, str, str]] # (name, selector, description) methods: List[Tuple[str, str]] # (name, code) class RouteScanner: """Scans Next.js directories for routes""" # Pattern to detect page files PAGE_PATTERNS = { 'page.tsx', 'page.ts', 'page.jsx', 'page.js', # App Router 'index.tsx', 'index.ts', 'index.jsx', 'index.js' # Pages Router } # Patterns indicating specific features FORM_PATTERNS = [ r'