|
| 1 | +import { Page } from '@playwright/test'; |
| 2 | + |
| 3 | +export async function debugPageState(page: Page, testName: string) { |
| 4 | + console.log(`=== DEBUG INFO FOR: ${testName} ===`); |
| 5 | + |
| 6 | + // 1. Check current URL |
| 7 | + console.log('Current URL:', page.url()); |
| 8 | + |
| 9 | + // 2. Check if Angular app is loaded |
| 10 | + const angularLoaded = await page.evaluate(() => { |
| 11 | + return !!(window as any).ng; |
| 12 | + }); |
| 13 | + console.log('Angular loaded:', angularLoaded); |
| 14 | + |
| 15 | + // 3. Check network requests |
| 16 | + const allRequests: string[] = []; |
| 17 | + page.on('request', (request) => { |
| 18 | + allRequests.push(`${request.method()} ${request.url()}`); |
| 19 | + }); |
| 20 | + |
| 21 | + // 4. Check for JavaScript errors |
| 22 | + const jsErrors: string[] = []; |
| 23 | + page.on('pageerror', (error) => { |
| 24 | + jsErrors.push(error.message); |
| 25 | + }); |
| 26 | + |
| 27 | + // 5. Check console logs |
| 28 | + const consoleLogs: string[] = []; |
| 29 | + page.on('console', (msg) => { |
| 30 | + consoleLogs.push(`${msg.type()}: ${msg.text()}`); |
| 31 | + }); |
| 32 | + |
| 33 | + // 6. Check if tags container exists |
| 34 | + const tagsContainer = await page.locator('[data-testid="tags-container"]').count(); |
| 35 | + console.log('Tags container count:', tagsContainer); |
| 36 | + |
| 37 | + // 7. Check if tags list exists |
| 38 | + const tagsList = await page.locator('[data-testid="tags-list"]').count(); |
| 39 | + console.log('Tags list count:', tagsList); |
| 40 | + |
| 41 | + // 8. Check if any tag items exist |
| 42 | + const tagItems = await page.locator('[data-testid="tag-item"]').count(); |
| 43 | + console.log('Tag items count:', tagItems); |
| 44 | + |
| 45 | + // 9. Check the HTML content of tags container |
| 46 | + if (tagsContainer > 0) { |
| 47 | + const tagsContainerHTML = await page.locator('[data-testid="tags-container"]').innerHTML(); |
| 48 | + console.log('Tags container HTML:', tagsContainerHTML); |
| 49 | + } |
| 50 | + |
| 51 | + // 10. Check for @for loop elements (Angular control flow) |
| 52 | + const ngForElements = await page.locator('[ng-for]').count(); |
| 53 | + console.log('ng-for elements count:', ngForElements); |
| 54 | + |
| 55 | + // 11. Check Angular component state |
| 56 | + const componentState = await page.evaluate(() => { |
| 57 | + // Try to access Angular component data |
| 58 | + const appRoot = document.querySelector('app-root'); |
| 59 | + if (appRoot) { |
| 60 | + return { |
| 61 | + hasAppRoot: true, |
| 62 | + innerHTML: appRoot.innerHTML.substring(0, 500) + '...' |
| 63 | + }; |
| 64 | + } |
| 65 | + return { hasAppRoot: false }; |
| 66 | + }); |
| 67 | + console.log('Component state:', componentState); |
| 68 | + |
| 69 | + // 12. Check API calls |
| 70 | + console.log('Recent network requests:', allRequests.slice(-10)); |
| 71 | + console.log('JavaScript errors:', jsErrors); |
| 72 | + console.log('Recent console logs:', consoleLogs.slice(-10)); |
| 73 | + |
| 74 | + // 13. Check if Supabase client is available |
| 75 | + const supabaseAvailable = await page.evaluate(() => { |
| 76 | + return typeof (window as any).supabase !== 'undefined'; |
| 77 | + }); |
| 78 | + console.log('Supabase client available:', supabaseAvailable); |
| 79 | + |
| 80 | + // 14. Check environment variables |
| 81 | + const envCheck = await page.evaluate(() => { |
| 82 | + return { |
| 83 | + hasSupabaseUrl: typeof process !== 'undefined' && !!process.env?.['SUPABASE_URL'], |
| 84 | + hasSupabaseKey: typeof process !== 'undefined' && !!process.env?.['SUPABASE_ANON_KEY'] |
| 85 | + }; |
| 86 | + }); |
| 87 | + console.log('Environment check:', envCheck); |
| 88 | + |
| 89 | + console.log('=== END DEBUG INFO ===\n'); |
| 90 | +} |
| 91 | + |
| 92 | +export async function waitForAngularToLoad(page: Page, timeout = 10000) { |
| 93 | + console.log('Waiting for Angular to load...'); |
| 94 | + |
| 95 | + try { |
| 96 | + // Wait for Angular to be ready |
| 97 | + await page.waitForFunction(() => { |
| 98 | + return !!(window as any).ng && document.querySelector('app-root'); |
| 99 | + }, { timeout }); |
| 100 | + |
| 101 | + console.log('Angular loaded successfully'); |
| 102 | + return true; |
| 103 | + } catch (error) { |
| 104 | + console.log('Angular failed to load within timeout:', error); |
| 105 | + return false; |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +export async function waitForApiCall(page: Page, urlPattern: string, timeout = 15000) { |
| 110 | + console.log(`Waiting for API call matching: ${urlPattern}`); |
| 111 | + |
| 112 | + return new Promise((resolve, reject) => { |
| 113 | + const timer = setTimeout(() => { |
| 114 | + reject(new Error(`API call to ${urlPattern} not detected within ${timeout}ms`)); |
| 115 | + }, timeout); |
| 116 | + |
| 117 | + const requestHandler = (request: any) => { |
| 118 | + if (request.url().includes(urlPattern)) { |
| 119 | + console.log(`API call detected: ${request.url()}`); |
| 120 | + clearTimeout(timer); |
| 121 | + page.off('request', requestHandler); |
| 122 | + resolve(request); |
| 123 | + } |
| 124 | + }; |
| 125 | + |
| 126 | + page.on('request', requestHandler); |
| 127 | + }); |
| 128 | +} |
0 commit comments