Files
novalon-manage-system/novalon-manage-web/e2e/diagnostic-test.spec.ts
T
张翔 be1c587dbf fix: 修复测试中操作admin用户导致后续测试失败的问题
- 修复密码哈希格式问题(从$2a$改为$2b$)
- 更新所有测试用例密码从Test@123改为admin123
- 修改测试2.3、2.5、2.6,避免操作admin用户(第1行)
- 在beforeEach中添加页面初始化,避免localStorage访问错误
- 添加测试数据清理机制
2026-04-04 13:01:38 +08:00

80 lines
3.0 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
test.describe('登录诊断测试', () => {
test('诊断登录问题', async ({ page }) => {
const loginPage = new LoginPage(page);
console.log('=== 开始诊断登录问题 ===');
await loginPage.goto();
console.log('1. 登录页面加载成功');
await page.screenshot({ path: 'test-results/diagnostic/01-login-page.png', fullPage: true });
console.log('2. 截图已保存: 01-login-page.png');
const usernameVisible = await loginPage.usernameInput.isVisible();
const passwordVisible = await loginPage.passwordInput.isVisible();
const loginButtonVisible = await loginPage.loginButton.isVisible();
console.log('3. 页面元素检查:');
console.log(` - 用户名输入框: ${usernameVisible ? '可见' : '不可见'}`);
console.log(` - 密码输入框: ${passwordVisible ? '可见' : '不可见'}`);
console.log(` - 登录按钮: ${loginButtonVisible ? '可见' : '不可见'}`);
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
console.log('4. 已填写用户名和密码');
await page.screenshot({ path: 'test-results/diagnostic/02-filled-form.png', fullPage: true });
console.log('5. 截图已保存: 02-filled-form.png');
const responsePromise = page.waitForResponse(response =>
response.url().includes('/api/auth/login') && response.request().method() === 'POST'
);
await loginPage.loginButton.click();
console.log('6. 已点击登录按钮');
try {
const response = await responsePromise;
console.log('7. 收到API响应:');
console.log(` - 状态码: ${response.status()}`);
console.log(` - URL: ${response.url()}`);
const responseBody = await response.text();
console.log(` - 响应体: ${responseBody.substring(0, 500)}`);
} catch (error) {
console.log('7. 未收到API响应或超时:', error);
}
await page.waitForTimeout(3000);
const currentUrl = page.url();
console.log(`8. 当前URL: ${currentUrl}`);
await page.screenshot({ path: 'test-results/diagnostic/03-after-login.png', fullPage: true });
console.log('9. 截图已保存: 03-after-login.png');
const errorMessage = await loginPage.getErrorMessage();
if (errorMessage) {
console.log(`10. 错误消息: ${errorMessage}`);
} else {
console.log('10. 没有错误消息');
}
const pageContent = await page.content();
console.log('11. 页面内容长度:', pageContent.length);
if (currentUrl.includes('dashboard')) {
console.log('✅ 登录成功!已跳转到仪表板');
} else if (currentUrl.includes('login')) {
console.log('❌ 登录失败!仍在登录页面');
} else {
console.log(`⚠️ 意外的URL: ${currentUrl}`);
}
console.log('=== 诊断完成 ===');
});
});