f882599072
- 添加waitForSuccessMessage()方法到UserManagementPage和RoleManagementPage - 改进submitForm()方法,添加等待时间 - 更新测试用例使用新的等待方法 - 增加错误消息检测和日志输出 - 修复权限选择器问题(使用.el-tree替代固定value)
80 lines
3.0 KiB
TypeScript
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('Test@123');
|
|
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('=== 诊断完成 ===');
|
|
});
|
|
});
|