#!/usr/bin/env python3
"""
Single User Test - Assessments Flow

Tests the Assessments flow with 1 user (visible browser) to verify everything works.
"""
import sys
from pathlib import Path

project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))

from tests.load_tests.test_generic_load_assessments import GenericAssessmentsLoadTest


def main():
    """Run single user Assessments test"""
    print(f"\n{'='*80}")
    print(f"🧪 SINGLE USER TEST - Assessments Flow")
    print(f"{'='*80}\n")
    
    # Create and run load test with 1 user (visible browser)
    load_test = GenericAssessmentsLoadTest("Single User Assessments Verification")
    result = load_test.run_load_test(
        num_users=1,
        ramp_up_time=0,
        max_workers=1,
        headless=False  # Visible browser so you can see what's happening
    )
    
    summary = result['summary']
    
    # Print detailed result
    print(f"\n{'='*80}")
    print(f"📋 DETAILED RESULT")
    print(f"{'='*80}")
    if summary.results:
        user_result = summary.results[0]
        print(f"\n✅ Status: {user_result.status.value}")
        print(f"⏱️  Duration: {user_result.total_duration:.2f} seconds")
        print(f"\n📝 Steps Completed:")
        for step in user_result.steps_completed:
            print(f"   • {step}")
        
        if user_result.page_metrics:
            print(f"\n📊 Page Metrics:")
            print(f"   • Page Load Time: {user_result.page_metrics.page_load_time:.2f}s")
            print(f"   • DOM Ready Time: {user_result.page_metrics.dom_ready_time:.2f}s")
            print(f"   • Scroll Smooth: {'✅ Yes' if user_result.page_metrics.scroll_smooth else '❌ No'}")
            print(f"   • Scroll Time: {user_result.page_metrics.scroll_time:.2f}s")
            print(f"   • Elements Loaded: {user_result.page_metrics.elements_loaded}")
            print(f"   • Render Complete: {'✅ Yes' if user_result.page_metrics.render_complete else '❌ No'}")
        
        if user_result.errors:
            print(f"\n❌ Errors:")
            for error in user_result.errors:
                print(f"   • {error}")
    
    print(f"\n{'='*80}")
    
    # Final verdict
    if summary.success_rate == 100:
        print("✅ TEST PASSED - All steps completed successfully!")
        sys.exit(0)
    else:
        print("❌ TEST FAILED - Some steps did not complete")
        sys.exit(1)


if __name__ == "__main__":
    main()






