""" Main Entry Point - LangGraph UI Regression Testing System Hybrid Approach: Screenshots + HF Vision + CSS Extraction """ import os import sys import argparse from datetime import datetime # Load environment variables from .env file manually def load_env_file(env_path: str = ".env"): """Load environment variables from .env file.""" if os.path.exists(env_path): with open(env_path, 'r') as f: for line in f: line = line.strip() if line and not line.startswith('#') and '=' in line: key, value = line.split('=', 1) os.environ[key.strip()] = value.strip() load_env_file() from state_schema import create_initial_state, WorkflowState from agents.agent_0_super_agent import agent_0_node from agents.agent_1_design_inspector import agent_1_node from agents.agent_2_website_inspector import agent_2_node from agents.agent_3_difference_analyzer import agent_3_node from screenshot_annotator import annotate_all_screenshots from report_generator import ReportGenerator def get_credentials(): """Get credentials from environment variables.""" figma_key = os.getenv("FIGMA_FILE_KEY", "") figma_token = os.getenv("FIGMA_ACCESS_TOKEN", "") website_url = os.getenv("WEBSITE_URL", "") hf_token = os.getenv("HUGGINGFACE_API_TOKEN", "") if not figma_key: print("āŒ Error: FIGMA_FILE_KEY not set in .env") sys.exit(1) if not figma_token: print("āŒ Error: FIGMA_ACCESS_TOKEN not set in .env") sys.exit(1) if not website_url: print("āŒ Error: WEBSITE_URL not set in .env") sys.exit(1) return figma_key, figma_token, website_url, hf_token def run_workflow(figma_file_key: str, figma_access_token: str, website_url: str, hf_token: str, execution_id: str) -> WorkflowState: """Run the complete workflow.""" # Create initial state state = create_initial_state( figma_file_key=figma_file_key, figma_access_token=figma_access_token, website_url=website_url, hf_token=hf_token, execution_id=execution_id ) print("\n" + "="*60) print("šŸš€ Starting UI Regression Testing Workflow") print("="*60) # Agent 0: Super Agent (Test Plan) print("\nšŸ¤– Agent 0: Super Agent - Generating Test Plan...") agent_0_result = agent_0_node(state) state.test_plan = agent_0_result.get("test_plan", {}) state.test_categories = agent_0_result.get("test_categories", state.test_categories) print(f" āœ“ Test plan generated") # Agent 1: Design Inspector (Figma Screenshots) print("\nšŸŽØ Agent 1: Design Inspector - Capturing Figma Screenshots...") agent_1_result = agent_1_node(state.__dict__) state.design_screenshots = agent_1_result.get("design_screenshots", {}) state.status = agent_1_result.get("status", state.status) if state.status == "design_inspection_failed": print(f" āŒ Agent 1 failed") return state # Agent 2: Website Inspector (Website Screenshots) print("\n🌐 Agent 2: Website Inspector - Capturing Website Screenshots...") agent_2_result = agent_2_node(state.__dict__) state.website_screenshots = agent_2_result.get("website_screenshots", {}) state.status = agent_2_result.get("status", state.status) if state.status == "website_inspection_failed": print(f" āŒ Agent 2 failed") return state # Agent 3: Difference Analyzer (Screenshot Comparison) print("\nšŸ” Agent 3: Difference Analyzer - Analyzing Visual Differences...") agent_3_result = agent_3_node(state.__dict__) state.visual_differences = agent_3_result.get("visual_differences", []) state.similarity_score = agent_3_result.get("similarity_score", 0) state.status = agent_3_result.get("status", state.status) if state.status == "analysis_failed": print(f" āŒ Agent 3 failed") return state # Annotate screenshots print("\nšŸ“ø Annotating Screenshots...") state = annotate_all_screenshots(state) print("\n" + "="*60) print("āœ… Workflow Completed") print("="*60) return state def main(): """Main entry point.""" parser = argparse.ArgumentParser(description="UI Regression Testing System") parser.add_argument("--execution-id", default="", help="Execution ID") parser.add_argument("--debug", action="store_true", help="Enable debug mode") parser.add_argument("--output-dir", default="reports", help="Output directory for reports") args = parser.parse_args() # Print header print("\n" + "="*70) print("šŸš€ UI REGRESSION TESTING SYSTEM (Hybrid Approach)") print("="*70) # Get credentials print("\nšŸ“‹ Configuration:") figma_key, figma_token, website_url, hf_token = get_credentials() print(f" Figma File Key: {figma_key[:20]}...") print(f" Website URL: {website_url}") print(f" Output Directory: {args.output_dir}") print(f" Debug Mode: {args.debug}") print(f" HF Token: {'āœ“ Enabled' if hf_token else 'āœ— Disabled'}") print("\n" + "="*70) # Generate execution ID if not provided execution_id = args.execution_id or f"exec_{datetime.now().strftime('%Y%m%d_%H%M%S')}" # Run workflow try: final_state = run_workflow( figma_file_key=figma_key, figma_access_token=figma_token, website_url=website_url, hf_token=hf_token, execution_id=execution_id ) # Generate reports if final_state.status == "analysis_complete": ReportGenerator.generate_all_reports(final_state, args.output_dir) # Print summary print("\n" + "="*70) print("āœ… EXECUTION COMPLETED SUCCESSFULLY") print("="*70) print(f"\nšŸ“Š Results:") print(f" Total Differences: {len(final_state.visual_differences)}") print(f" High Severity: {len([d for d in final_state.visual_differences if d.severity == 'High'])}") print(f" Medium Severity: {len([d for d in final_state.visual_differences if d.severity == 'Medium'])}") print(f" Low Severity: {len([d for d in final_state.visual_differences if d.severity == 'Low'])}") print(f" Similarity Score: {final_state.similarity_score:.1f}/100") print(f"\nšŸ“ Reports saved to: {args.output_dir}/") print("\n" + "="*70) else: print(f"\nāŒ Workflow failed: {final_state.error_message}") sys.exit(1) except Exception as e: print(f"\nāŒ Error: {str(e)}") import traceback traceback.print_exc() sys.exit(1) if __name__ == "__main__": main()