const { chromium } = require('playwright'); const fs = require('fs'); const path = require('path'); (async () => { const browser = await chromium.launch(); const context = await browser.newContext(); const page = await context.newPage(); // Create screenshots directory const screenshotDir = path.join(__dirname, '../screenshots/authenticated-pages'); if (!fs.existsSync(screenshotDir)) { fs.mkdirSync(screenshotDir, { recursive: true }); } const baseUrl = 'https://upskill-staging.measurequick.com'; console.log('Logging in as test trainer...'); // Navigate to login page await page.goto(baseUrl + '/training-login/', { waitUntil: 'networkidle' }); // Fill login form await page.fill('input[name="log"]', 'test_trainer'); await page.fill('input[name="pwd"]', 'TestPass123!'); await page.click('input[type="submit"]'); // Wait for redirect await page.waitForURL('**/trainer/dashboard/**', { timeout: 10000 }).catch(() => { console.log('Did not redirect to dashboard - checking current page'); }); // Test authenticated pages const testPages = [ { name: 'trainer-dashboard', url: '/trainer/dashboard/', expectedContent: 'Welcome' }, { name: 'certificate-reports', url: '/trainer/certificate-reports/', expectedContent: 'Certificate Reports' }, { name: 'generate-certificates', url: '/trainer/generate-certificates/', expectedContent: 'Generate Certificates' }, { name: 'email-attendees', url: '/trainer/email-attendees/', expectedContent: 'Email Attendees' }, { name: 'trainer-profile', url: '/trainer/my-profile/', expectedContent: 'Profile' } ]; console.log('\nTesting authenticated pages...'); for (const testPage of testPages) { console.log(`\nTesting ${testPage.name}...`); try { await page.goto(baseUrl + testPage.url, { waitUntil: 'networkidle' }); // Check for expected content const bodyText = await page.textContent('body'); if (bodyText.includes(testPage.expectedContent)) { console.log(`✓ ${testPage.name} - Content found: "${testPage.expectedContent}"`); } else { console.log(`✗ ${testPage.name} - Expected content not found`); } // Check if page has sidebar (indicates template issue) const hasSidebar = await page.locator('.widget-area, .sidebar, #secondary').count(); if (hasSidebar > 0) { console.log(`⚠️ ${testPage.name} - Has sidebar (possible template issue)`); } else { console.log(`✓ ${testPage.name} - No sidebar (template working)`); } // Take screenshot await page.screenshot({ path: path.join(screenshotDir, `${testPage.name}.png`), fullPage: true }); } catch (error) { console.log(`✗ ${testPage.name} - Error: ${error.message}`); } } console.log('\nVerification complete. Screenshots saved to:', screenshotDir); await browser.close(); })();