08ea5fbe98
添加用户管理视图、API和状态管理文件
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { MockManager } from './mock-manager';
|
|
|
|
test('调试登录功能', async ({ page }) => {
|
|
const mockManager = new MockManager({
|
|
enabled: true,
|
|
mode: 'full',
|
|
mockPaths: [],
|
|
delay: 0,
|
|
logCalls: true,
|
|
validateResponses: true,
|
|
dataSource: 'memory'
|
|
});
|
|
|
|
mockManager.presetTestData({
|
|
menus: [
|
|
{
|
|
id: 1,
|
|
name: '仪表盘',
|
|
code: 'dashboard',
|
|
path: '/dashboard',
|
|
icon: 'DashboardOutlined',
|
|
sortOrder: 1,
|
|
status: 'active',
|
|
parentId: 0,
|
|
createBy: 'system',
|
|
updateBy: 'system',
|
|
createdAt: '2024-01-01T00:00:00.000Z',
|
|
updatedAt: '2024-01-01T00:00:00.000Z',
|
|
children: []
|
|
}
|
|
]
|
|
});
|
|
|
|
await mockManager.interceptAPIRequest(page);
|
|
|
|
page.on('console', msg => {
|
|
console.log('Browser Console:', msg.type(), msg.text());
|
|
});
|
|
|
|
page.on('pageerror', error => {
|
|
console.log('Browser Error:', error.message);
|
|
});
|
|
|
|
page.on('request', request => {
|
|
console.log('Request:', request.method(), request.url());
|
|
});
|
|
|
|
page.on('response', async response => {
|
|
const url = response.url();
|
|
if (url.includes('/sys/auth/login')) {
|
|
console.log('Login Response Status:', response.status());
|
|
console.log('Login Response Headers:', response.headers());
|
|
const body = await response.text();
|
|
console.log('Login Response Body:', body);
|
|
}
|
|
});
|
|
|
|
await page.goto('/');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const usernameInput = page.locator('input[placeholder="请输入用户名"]');
|
|
const passwordInput = page.locator('input[placeholder="请输入密码"]');
|
|
const loginButton = page.locator('button[type="submit"]');
|
|
|
|
await usernameInput.waitFor({ state: 'visible', timeout: 10000 });
|
|
await passwordInput.waitFor({ state: 'visible', timeout: 10000 });
|
|
await loginButton.waitFor({ state: 'visible', timeout: 10000 });
|
|
|
|
await usernameInput.fill('admin');
|
|
await passwordInput.fill('admin123');
|
|
|
|
await loginButton.click();
|
|
|
|
await page.waitForTimeout(5000);
|
|
|
|
const currentUrl = page.url();
|
|
console.log('Current URL after login:', currentUrl);
|
|
|
|
const errorMessage = page.locator('.ant-message-error');
|
|
const hasError = await errorMessage.count() > 0;
|
|
if (hasError) {
|
|
const errorText = await errorMessage.textContent();
|
|
console.log('Error message found:', errorText);
|
|
}
|
|
|
|
await page.screenshot({ path: 'debug-login.png' });
|
|
});
|