Files
BIPAuto/tests/test_login.py
Misaka_Company e7bbbbc194 refactor(logging): Add optional logging support throughout codebase
Add centralized logging utility and optional logger parameters to all
core functions for better observability and debugging capabilities.

New modules:
- utils/logging.py: Centralized logger configuration with console
  and optional file handlers

Enhanced features:
- Added optional logger parameter to all extractor_core functions
- Added logger support to extractor, excel_converter, and auth modules
- Functions remain silent when logger=None (backward compatible)
- Improved environment variable validation in test files

Documentation:
- Added discrete_material_plan_extractor_core.md with complete API
  reference and usage patterns

Benefits:
- Consistent logging format across all components
- Optional debug output for troubleshooting
- No breaking changes - fully backward compatible
- Better error messages and validation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 16:08:21 +08:00

104 lines
3.2 KiB
Python

"""
Test Yonyou BIP system login functionality
"""
import sys
from pathlib import Path
# Add project root to Python path
PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
from playwright.sync_api import sync_playwright
from utils.auth import login, logout
import os
# Load environment variables
from dotenv import load_dotenv
load_dotenv(PROJECT_ROOT / ".env")
# Configure browser path
browser_path = os.getenv("PLAYWRIGHT_BROWSERS_PATH")
if not browser_path:
raise ValueError("PLAYWRIGHT_BROWSERS_PATH environment variable is required")
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = browser_path
print("=" * 60)
print("Testing Yonyou BIP Login and Logout")
print("=" * 60)
# Display configuration information
print(f"\nConfiguration:")
print(f" URL: {os.getenv('ERP_URL')}")
print(f" Username: {os.getenv('ERP_USERNAME')}")
print(f" Headless: {os.getenv('ERP_HEADLESS')}")
print(f" Ignore HTTPS Errors: {os.getenv('ERP_IGNORE_HTTPS_ERRORS')}")
# Construct complete login URL
base_url = os.getenv('ERP_URL')
if not base_url:
raise ValueError("ERP_URL environment variable is required")
url = f"{base_url.rstrip('/')}/yonbip/resources/uap/rbac/login/main/index.html"
try:
# Get required environment variables
username = os.getenv('ERP_USERNAME')
password = os.getenv('ERP_PASSWORD')
headless = os.getenv('ERP_HEADLESS', 'false').lower() in ('true', '1', 'yes')
ignore_https_errors = os.getenv('ERP_IGNORE_HTTPS_ERRORS', 'true').lower() in ('true', '1', 'yes')
if not username or not password:
raise ValueError("ERP_USERNAME and ERP_PASSWORD environment variables are required")
with sync_playwright() as p:
print("\n[1/5] Starting browser...")
browser, context, page, main_frame = login(
playwright=p,
username=username,
password=password,
url=url,
headless=headless,
ignore_https_errors=ignore_https_errors,
verbose=True
)
print("\n[2/5] Login successful!")
# Wait a moment to observe the page after login
print("\n[3/5] Waiting 3 seconds to observe the page after login...")
import time
time.sleep(3)
# Test logout
print("\n[4/5] Testing logout...")
logout(main_frame, verbose=True)
print("\n[5/5] Logout successful!")
# Wait a moment to observe the page after logout
print("\nWaiting 2 seconds to observe the page after logout...")
time.sleep(2)
print("\n[SUCCESS] Login and logout test completed successfully!")
# Check if auto-close browser
auto_close = os.getenv("ERP_AUTO_CLOSE_BROWSER", "true").lower() in ("true", "1", "yes")
if not auto_close:
print("\n[INFO] Browser will stay open for 10 seconds for manual observation...")
time.sleep(10)
# Close browser
print("\n[CLEANUP] Closing browser session...")
context.close()
browser.close()
except Exception as e:
print(f"\n[ERROR] Login/logout test failed!")
print(f"Error: {e}")
import traceback
traceback.print_exc()
print("\n" + "=" * 60)
print("Test completed")
print("=" * 60)