🎉 Added new form testing tools and examples to the backend 📚
This commit is contained in:
393
backend/README_FORM_TESTER.md
Normal file
393
backend/README_FORM_TESTER.md
Normal file
@@ -0,0 +1,393 @@
|
|||||||
|
# Flask HTML-Formular Test Automator 🧪
|
||||||
|
|
||||||
|
Ein umfassender Frontend-fokussierter Test-Automator für HTML-Formulare in Flask-Anwendungen. Simuliert echte Browser-Interaktionen und testet die tatsächliche Benutzeroberfläche mit JavaScript-Validierungen, dynamischen Elementen und realistischen User-Interaktionen.
|
||||||
|
|
||||||
|
## 🎯 Hauptmerkmale
|
||||||
|
|
||||||
|
### ✅ **Browser-basiertes Testing**
|
||||||
|
- Echte Browser-Interaktionen (Playwright)
|
||||||
|
- Realistische Mausbewegungen und Tipp-Geschwindigkeiten
|
||||||
|
- JavaScript-Validierungen werden mitgetestet
|
||||||
|
- Dynamische Inhalte und AJAX-Requests
|
||||||
|
|
||||||
|
### ✅ **Intelligente Formular-Erkennung**
|
||||||
|
- Automatisches Scannen aller Formulare auf einer Seite
|
||||||
|
- Erkennung von Feld-Typen und Validierungsregeln
|
||||||
|
- Multi-Step-Formular-Unterstützung
|
||||||
|
- CSRF-Token-Behandlung
|
||||||
|
|
||||||
|
### ✅ **Realistische Test-Daten**
|
||||||
|
- Intelligente Daten-Generierung basierend auf Feld-Attributen
|
||||||
|
- Pattern-basierte Generierung (RegEx-Support)
|
||||||
|
- Edge-Case-Generierung für robuste Tests
|
||||||
|
- Locale-spezifische Daten (Deutsch, Englisch, etc.)
|
||||||
|
|
||||||
|
### ✅ **Umfassende Validierung**
|
||||||
|
- HTML5-Validierungen
|
||||||
|
- Client-Side JavaScript-Validierungen
|
||||||
|
- Visual Feedback (Fehlermeldungen, Icons)
|
||||||
|
- Server-Side Validierung-Tests
|
||||||
|
|
||||||
|
### ✅ **Accessibility-Testing**
|
||||||
|
- ARIA-Attribute-Validierung
|
||||||
|
- Label-Zuordnungs-Tests
|
||||||
|
- Keyboard-Navigation
|
||||||
|
- Farbkontrast-Prüfung
|
||||||
|
- Screen-Reader-Kompatibilität
|
||||||
|
|
||||||
|
### ✅ **Responsive Design Tests**
|
||||||
|
- Multi-Device-Testing (iPhone, iPad, Desktop)
|
||||||
|
- Touch-Interaktions-Tests
|
||||||
|
- Viewport-spezifische Validierung
|
||||||
|
- Layout-Stabilitäts-Tests
|
||||||
|
|
||||||
|
### ✅ **Visual Documentation**
|
||||||
|
- Screenshots aller Test-Phasen
|
||||||
|
- Video-Aufzeichnung (optional)
|
||||||
|
- HTML-Reports mit visuellen Beweisen
|
||||||
|
- JSON-Export für Automation
|
||||||
|
|
||||||
|
## 🚀 Installation
|
||||||
|
|
||||||
|
### Schnell-Setup
|
||||||
|
```bash
|
||||||
|
# Setup-Skript ausführen
|
||||||
|
./form_tester_setup.sh
|
||||||
|
|
||||||
|
# Oder mit Virtual Environment
|
||||||
|
./form_tester_setup.sh --venv
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manuelle Installation
|
||||||
|
```bash
|
||||||
|
# Dependencies installieren
|
||||||
|
pip install playwright faker beautifulsoup4 rich
|
||||||
|
|
||||||
|
# Browser installieren
|
||||||
|
playwright install chromium firefox webkit
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📋 Verwendung
|
||||||
|
|
||||||
|
### CLI-Interface
|
||||||
|
|
||||||
|
#### Alle Formulare auf einer Seite testen
|
||||||
|
```bash
|
||||||
|
python form_test_automator.py --url http://localhost:5000/register --test-all
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Spezifisches Formular testen
|
||||||
|
```bash
|
||||||
|
python form_test_automator.py --url http://localhost:5000/contact --form "#contact-form"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Multi-Step Formular testen
|
||||||
|
```bash
|
||||||
|
python form_test_automator.py --url http://localhost:5000/signup --multi-step --steps "step1,step2,step3"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Responsive Testing
|
||||||
|
```bash
|
||||||
|
python form_test_automator.py --url http://localhost:5000/order --responsive --devices "iPhone 12,iPad,Desktop"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Umfassende Tests mit allen Szenarien
|
||||||
|
```bash
|
||||||
|
python form_test_automator.py --url http://localhost:5000/application --comprehensive
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Mit sichtbarem Browser (für Debugging)
|
||||||
|
```bash
|
||||||
|
python form_test_automator.py --url http://localhost:5000/login --test-all --headed
|
||||||
|
```
|
||||||
|
|
||||||
|
### Python-API
|
||||||
|
|
||||||
|
```python
|
||||||
|
import asyncio
|
||||||
|
from form_test_automator import HTMLFormTestAutomator
|
||||||
|
|
||||||
|
async def test_my_forms():
|
||||||
|
async with HTMLFormTestAutomator(
|
||||||
|
base_url="http://localhost:5000",
|
||||||
|
browser="chromium",
|
||||||
|
headless=True
|
||||||
|
) as automator:
|
||||||
|
|
||||||
|
# Einfacher Formular-Test
|
||||||
|
results = await automator.test_form(
|
||||||
|
url="/login",
|
||||||
|
form_selector="#login-form",
|
||||||
|
test_data={
|
||||||
|
"username": "admin",
|
||||||
|
"password": "admin123"
|
||||||
|
},
|
||||||
|
test_scenarios=["valid", "invalid", "accessibility"]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Report generieren
|
||||||
|
report_path = automator.generate_report("my_test_report")
|
||||||
|
print(f"Report: {report_path}")
|
||||||
|
|
||||||
|
# Test ausführen
|
||||||
|
asyncio.run(test_my_forms())
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🧪 Test-Szenarien
|
||||||
|
|
||||||
|
### Standard-Szenarien
|
||||||
|
- **`valid`**: Gültige Daten, erwartete erfolgreiche Submission
|
||||||
|
- **`invalid`**: Ungültige Daten, Validierung sollte greifen
|
||||||
|
- **`edge_cases`**: XSS, SQL-Injection, Unicode, extreme Längen
|
||||||
|
- **`accessibility`**: ARIA, Labels, Keyboard-Navigation
|
||||||
|
- **`validations`**: Client-Side Validierungs-Tests
|
||||||
|
- **`responsive`**: Multi-Device-Tests
|
||||||
|
- **`dynamic`**: Conditional Fields, JavaScript-Verhalten
|
||||||
|
- **`error_display`**: Fehlermeldungs-Anzeige-Tests
|
||||||
|
|
||||||
|
### Erweiterte Tests
|
||||||
|
```bash
|
||||||
|
# Alle Szenarien
|
||||||
|
python form_test_automator.py --url http://localhost:5000 --comprehensive
|
||||||
|
|
||||||
|
# Spezifische Szenarien
|
||||||
|
python form_test_automator.py --url http://localhost:5000 --scenarios "valid,accessibility,responsive"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📊 Reports
|
||||||
|
|
||||||
|
### HTML-Report
|
||||||
|
- Visuelle Übersicht aller Tests
|
||||||
|
- Screenshots der Formular-Zustände
|
||||||
|
- Interaktive Statistiken
|
||||||
|
- Filtermöglichkeiten nach Status
|
||||||
|
|
||||||
|
### JSON-Report
|
||||||
|
- Maschinell lesbare Ergebnisse
|
||||||
|
- Integration in CI/CD-Pipelines
|
||||||
|
- Datenanalyse und Metriken
|
||||||
|
- API-kompatibles Format
|
||||||
|
|
||||||
|
### Screenshot-Dokumentation
|
||||||
|
- Vor/Nach-Vergleiche
|
||||||
|
- Fehler-Zustände
|
||||||
|
- Responsive-Ansichten
|
||||||
|
- Validierungs-Meldungen
|
||||||
|
|
||||||
|
## 🎪 MYP-spezifische Tests
|
||||||
|
|
||||||
|
Für das MYP (Manage Your Printers) System sind spezielle Test-Beispiele verfügbar:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# MYP-Beispiele ausführen
|
||||||
|
python test_forms_example.py
|
||||||
|
|
||||||
|
# Oder interaktiv wählen:
|
||||||
|
# 1. Umfassende Tests (alle Formulare)
|
||||||
|
# 2. Demo Einzeltest (mit sichtbarem Browser)
|
||||||
|
# 3. Nur Login-Test
|
||||||
|
# 4. Nur Responsive-Test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Getestete MYP-Formulare
|
||||||
|
- **Login & Authentifizierung**
|
||||||
|
- **Drucker-Registrierung & -Verwaltung**
|
||||||
|
- **Druckauftrags-Erstellung**
|
||||||
|
- **Gast-Zugangs-System (OTP)**
|
||||||
|
- **Einstellungen & Konfiguration**
|
||||||
|
- **Tapo-Controller-Integration**
|
||||||
|
|
||||||
|
## ⚙️ Konfiguration
|
||||||
|
|
||||||
|
### form_tester_config.json
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"base_url": "http://localhost:5000",
|
||||||
|
"browser": "chromium",
|
||||||
|
"headless": true,
|
||||||
|
"viewport": {
|
||||||
|
"width": 1280,
|
||||||
|
"height": 720
|
||||||
|
},
|
||||||
|
"default_scenarios": [
|
||||||
|
"valid",
|
||||||
|
"invalid",
|
||||||
|
"accessibility"
|
||||||
|
],
|
||||||
|
"test_devices": [
|
||||||
|
"iPhone SE",
|
||||||
|
"iPhone 12",
|
||||||
|
"iPad",
|
||||||
|
"Desktop 1280x720"
|
||||||
|
],
|
||||||
|
"output_directory": "form_test_reports",
|
||||||
|
"screenshot_on_failure": true,
|
||||||
|
"video_recording": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Erweiterte Features
|
||||||
|
|
||||||
|
### 1. Multi-Step-Form-Testing
|
||||||
|
```python
|
||||||
|
# Mehrstufige Formulare
|
||||||
|
results = await automator.test_multi_step_form(
|
||||||
|
start_url="/registration",
|
||||||
|
steps=["personal-info", "address", "payment", "confirmation"]
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. File-Upload-Testing
|
||||||
|
```python
|
||||||
|
# Datei-Upload-Tests
|
||||||
|
test_data = {
|
||||||
|
"file": "/path/to/test-file.pdf",
|
||||||
|
"description": "Test-Upload"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Cross-Browser-Testing
|
||||||
|
```python
|
||||||
|
browsers = ["chromium", "firefox", "webkit"]
|
||||||
|
for browser in browsers:
|
||||||
|
async with HTMLFormTestAutomator(browser=browser) as automator:
|
||||||
|
# Tests für jeden Browser
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Performance-Monitoring
|
||||||
|
```python
|
||||||
|
# Execution-Time wird automatisch gemessen
|
||||||
|
for result in results:
|
||||||
|
print(f"Test: {result.test_type}, Zeit: {result.execution_time:.2f}s")
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Custom Test Data Generators
|
||||||
|
```python
|
||||||
|
# Eigene Daten-Generatoren
|
||||||
|
class CustomDataGenerator(FrontendTestDataGenerator):
|
||||||
|
def _generate_company_id(self, field):
|
||||||
|
return f"MB-{random.randint(1000, 9999)}"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 Debugging & Troubleshooting
|
||||||
|
|
||||||
|
### Häufige Probleme
|
||||||
|
|
||||||
|
#### Playwright Installation
|
||||||
|
```bash
|
||||||
|
# Browser neu installieren
|
||||||
|
playwright install chromium
|
||||||
|
|
||||||
|
# System-Dependencies (Linux)
|
||||||
|
sudo apt-get install libnss3 libatk-bridge2.0-0 libx11-xcb1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Formular nicht gefunden
|
||||||
|
```python
|
||||||
|
# Erweiterte Selektoren verwenden
|
||||||
|
form_selector = "form[action*='login'], #login-form, .login-form"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JavaScript-Timing-Probleme
|
||||||
|
```python
|
||||||
|
# Längere Wartezeiten
|
||||||
|
await page.wait_for_timeout(2000)
|
||||||
|
await page.wait_for_load_state("networkidle")
|
||||||
|
```
|
||||||
|
|
||||||
|
### Debug-Modus
|
||||||
|
```bash
|
||||||
|
# Mit sichtbarem Browser
|
||||||
|
python form_test_automator.py --url http://localhost:5000 --headed
|
||||||
|
|
||||||
|
# Mit Console-Output
|
||||||
|
python form_test_automator.py --url http://localhost:5000 --verbose
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📈 Integration in CI/CD
|
||||||
|
|
||||||
|
### GitHub Actions
|
||||||
|
```yaml
|
||||||
|
name: Form Tests
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
test-forms:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.9'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
pip install -r requirements_form_tester.txt
|
||||||
|
playwright install chromium
|
||||||
|
- name: Run form tests
|
||||||
|
run: |
|
||||||
|
python form_test_automator.py --url http://localhost:5000 --comprehensive
|
||||||
|
- name: Upload reports
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: form-test-reports
|
||||||
|
path: form_test_reports/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Jenkins Pipeline
|
||||||
|
```groovy
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
stages {
|
||||||
|
stage('Form Tests') {
|
||||||
|
steps {
|
||||||
|
sh 'python form_test_automator.py --url $TEST_URL --comprehensive'
|
||||||
|
publishHTML([
|
||||||
|
allowMissing: false,
|
||||||
|
alwaysLinkToLastBuild: true,
|
||||||
|
keepAll: true,
|
||||||
|
reportDir: 'form_test_reports/reports',
|
||||||
|
reportFiles: '*.html',
|
||||||
|
reportName: 'Form Test Report'
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
|
||||||
|
### Neue Test-Szenarien hinzufügen
|
||||||
|
```python
|
||||||
|
# In FormInteractionEngine
|
||||||
|
async def test_custom_scenario(self, form: FormStructure) -> List[TestResult]:
|
||||||
|
# Custom Test-Logik
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom Validators
|
||||||
|
```python
|
||||||
|
# In VisualFormValidator
|
||||||
|
async def validate_custom_aspect(self, form: FormStructure) -> List[TestResult]:
|
||||||
|
# Custom Validierung
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📝 Lizenz
|
||||||
|
|
||||||
|
Dieses Tool wurde als Teil der Mercedes-Benz Projektarbeit MYP entwickelt.
|
||||||
|
|
||||||
|
**Autor**: Till Tomczak
|
||||||
|
**Projekt**: MYP (Manage Your Printers)
|
||||||
|
**Version**: 1.0
|
||||||
|
|
||||||
|
## 🔗 Links
|
||||||
|
|
||||||
|
- [Playwright Documentation](https://playwright.dev/python/)
|
||||||
|
- [Faker Documentation](https://faker.readthedocs.io/)
|
||||||
|
- [BeautifulSoup Documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)
|
||||||
|
- [Rich Documentation](https://rich.readthedocs.io/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**🎯 Frontend-fokussiertes Testing für Flask-Anwendungen - Teste wie deine Benutzer es sehen!**
|
2465
backend/form_test_automator.py
Normal file
2465
backend/form_test_automator.py
Normal file
File diff suppressed because it is too large
Load Diff
223
backend/form_tester_setup.sh
Normal file
223
backend/form_tester_setup.sh
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Flask HTML-Formular Test Automator - Setup Skript
|
||||||
|
# =================================================
|
||||||
|
|
||||||
|
echo "🧪 Flask HTML-Formular Test Automator Setup"
|
||||||
|
echo "============================================"
|
||||||
|
|
||||||
|
# Farben für Ausgabe
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Funktionen
|
||||||
|
print_status() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Python-Version prüfen
|
||||||
|
print_status "Prüfe Python-Version..."
|
||||||
|
python_version=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
|
||||||
|
required_version="3.8"
|
||||||
|
|
||||||
|
if python3 -c "import sys; exit(0 if sys.version_info >= (3, 8) else 1)"; then
|
||||||
|
print_success "Python $python_version ist kompatibel (benötigt: $required_version+)"
|
||||||
|
else
|
||||||
|
print_error "Python $required_version oder höher erforderlich (gefunden: $python_version)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Virtual Environment erstellen (optional)
|
||||||
|
if [ "$1" = "--venv" ]; then
|
||||||
|
print_status "Erstelle Virtual Environment..."
|
||||||
|
python3 -m venv form_tester_env
|
||||||
|
source form_tester_env/bin/activate
|
||||||
|
print_success "Virtual Environment aktiviert"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Python-Dependencies installieren
|
||||||
|
print_status "Installiere Python-Dependencies..."
|
||||||
|
if [ -f "requirements_form_tester.txt" ]; then
|
||||||
|
if python3 -m pip install -r requirements_form_tester.txt; then
|
||||||
|
print_success "Python-Dependencies installiert"
|
||||||
|
else
|
||||||
|
print_error "Fehler beim Installieren der Python-Dependencies"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_warning "requirements_form_tester.txt nicht gefunden, installiere Basis-Dependencies..."
|
||||||
|
python3 -m pip install playwright faker beautifulsoup4 rich
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Playwright Browser installieren
|
||||||
|
print_status "Installiere Playwright Browser..."
|
||||||
|
if python3 -m playwright install chromium firefox webkit; then
|
||||||
|
print_success "Playwright Browser installiert"
|
||||||
|
else
|
||||||
|
print_error "Fehler beim Installieren der Playwright Browser"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Zusätzliche Systemabhängigkeiten für Linux
|
||||||
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
print_status "Installiere System-Dependencies für Linux..."
|
||||||
|
|
||||||
|
# Detect package manager
|
||||||
|
if command -v apt-get &> /dev/null; then
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
libnss3 \
|
||||||
|
libnspr4 \
|
||||||
|
libatk-bridge2.0-0 \
|
||||||
|
libdrm2 \
|
||||||
|
libxkbcommon0 \
|
||||||
|
libgtk-3-0 \
|
||||||
|
libatspi2.0-0 \
|
||||||
|
libx11-xcb1 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxrandr2 \
|
||||||
|
libgbm1 \
|
||||||
|
libxss1 \
|
||||||
|
libasound2
|
||||||
|
print_success "System-Dependencies installiert"
|
||||||
|
elif command -v yum &> /dev/null; then
|
||||||
|
sudo yum install -y \
|
||||||
|
nss \
|
||||||
|
nspr \
|
||||||
|
at-spi2-atk \
|
||||||
|
libdrm \
|
||||||
|
libxkbcommon \
|
||||||
|
gtk3 \
|
||||||
|
at-spi2-core \
|
||||||
|
libXcomposite \
|
||||||
|
libXdamage \
|
||||||
|
libXrandr \
|
||||||
|
mesa-libgbm \
|
||||||
|
libXScrnSaver \
|
||||||
|
alsa-lib
|
||||||
|
print_success "System-Dependencies installiert"
|
||||||
|
else
|
||||||
|
print_warning "Unbekannter Package Manager, überspringe System-Dependencies"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test-Verzeichnis erstellen
|
||||||
|
print_status "Erstelle Test-Verzeichnisse..."
|
||||||
|
mkdir -p form_test_reports
|
||||||
|
mkdir -p form_test_reports/screenshots
|
||||||
|
mkdir -p form_test_reports/videos
|
||||||
|
mkdir -p form_test_reports/reports
|
||||||
|
print_success "Test-Verzeichnisse erstellt"
|
||||||
|
|
||||||
|
# Ausführungsrechte setzen
|
||||||
|
print_status "Setze Ausführungsrechte..."
|
||||||
|
chmod +x form_test_automator.py
|
||||||
|
chmod +x test_forms_example.py
|
||||||
|
print_success "Ausführungsrechte gesetzt"
|
||||||
|
|
||||||
|
# Verfügbarkeit testen
|
||||||
|
print_status "Teste Installation..."
|
||||||
|
if python3 -c "from playwright.async_api import async_playwright; print('Playwright OK')"; then
|
||||||
|
print_success "Playwright erfolgreich installiert"
|
||||||
|
else
|
||||||
|
print_error "Playwright-Test fehlgeschlagen"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if python3 -c "from faker import Faker; print('Faker OK')"; then
|
||||||
|
print_success "Faker erfolgreich installiert"
|
||||||
|
else
|
||||||
|
print_warning "Faker nicht verfügbar (optional)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if python3 -c "from bs4 import BeautifulSoup; print('BeautifulSoup OK')"; then
|
||||||
|
print_success "BeautifulSoup erfolgreich installiert"
|
||||||
|
else
|
||||||
|
print_warning "BeautifulSoup nicht verfügbar (optional)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if python3 -c "from rich.console import Console; print('Rich OK')"; then
|
||||||
|
print_success "Rich erfolgreich installiert"
|
||||||
|
else
|
||||||
|
print_warning "Rich nicht verfügbar (optional)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Beispiel-Konfiguration erstellen
|
||||||
|
print_status "Erstelle Beispiel-Konfiguration..."
|
||||||
|
cat > form_tester_config.json << EOF
|
||||||
|
{
|
||||||
|
"base_url": "http://localhost:5000",
|
||||||
|
"browser": "chromium",
|
||||||
|
"headless": true,
|
||||||
|
"viewport": {
|
||||||
|
"width": 1280,
|
||||||
|
"height": 720
|
||||||
|
},
|
||||||
|
"default_scenarios": [
|
||||||
|
"valid",
|
||||||
|
"invalid",
|
||||||
|
"accessibility"
|
||||||
|
],
|
||||||
|
"test_devices": [
|
||||||
|
"iPhone SE",
|
||||||
|
"iPhone 12",
|
||||||
|
"iPad",
|
||||||
|
"Desktop 1280x720"
|
||||||
|
],
|
||||||
|
"output_directory": "form_test_reports",
|
||||||
|
"screenshot_on_failure": true,
|
||||||
|
"video_recording": false
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
print_success "Beispiel-Konfiguration erstellt: form_tester_config.json"
|
||||||
|
|
||||||
|
# Erfolgreiche Installation
|
||||||
|
echo ""
|
||||||
|
echo "🎉 Installation erfolgreich abgeschlossen!"
|
||||||
|
echo "========================================="
|
||||||
|
echo ""
|
||||||
|
echo "📋 NÄCHSTE SCHRITTE:"
|
||||||
|
echo ""
|
||||||
|
echo "1. Flask-App starten:"
|
||||||
|
echo " python app.py"
|
||||||
|
echo ""
|
||||||
|
echo "2. Formular-Tests ausführen:"
|
||||||
|
echo " python form_test_automator.py --url http://localhost:5000 --test-all"
|
||||||
|
echo ""
|
||||||
|
echo "3. MYP-spezifische Tests:"
|
||||||
|
echo " python test_forms_example.py"
|
||||||
|
echo ""
|
||||||
|
echo "4. CLI-Hilfe anzeigen:"
|
||||||
|
echo " python form_test_automator.py --help"
|
||||||
|
echo ""
|
||||||
|
echo "📁 AUSGABE-VERZEICHNISSE:"
|
||||||
|
echo " • Screenshots: form_test_reports/screenshots/"
|
||||||
|
echo " • Videos: form_test_reports/videos/"
|
||||||
|
echo " • Reports: form_test_reports/reports/"
|
||||||
|
echo ""
|
||||||
|
echo "🔧 KONFIGURATION:"
|
||||||
|
echo " • Anpassen in: form_tester_config.json"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ "$1" = "--venv" ]; then
|
||||||
|
echo "💡 Virtual Environment aktiviert. Zum Deaktivieren:"
|
||||||
|
echo " deactivate"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "🧪 Flask HTML-Formular Test Automator bereit!"
|
37
backend/requirements_form_tester.txt
Normal file
37
backend/requirements_form_tester.txt
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Flask HTML-Formular Test Automator - Dependencies
|
||||||
|
# =================================================
|
||||||
|
|
||||||
|
# Browser-Automation (Haupt-Abhängigkeit)
|
||||||
|
playwright>=1.40.0
|
||||||
|
|
||||||
|
# Test-Daten-Generierung
|
||||||
|
faker>=20.1.0
|
||||||
|
|
||||||
|
# HTML-Parsing
|
||||||
|
beautifulsoup4>=4.12.0
|
||||||
|
|
||||||
|
# Rich Console-Ausgabe (optional, aber empfohlen)
|
||||||
|
rich>=13.7.0
|
||||||
|
|
||||||
|
# Zusätzliche nützliche Libraries
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# Für erweiterte Bild-Verarbeitung (optional)
|
||||||
|
# Pillow>=10.1.0
|
||||||
|
|
||||||
|
# Für JSON-Schema-Validierung (optional)
|
||||||
|
# jsonschema>=4.20.0
|
||||||
|
|
||||||
|
# Für HTTP-Requests außerhalb von Playwright (optional)
|
||||||
|
# requests>=2.31.0
|
||||||
|
|
||||||
|
# Für Datenbank-Tests (optional)
|
||||||
|
# sqlalchemy>=2.0.0
|
||||||
|
|
||||||
|
# Für CSV/Excel-Export (optional)
|
||||||
|
# pandas>=2.1.0
|
||||||
|
# openpyxl>=3.1.0
|
||||||
|
|
||||||
|
# Installation:
|
||||||
|
# pip install -r requirements_form_tester.txt
|
||||||
|
# playwright install chromium firefox webkit
|
555
backend/test_forms_example.py
Normal file
555
backend/test_forms_example.py
Normal file
@@ -0,0 +1,555 @@
|
|||||||
|
#!/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())
|
Reference in New Issue
Block a user