555 lines
17 KiB
Python
555 lines
17 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Beispiel-Skript für den Flask HTML-Formular Test Automator
|
|
=========================================================
|
|
|
|
Dieses Skript demonstriert verschiedene Anwendungsfälle des Form Test Automators
|
|
speziell für das MYP (Manage Your Printers) System.
|
|
|
|
Autor: Till Tomczak
|
|
Mercedes-Benz Projektarbeit MYP
|
|
"""
|
|
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Form Test Automator importieren
|
|
try:
|
|
from form_test_automator import HTMLFormTestAutomator, TestStatus
|
|
except ImportError:
|
|
print("❌ Kann form_test_automator nicht importieren. Stelle sicher, dass die Datei im gleichen Verzeichnis ist.")
|
|
sys.exit(1)
|
|
|
|
|
|
async def test_myp_login_form():
|
|
"""
|
|
Testet das MYP Login-Formular umfassend.
|
|
"""
|
|
print("🔐 Teste MYP Login-Formular...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
# 1. Login-Formular mit gültigen Daten testen
|
|
valid_results = await automator.test_form(
|
|
url="/login",
|
|
form_selector="#login-form",
|
|
test_data={
|
|
"username": "admin",
|
|
"password": "admin123"
|
|
},
|
|
test_scenarios=["valid"]
|
|
)
|
|
|
|
# 2. Ungültige Login-Versuche testen
|
|
invalid_results = await automator.test_form(
|
|
url="/login",
|
|
form_selector="#login-form",
|
|
test_data={
|
|
"username": "wronguser",
|
|
"password": "wrongpass"
|
|
},
|
|
test_scenarios=["invalid"]
|
|
)
|
|
|
|
# 3. Accessibility und Responsive Design
|
|
accessibility_results = await automator.test_form(
|
|
url="/login",
|
|
form_selector="#login-form",
|
|
test_scenarios=["accessibility", "responsive"]
|
|
)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_login_test")
|
|
print(f"📊 Login-Test Report: {report_path}")
|
|
|
|
return valid_results + invalid_results + accessibility_results
|
|
|
|
|
|
async def test_myp_printer_registration():
|
|
"""
|
|
Testet das Drucker-Registrierungs-Formular.
|
|
"""
|
|
print("🖨️ Teste Drucker-Registrierung...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
# Verschiedene Drucker-Konfigurationen testen
|
|
printer_configs = [
|
|
{
|
|
"name": "Prusa i3 MK3S+",
|
|
"ip_address": "192.168.1.100",
|
|
"tapo_ip": "192.168.1.200",
|
|
"location": "Werkstatt A",
|
|
"description": "Hochpräzisionsdrucker für Prototypen"
|
|
},
|
|
{
|
|
"name": "Ender 3 Pro",
|
|
"ip_address": "192.168.1.101",
|
|
"tapo_ip": "192.168.1.201",
|
|
"location": "Werkstatt B",
|
|
"description": "Robuster Drucker für größere Teile"
|
|
}
|
|
]
|
|
|
|
all_results = []
|
|
|
|
for config in printer_configs:
|
|
print(f" 📋 Teste Konfiguration: {config['name']}")
|
|
|
|
results = await automator.test_form(
|
|
url="/admin/add_printer",
|
|
form_selector="#add-printer-form",
|
|
test_data=config,
|
|
test_scenarios=["valid", "validations"]
|
|
)
|
|
all_results.extend(results)
|
|
|
|
# Edge Cases für IP-Adressen testen
|
|
edge_cases = [
|
|
{"ip_address": "999.999.999.999"}, # Ungültige IP
|
|
{"ip_address": "192.168.1"}, # Unvollständige IP
|
|
{"ip_address": "localhost"}, # Hostname statt IP
|
|
{"name": ""}, # Leerer Name
|
|
{"name": "x" * 500} # Zu langer Name
|
|
]
|
|
|
|
for edge_case in edge_cases:
|
|
print(f" 🔍 Teste Edge Case: {edge_case}")
|
|
|
|
edge_results = await automator.test_form(
|
|
url="/admin/add_printer",
|
|
form_selector="#add-printer-form",
|
|
test_data=edge_case,
|
|
test_scenarios=["edge_cases"]
|
|
)
|
|
all_results.extend(edge_results)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_printer_registration_test")
|
|
print(f"📊 Drucker-Registrierung Report: {report_path}")
|
|
|
|
return all_results
|
|
|
|
|
|
async def test_myp_job_submission():
|
|
"""
|
|
Testet das Druckauftrags-Formular.
|
|
"""
|
|
print("📋 Teste Druckauftrags-Formular...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
# Standard-Druckauftrag testen
|
|
job_data = {
|
|
"title": "Prototyp Gehäuse v2.1",
|
|
"description": "Gehäuse für neuen Sensor, benötigt hohe Präzision",
|
|
"priority": "high",
|
|
"material": "PLA",
|
|
"infill": "20",
|
|
"layer_height": "0.2",
|
|
"estimated_time": "4:30",
|
|
"notes": "Bitte mit Support-Strukturen drucken"
|
|
}
|
|
|
|
# File-Upload simulieren (falls unterstützt)
|
|
# job_data["file"] = "test_models/gehaeuse_v2.stl"
|
|
|
|
results = await automator.test_form(
|
|
url="/new_job",
|
|
form_selector="#job-form",
|
|
test_data=job_data,
|
|
test_scenarios=["valid", "validations", "dynamic"]
|
|
)
|
|
|
|
# Verschiedene Prioritäten testen
|
|
priorities = ["urgent", "high", "normal", "low"]
|
|
|
|
for priority in priorities:
|
|
print(f" ⚡ Teste Priorität: {priority}")
|
|
|
|
priority_test_data = job_data.copy()
|
|
priority_test_data["priority"] = priority
|
|
|
|
priority_results = await automator.test_form(
|
|
url="/new_job",
|
|
form_selector="#job-form",
|
|
test_data=priority_test_data,
|
|
test_scenarios=["valid"]
|
|
)
|
|
results.extend(priority_results)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_job_submission_test")
|
|
print(f"📊 Druckauftrags Report: {report_path}")
|
|
|
|
return results
|
|
|
|
|
|
async def test_myp_guest_access():
|
|
"""
|
|
Testet das Gast-Zugangs-System (OTP-basiert).
|
|
"""
|
|
print("👤 Teste Gast-Zugang...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
# 1. Gast-Anfrage erstellen
|
|
guest_request_data = {
|
|
"name": "Max Mustermann",
|
|
"email": "max.mustermann@mercedes-benz.com",
|
|
"department": "Entwicklung",
|
|
"reason": "Prototyp für neues Projekt benötigt",
|
|
"requested_time": "2024-06-20T14:00"
|
|
}
|
|
|
|
request_results = await automator.test_form(
|
|
url="/guest_request",
|
|
form_selector="#guest-request-form",
|
|
test_data=guest_request_data,
|
|
test_scenarios=["valid", "validations"]
|
|
)
|
|
|
|
# 2. OTP-Eingabe simulieren (falls OTP bekannt)
|
|
# otp_results = await automator.test_form(
|
|
# url="/guest/otp",
|
|
# form_selector="#otp-form",
|
|
# test_data={"otp": "123456"},
|
|
# test_scenarios=["valid", "invalid"]
|
|
# )
|
|
|
|
# 3. Verschiedene Email-Formate testen
|
|
email_variants = [
|
|
"test@mercedes-benz.com",
|
|
"test.user@daimler.com",
|
|
"invalid-email", # Ungültig
|
|
"test@external.com", # Externes Domain
|
|
"" # Leer
|
|
]
|
|
|
|
for email in email_variants:
|
|
print(f" 📧 Teste Email: {email}")
|
|
|
|
email_test_data = guest_request_data.copy()
|
|
email_test_data["email"] = email
|
|
|
|
email_results = await automator.test_form(
|
|
url="/guest_request",
|
|
form_selector="#guest-request-form",
|
|
test_data=email_test_data,
|
|
test_scenarios=["validations"]
|
|
)
|
|
request_results.extend(email_results)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_guest_access_test")
|
|
print(f"📊 Gast-Zugang Report: {report_path}")
|
|
|
|
return request_results
|
|
|
|
|
|
async def test_myp_settings_forms():
|
|
"""
|
|
Testet verschiedene Einstellungs-Formulare.
|
|
"""
|
|
print("⚙️ Teste Einstellungs-Formulare...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
all_results = []
|
|
|
|
# 1. Benutzer-Profil-Einstellungen
|
|
profile_data = {
|
|
"display_name": "Till Tomczak",
|
|
"email": "till.tomczak@mercedes-benz.com",
|
|
"notification_email": "true",
|
|
"notification_browser": "true",
|
|
"language": "de",
|
|
"timezone": "Europe/Berlin"
|
|
}
|
|
|
|
profile_results = await automator.test_form(
|
|
url="/profile",
|
|
form_selector="#profile-form",
|
|
test_data=profile_data,
|
|
test_scenarios=["valid", "validations"]
|
|
)
|
|
all_results.extend(profile_results)
|
|
|
|
# 2. System-Einstellungen (Admin)
|
|
system_data = {
|
|
"max_concurrent_jobs": "3",
|
|
"default_job_timeout": "480",
|
|
"auto_cleanup_days": "30",
|
|
"maintenance_mode": "false",
|
|
"email_notifications": "true",
|
|
"log_level": "INFO"
|
|
}
|
|
|
|
system_results = await automator.test_form(
|
|
url="/admin/settings",
|
|
form_selector="#system-settings-form",
|
|
test_data=system_data,
|
|
test_scenarios=["valid", "edge_cases"]
|
|
)
|
|
all_results.extend(system_results)
|
|
|
|
# 3. Tapo-Controller-Einstellungen
|
|
tapo_data = {
|
|
"device_ip": "192.168.1.200",
|
|
"username": "admin",
|
|
"password": "tapo_password",
|
|
"auto_power_on": "true",
|
|
"auto_power_off": "true",
|
|
"power_off_delay": "300"
|
|
}
|
|
|
|
tapo_results = await automator.test_form(
|
|
url="/admin/tapo_settings",
|
|
form_selector="#tapo-form",
|
|
test_data=tapo_data,
|
|
test_scenarios=["valid", "validations"]
|
|
)
|
|
all_results.extend(tapo_results)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_settings_test")
|
|
print(f"📊 Einstellungen Report: {report_path}")
|
|
|
|
return all_results
|
|
|
|
|
|
async def test_myp_responsive_design():
|
|
"""
|
|
Testet alle wichtigen Formulare auf verschiedenen Geräten.
|
|
"""
|
|
print("📱 Teste Responsive Design...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
# Wichtige Formulare für Responsive Tests
|
|
important_forms = [
|
|
"/login",
|
|
"/new_job",
|
|
"/guest_request",
|
|
"/profile"
|
|
]
|
|
|
|
# Test-Geräte
|
|
devices = [
|
|
"iPhone SE", # Kleine Mobile
|
|
"iPhone 12", # Standard Mobile
|
|
"iPad", # Tablet
|
|
"Desktop 1280x720", # Standard Desktop
|
|
"Desktop 1920x1080" # Large Desktop
|
|
]
|
|
|
|
all_results = []
|
|
|
|
for url in important_forms:
|
|
print(f" 📋 Teste {url} auf allen Geräten...")
|
|
|
|
responsive_results = await automator.test_form_on_devices(url, devices)
|
|
all_results.extend(responsive_results)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_responsive_test")
|
|
print(f"📊 Responsive Design Report: {report_path}")
|
|
|
|
return all_results
|
|
|
|
|
|
async def test_myp_accessibility():
|
|
"""
|
|
Führt umfassende Accessibility-Tests für alle MYP-Formulare durch.
|
|
"""
|
|
print("♿ Teste Accessibility...")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=True
|
|
) as automator:
|
|
|
|
# Alle wichtigen Seiten für Accessibility
|
|
pages_to_test = [
|
|
"/",
|
|
"/login",
|
|
"/dashboard",
|
|
"/new_job",
|
|
"/printers",
|
|
"/guest_request",
|
|
"/profile",
|
|
"/admin"
|
|
]
|
|
|
|
all_results = []
|
|
|
|
for page in pages_to_test:
|
|
print(f" ♿ Teste Accessibility: {page}")
|
|
|
|
# Alle Formulare auf der Seite finden und testen
|
|
page_results = await automator.test_all_forms_on_page(
|
|
page,
|
|
test_scenarios=["accessibility"]
|
|
)
|
|
all_results.extend(page_results)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("myp_accessibility_test")
|
|
print(f"📊 Accessibility Report: {report_path}")
|
|
|
|
return all_results
|
|
|
|
|
|
async def run_comprehensive_myp_tests():
|
|
"""
|
|
Führt alle Tests für das MYP-System durch.
|
|
"""
|
|
print(f"""
|
|
{'='*70}
|
|
🧪 UMFASSENDE MYP FORMULAR-TESTS
|
|
{'='*70}
|
|
|
|
Testet alle wichtigen Formulare des MYP Systems:
|
|
• Login & Authentifizierung
|
|
• Drucker-Registrierung & -Verwaltung
|
|
• Druckauftrags-Erstellung
|
|
• Gast-Zugangs-System
|
|
• Einstellungen & Konfiguration
|
|
• Responsive Design
|
|
• Accessibility
|
|
|
|
{'='*70}
|
|
""")
|
|
|
|
all_test_results = []
|
|
test_functions = [
|
|
("Login-Formular", test_myp_login_form),
|
|
("Drucker-Registrierung", test_myp_printer_registration),
|
|
("Druckauftrags-Formular", test_myp_job_submission),
|
|
("Gast-Zugang", test_myp_guest_access),
|
|
("Einstellungen", test_myp_settings_forms),
|
|
("Responsive Design", test_myp_responsive_design),
|
|
("Accessibility", test_myp_accessibility)
|
|
]
|
|
|
|
for test_name, test_function in test_functions:
|
|
try:
|
|
print(f"\n{'='*50}")
|
|
print(f"🔄 Starte {test_name}-Tests...")
|
|
print(f"{'='*50}")
|
|
|
|
results = await test_function()
|
|
all_test_results.extend(results)
|
|
|
|
# Kurze Statistik
|
|
passed = len([r for r in results if r.status == TestStatus.PASSED])
|
|
failed = len([r for r in results if r.status == TestStatus.FAILED])
|
|
total = len(results)
|
|
|
|
print(f"✅ {test_name} abgeschlossen: {passed}/{total} Tests bestanden")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Fehler bei {test_name}: {str(e)}")
|
|
|
|
# Gesamt-Statistik
|
|
total_tests = len(all_test_results)
|
|
passed_tests = len([r for r in all_test_results if r.status == TestStatus.PASSED])
|
|
failed_tests = len([r for r in all_test_results if r.status == TestStatus.FAILED])
|
|
success_rate = (passed_tests / total_tests * 100) if total_tests > 0 else 0
|
|
|
|
print(f"""
|
|
{'='*70}
|
|
🎉 ALLE TESTS ABGESCHLOSSEN
|
|
{'='*70}
|
|
|
|
📊 GESAMT-STATISTIK:
|
|
• Gesamt Tests: {total_tests}
|
|
• ✅ Bestanden: {passed_tests} ({passed_tests/total_tests*100:.1f}%)
|
|
• ❌ Fehlgeschlagen: {failed_tests} ({failed_tests/total_tests*100:.1f}%)
|
|
• 🎯 Erfolgsrate: {success_rate:.1f}%
|
|
|
|
💡 Reports wurden im Verzeichnis 'form_test_reports/' erstellt.
|
|
|
|
{'='*70}
|
|
""")
|
|
|
|
return all_test_results
|
|
|
|
|
|
async def demo_single_form_test():
|
|
"""
|
|
Einfaches Beispiel für einen einzelnen Formular-Test.
|
|
"""
|
|
print("🎯 Demo: Einzelner Formular-Test")
|
|
|
|
async with HTMLFormTestAutomator(
|
|
base_url="http://localhost:5000",
|
|
browser="chromium",
|
|
headless=False # Browser-Fenster anzeigen für Demo
|
|
) as automator:
|
|
|
|
# Login-Formular mit sichtbarem Browser testen
|
|
results = await automator.test_form(
|
|
url="/login",
|
|
form_selector="#login-form",
|
|
test_data={
|
|
"username": "demo_user",
|
|
"password": "demo_password"
|
|
},
|
|
test_scenarios=["valid", "invalid", "accessibility"]
|
|
)
|
|
|
|
# Report generieren
|
|
report_path = automator.generate_report("demo_single_test")
|
|
print(f"📊 Demo Report: {report_path}")
|
|
|
|
return results
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 MYP Formular Test Automator - Beispiele")
|
|
print("Verfügbare Tests:")
|
|
print("1. Umfassende Tests (alle Formulare)")
|
|
print("2. Demo Einzeltest (mit sichtbarem Browser)")
|
|
print("3. Nur Login-Test")
|
|
print("4. Nur Responsive-Test")
|
|
|
|
choice = input("\nWähle einen Test (1-4): ").strip()
|
|
|
|
if choice == "1":
|
|
asyncio.run(run_comprehensive_myp_tests())
|
|
elif choice == "2":
|
|
asyncio.run(demo_single_form_test())
|
|
elif choice == "3":
|
|
asyncio.run(test_myp_login_form())
|
|
elif choice == "4":
|
|
asyncio.run(test_myp_responsive_design())
|
|
else:
|
|
print("Führe umfassende Tests aus...")
|
|
asyncio.run(run_comprehensive_myp_tests()) |