From 678ca784a18be7e4023f0c131340280632d79352 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 11 Mar 2026 10:05:32 +0100 Subject: [PATCH] test: robust E2E form verification with direct Gatekeeper auth and verbose logging --- scripts/check-forms.ts | 65 +++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/scripts/check-forms.ts b/scripts/check-forms.ts index 224668ab..7449fb78 100644 --- a/scripts/check-forms.ts +++ b/scripts/check-forms.ts @@ -34,22 +34,27 @@ async function main() { process.exit(1); } - const contactUrl = urls.find((u) => u.includes('/de/kontakt')); - // Ensure we select an actual product page (depth >= 7: http://host/de/produkte/category/product) + const contactUrl = urls.find((u) => u.includes('/de/contact') || u.includes('/de/kontakt')); + // Ensure we select an actual product page (depth >= 4 segments: /de/produkte/category/product) const productUrl = urls.find( (u) => - u.includes('/de/produkte/') && new URL(u).pathname.split('/').filter(Boolean).length >= 4, + (u.includes('/de/produkte/') || u.includes('/de/products/')) && + new URL(u).pathname.split('/').filter(Boolean).length >= 4, ); if (!contactUrl) { - console.error(`āŒ Could not find contact page in sitemap. Ensure /de/kontakt exists.`); + console.error( + `āŒ Could not find contact page in sitemap. Checked patterns: /de/contact, /de/kontakt`, + ); + console.log('Available URLs (first 20):', urls.slice(0, 20)); process.exit(1); } if (!productUrl) { console.error( - `āŒ Could not find a product page in sitemap. Form testing requires at least one product page.`, + `āŒ Could not find a product page in sitemap. Checked patterns: /de/produkte/, /de/products/`, ); + console.log('Available URLs (first 20):', urls.slice(0, 20)); process.exit(1); } @@ -66,32 +71,34 @@ async function main() { const page = await browser.newPage(); + // Set viewport for consistent layout + await page.setViewport({ width: 1280, height: 800 }); + page.on('console', (msg) => console.log('šŸ’» BROWSER CONSOLE:', msg.text())); page.on('pageerror', (error: any) => console.error('šŸ’» BROWSER ERROR:', error.message)); page.on('requestfailed', (request) => { - console.error('šŸ’» BROWSER REQUEST FAILED:', request.url(), request.failure()?.errorText); + // Only log failures for main document and API calls to reduce noise + const resourceType = request.resourceType(); + if (resourceType === 'document' || resourceType === 'fetch' || resourceType === 'xhr') { + console.error('šŸ’» BROWSER REQUEST FAILED:', request.url(), request.failure()?.errorText); + } }); - // 3. Authenticate through Gatekeeper login form - console.log(`\nšŸ›”ļø Authenticating through Gatekeeper...`); + // 3. Authenticate through Gatekeeper via Direct Cookie Insertion + console.log(`\nšŸ›”ļø Authenticating through Gatekeeper via Cookie Injection...`); try { - // Navigate to a protected page so Gatekeeper redirects us to the login screen - await page.goto(contactUrl, { waitUntil: 'networkidle0', timeout: 30000 }); - - // Check if we landed on the Gatekeeper login page - const isGatekeeperPage = await page.$('input[name="password"]'); - if (isGatekeeperPage) { - await page.type('input[name="password"]', gatekeeperPassword); - await Promise.all([ - page.waitForNavigation({ waitUntil: 'networkidle0', timeout: 30000 }), - page.click('button[type="submit"]'), - ]); - console.log(`āœ… Gatekeeper authentication successful!`); - } else { - console.log(`āœ… Already authenticated (no Gatekeeper gate detected).`); - } + const domain = new URL(targetUrl).hostname; + await page.setCookie({ + name: 'klz_gatekeeper_session', + value: gatekeeperPassword, + domain: domain, + path: '/', + secure: true, + httpOnly: true, + }); + console.log(`āœ… Gatekeeper cookie injected for domain: ${domain}`); } catch (err: any) { - console.error(`āŒ Gatekeeper authentication failed: ${err.message}`); + console.error(`āŒ Gatekeeper cookie injection failed: ${err.message}`); await browser.close(); process.exit(1); } @@ -114,7 +121,10 @@ async function main() { timeout: 15000, }); } catch (e) { - console.error('Failed to find Contact Form input. Page Title:', await page.title()); + console.error('āŒ Failed to find Contact Form input.'); + console.log('Page Title:', await page.title()); + const bodySnippet = await page.evaluate(() => document.body.innerText.slice(0, 500)); + console.log('Page Content Snippet:', bodySnippet); throw e; } @@ -169,7 +179,10 @@ async function main() { timeout: 15000, }); } catch (e) { - console.error('Failed to find Product Quote Form input. Page Title:', await page.title()); + console.error('āŒ Failed to find Product Quote Form input.'); + console.log('Page Title:', await page.title()); + const bodySnippet = await page.evaluate(() => document.body.innerText.slice(0, 500)); + console.log('Page Content Snippet:', bodySnippet); throw e; }