upskill-event-manager/wordpress-dev/tests/e2e/debug-authenticated-dashboard.test.ts
bengizmo 43e0bb10f5 Fix PHP compatibility issues causing dashboard 500 errors
- Removed PHP 7.4+ type declarations (private int, return types) that were causing fatal errors
- Fixed constructor parameter and property declarations for older PHP versions
- Created minimal dashboard data class as emergency fallback
- Root cause: Server running older PHP version incompatible with modern type declarations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-22 20:25:31 -03:00

162 lines
No EOL
6.8 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('Debug Authenticated Dashboard 500 Error', async ({ page }) => {
console.log('=== Testing Dashboard 500 Error After Login ===');
try {
// Go to community login
console.log('1. Navigating to community login...');
await page.goto('https://upskill-staging.measurequick.com/community-login/', {
waitUntil: 'load',
timeout: 10000
});
console.log('2. Filling login form with provided credentials...');
await page.fill('#user_login', 'test_trainer');
await page.fill('#user_pass', 'test_password');
console.log('3. Submitting login form...');
await page.click('#wp-submit');
// Wait for response and check result
await page.waitForLoadState('networkidle', { timeout: 10000 });
const currentUrl = page.url();
console.log(`4. URL after login attempt: ${currentUrl}`);
// Check if login was successful
if (currentUrl.includes('login=failed')) {
console.log('❌ Login failed - checking error message...');
const errorMessage = await page.locator('.login-error').textContent().catch(() => 'No error message found');
console.log(`Error message: ${errorMessage}`);
await page.screenshot({ path: 'login-failed-test-trainer.png' });
return;
}
// If we're redirected to dashboard or another page, login was successful
if (currentUrl.includes('hvac-dashboard') || !currentUrl.includes('login')) {
console.log('✅ Login appears successful, checking dashboard...');
} else {
console.log('⚠️ Login status unclear, trying to access dashboard directly...');
}
console.log('5. Attempting to access dashboard...');
// Set up response handler to catch 500 errors
let responseStatus = 0;
let responseError = '';
page.on('response', response => {
if (response.url().includes('hvac-dashboard')) {
responseStatus = response.status();
console.log(`Dashboard response status: ${responseStatus}`);
}
});
// Navigate to dashboard
const dashboardResponse = await page.goto('https://upskill-staging.measurequick.com/hvac-dashboard/', {
waitUntil: 'load',
timeout: 10000
}).catch(error => {
console.log(`Dashboard navigation error: ${error}`);
return null;
});
if (dashboardResponse) {
console.log(`Dashboard HTTP status: ${dashboardResponse.status()}`);
if (dashboardResponse.status() === 500) {
console.log('❌ 500 ERROR DETECTED ON DASHBOARD');
// Get page content to see error details
const pageContent = await page.content();
const bodyText = await page.locator('body').textContent() || '';
console.log('Error page content analysis:');
// Check for WordPress error patterns
if (bodyText.includes('There has been a critical error')) {
console.log(' - WordPress critical error detected');
}
if (bodyText.includes('Fatal error')) {
console.log(' - PHP Fatal error detected');
}
if (bodyText.includes('Parse error')) {
console.log(' - PHP Parse error detected');
}
if (bodyText.includes('Call Stack')) {
console.log(' - Call stack detected');
}
// Look for plugin-specific errors
if (bodyText.includes('HVAC') || bodyText.includes('hvac')) {
console.log(' - HVAC plugin related error detected');
}
// Extract error details if visible
const errorLines = bodyText.split('\n')
.filter(line => line.includes('error') || line.includes('Error') || line.includes('Fatal') || line.includes('.php'))
.slice(0, 15);
if (errorLines.length > 0) {
console.log(' Error details found:');
errorLines.forEach((line, i) => {
if (line.trim()) console.log(` ${i + 1}: ${line.trim()}`);
});
}
await page.screenshot({
path: 'dashboard-500-error.png',
fullPage: true
});
// Check if we can access other pages while logged in
console.log('6. Testing other authenticated pages...');
const testPages = [
'certificate-reports',
'generate-certificates',
'trainer-profile'
];
for (const testPage of testPages) {
try {
console.log(` Testing: ${testPage}...`);
const testResponse = await page.goto(`https://upskill-staging.measurequick.com/${testPage}/`, {
waitUntil: 'load',
timeout: 5000
});
console.log(` Status: ${testResponse?.status()}`);
if (testResponse?.status() === 500) {
console.log(`${testPage} also has 500 error`);
await page.screenshot({
path: `${testPage}-500-error.png`,
fullPage: true
});
} else {
console.log(`${testPage} loads successfully`);
}
} catch (error) {
console.log(` ❌ Error accessing ${testPage}: ${error}`);
}
}
} else {
console.log('✅ Dashboard loads successfully');
await page.screenshot({ path: 'dashboard-success.png' });
}
} else {
console.log('❌ Failed to get dashboard response');
}
} catch (error) {
console.log(`❌ Test exception: ${error}`);
await page.screenshot({ path: 'test-exception.png' });
}
console.log('\n=== Dashboard Debug Test Complete ===');
});