diff --git a/testing/hooks/screenshot.sh b/testing/hooks/screenshot.sh index 00ff66e..c81d56a 100755 --- a/testing/hooks/screenshot.sh +++ b/testing/hooks/screenshot.sh @@ -5,7 +5,13 @@ export E2E_SSH_PORT="${2:-2222}" ARTIFACTS_DIR="${3:-/output}" source /test/scripts/ssh-helpers.sh SCREENSHOT_URL="${SCREENSHOT_URL:-http://localhost/FullPageDashboard}" -PAINT_STDDEV_THRESHOLD="${PAINT_STDDEV_THRESHOLD:-0.08}" +# The FullPageOS desktop wallpaper / dashboard shell alone paints at stddev +# ~0.20, while the welcome dashboard with the QR code paints at ~0.31. Require +# the higher value so we don't accept the wallpaper after the kiosk restarts +# (e.g. following test_translation_disabled.sh), and wait for the welcome +# iframe content to actually render. +PAINT_STDDEV_THRESHOLD="${PAINT_STDDEV_THRESHOLD:-0.26}" +PAINT_STABLE_PASSES="${PAINT_STABLE_PASSES:-2}" echo "Capturing X display screenshot from the running desktop..." @@ -76,16 +82,26 @@ dashboard_is_painted() { } echo " Waiting for dashboard iframe content to paint..." +consecutive_passes=0 for i in $(seq 1 60); do if capture_display_png "$ARTIFACTS_DIR/screenshot-candidate.png"; then cp "$ARTIFACTS_DIR/screenshot-candidate.png" "$ARTIFACTS_DIR/screenshot-not-painted.png" if dashboard_is_painted "$ARTIFACTS_DIR/screenshot-candidate.png"; then - mv "$ARTIFACTS_DIR/screenshot-candidate.png" "$ARTIFACTS_DIR/screenshot.png" - rm -f "$ARTIFACTS_DIR/screenshot-not-painted.png" - echo "Display screenshot saved after dashboard paint (${i}x2s)" - exit 0 + consecutive_passes=$((consecutive_passes + 1)) + if [ "$consecutive_passes" -ge "$PAINT_STABLE_PASSES" ]; then + mv "$ARTIFACTS_DIR/screenshot-candidate.png" "$ARTIFACTS_DIR/screenshot.png" + rm -f "$ARTIFACTS_DIR/screenshot-not-painted.png" + echo "Display screenshot saved after dashboard paint (${consecutive_passes} stable passes, ${i}x2s)" + exit 0 + fi + echo " Painted but waiting for stabilization (${consecutive_passes}/${PAINT_STABLE_PASSES})" + sleep 3 + continue + else + consecutive_passes=0 fi else + consecutive_passes=0 echo " Candidate capture failed (${i}x2s)" fi sleep 2 diff --git a/testing/tests/test_translation_disabled.sh b/testing/tests/test_translation_disabled.sh index e326e97..2fcf962 100755 --- a/testing/tests/test_translation_disabled.sh +++ b/testing/tests/test_translation_disabled.sh @@ -40,11 +40,31 @@ ORIG_URL=$(ssh_cmd "cat ${FULLPAGEOS_TXT} 2>/dev/null || true" 2>/dev/null || tr echo " Current URL: ${ORIG_URL:-}" restore_url() { + local restored_url="${ORIG_URL:-http://localhost/FullPageDashboard}" echo " Restoring original kiosk URL..." - if [ -n "$ORIG_URL" ]; then - ssh_cmd "printf '%s\n' \"$ORIG_URL\" | sudo tee ${FULLPAGEOS_TXT} >/dev/null" 2>/dev/null || true - fi + ssh_cmd "printf '%s\n' '${restored_url}' | sudo tee ${FULLPAGEOS_TXT} >/dev/null" 2>/dev/null || true ssh_cmd "killall chromium 2>/dev/null || true; exit 0" || true + + # run_onepageos respawns chromium from fullpageos.txt, but the new kiosk + # process appearing does not mean its window has composited. Wait for the + # dashboard kiosk process to come back so screenshot.sh starts from a + # relaunched kiosk rather than the bare desktop wallpaper. + echo " Waiting for dashboard kiosk to relaunch on ${restored_url}..." + local restored=0 + for i in $(seq 1 60); do + local kiosk + kiosk=$(ssh_cmd "ps ax -o pid= -o args= | grep -F 'chromium' | grep -F -- '--kiosk' | grep -F -- '--app=${restored_url}' | grep -v grep || true" 2>/dev/null || true) + if [ -n "$kiosk" ]; then + restored=1 + echo " Dashboard kiosk restored (pid: $(echo "$kiosk" | awk '{print $1}' | head -1)) after ${i}x2s" + break + fi + sleep 2 + done + if [ "$restored" -eq 0 ]; then + echo " WARNING: Dashboard kiosk did not relaunch on ${restored_url}" + ssh_cmd "pgrep -a chromium || true" 2>/dev/null || true + fi } echo " Pointing kiosk at German test page..."