223 lines
6.2 KiB
Bash
223 lines
6.2 KiB
Bash
#!/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!" |