08ea5fbe98
添加用户管理视图、API和状态管理文件
89 lines
2.9 KiB
TypeScript
89 lines
2.9 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
/**
|
|
* 登录功能调试测试
|
|
* 用于验证登录功能是否正常工作
|
|
*/
|
|
|
|
test.describe('登录功能调试', () => {
|
|
test('应该能够访问登录页面', async ({ page }) => {
|
|
// 访问登录页面
|
|
await page.goto('http://localhost:5174/login');
|
|
|
|
// 等待页面加载
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 截图记录
|
|
await page.screenshot({ path: '/tmp/login-page.png', fullPage: true });
|
|
|
|
// 验证页面标题
|
|
const title = await page.title();
|
|
console.log('页面标题:', title);
|
|
expect(title).toContain('Admin');
|
|
|
|
// 验证登录表单存在(使用placeholder定位)
|
|
const usernameInput = page.locator('input[placeholder="请输入用户名"]');
|
|
await expect(usernameInput).toBeVisible();
|
|
|
|
console.log('✅ 登录页面访问成功');
|
|
});
|
|
|
|
test('应该能够登录成功', async ({ page }) => {
|
|
// 访问登录页面
|
|
await page.goto('http://localhost:5174/login');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 监听网络请求
|
|
page.on('request', request => {
|
|
if (request.url().includes('login')) {
|
|
console.log('📤 登录请求:', request.method(), request.url());
|
|
}
|
|
});
|
|
|
|
page.on('response', response => {
|
|
if (response.url().includes('login')) {
|
|
console.log('📥 登录响应:', response.status(), response.url());
|
|
response.text().then(text => {
|
|
console.log('响应内容:', text.substring(0, 200));
|
|
}).catch(() => {});
|
|
}
|
|
});
|
|
|
|
// 填写登录表单(使用演示账号密码)
|
|
console.log('📝 填写用户名...');
|
|
await page.fill('input[placeholder="请输入用户名"]', 'admin');
|
|
|
|
console.log('📝 填写密码...');
|
|
await page.fill('input[placeholder="请输入密码"]', 'admin123456');
|
|
|
|
// 截图记录填写后的状态
|
|
await page.screenshot({ path: '/tmp/login-filled.png', fullPage: true });
|
|
|
|
// 点击登录按钮
|
|
console.log('🖱️ 点击登录按钮...');
|
|
await page.click('button[type="submit"]');
|
|
|
|
// 等待响应
|
|
await page.waitForTimeout(3000);
|
|
|
|
// 截图记录结果
|
|
await page.screenshot({ path: '/tmp/login-result.png', fullPage: true });
|
|
|
|
// 检查是否登录成功(跳转到仪表盘或显示错误)
|
|
const currentUrl = page.url();
|
|
console.log('当前URL:', currentUrl);
|
|
|
|
if (currentUrl.includes('dashboard')) {
|
|
console.log('✅ 登录成功,已跳转到仪表盘');
|
|
} else if (currentUrl.includes('login')) {
|
|
// 检查是否有错误消息
|
|
const errorMessage = await page.locator('.el-message--error').textContent().catch(() => null);
|
|
if (errorMessage) {
|
|
console.log('❌ 登录失败,错误信息:', errorMessage);
|
|
} else {
|
|
console.log('⚠️ 仍在登录页面,可能没有错误提示');
|
|
}
|
|
}
|
|
});
|
|
});
|