diff --git a/scripts/test-gal-regression.sh b/scripts/test-gal-regression.sh index 25c1454..6dc4036 100755 --- a/scripts/test-gal-regression.sh +++ b/scripts/test-gal-regression.sh @@ -154,10 +154,17 @@ compare_screenshots() { fi fi + # Normalize both images to TrueColor RGB for consistent comparison + # This handles PNG format differences (RGBA vs RGB, palette vs truecolor) + local ref_normalized="$tmpdir/ref_$filename" + local cur_normalized="$tmpdir/cur_$filename" + convert "$ref" -flatten -colorspace sRGB -type TrueColor "$ref_normalized" 2>/dev/null + convert "$compare_file" -flatten -colorspace sRGB -type TrueColor "$cur_normalized" 2>/dev/null + # Compare with fuzz factor (allows small pixel differences from anti-aliasing) # Use AE (Absolute Error) metric - counts differing pixels # Output format: "123456 (0.123)" - extract just the first number - local compare_output=$(compare -metric AE -fuzz 2% "$ref" "$compare_file" null: 2>&1 || true) + local compare_output=$(compare -metric AE -fuzz 2% "$ref_normalized" "$cur_normalized" null: 2>&1 || true) local diff_pixels=$(echo "$compare_output" | awk '{print $1}') # Handle scientific notation (e.g., 1.92e+06) @@ -173,7 +180,7 @@ compare_screenshots() { fi # Calculate percentage - local total_pixels=$(identify -format "%[fx:w*h]" "$ref" 2>/dev/null) + local total_pixels=$(identify -format "%[fx:w*h]" "$ref_normalized" 2>/dev/null) # Handle scientific notation in total_pixels if [[ "$total_pixels" =~ [eE] ]]; then total_pixels=$(printf "%.0f" "$total_pixels") diff --git a/tests/e2e/gal-webgl.spec.ts b/tests/e2e/gal-webgl.spec.ts index 8e60216..11789e2 100644 --- a/tests/e2e/gal-webgl.spec.ts +++ b/tests/e2e/gal-webgl.spec.ts @@ -162,13 +162,22 @@ test.describe('GAL WebGL Regression Tests', () => { test('Run all scenarios sequentially', async ({ page, testLogger }) => { await page.goto('/gal-webgl/gal_webgl_test.html'); - // Wait for module to be ready + // Wait for module to be fully ready (not just defined) await page.waitForFunction(() => { - return (window as any).galTest !== undefined; + return (window as any).galTest !== undefined && (window as any).galTest.isReady(); }, { timeout: 60000 }); console.log('Running all 28 scenarios...'); + // Find the GL canvas (same logic as individual tests) + let canvas = page.locator('.gl-canvas').first(); + if (!(await canvas.count())) { + canvas = page.locator('#canvas'); + } + if (!(await canvas.count())) { + canvas = page.locator('canvas').first(); + } + for (let i = 0; i < SCENARIO_NAMES.length; i++) { const scenarioName = SCENARIO_NAMES[i]; @@ -177,14 +186,13 @@ test.describe('GAL WebGL Regression Tests', () => { (window as any).galTest.runScenario(index); }, i); - // Wait for rendering - await page.waitForTimeout(50); + // Wait for rendering to complete (same timeout as individual tests) + await page.waitForTimeout(100); // Hide controls overlay before screenshot await page.locator('#controls-overlay').evaluate(el => el.style.visibility = 'hidden'); - // Screenshot the canvas - const canvas = await page.locator('#canvas'); + // Screenshot the GL canvas const screenshotPath = path.join(OUTPUT_DIR, `gal-${scenarioName}.png`); await canvas.screenshot({ path: screenshotPath });