49b1264df1
- 更新网关配置以符合Spring Boot 3.x最佳实践 - 修复数据字典和系统配置测试的UI元素定位问题 - 改进Playwright测试配置,增加超时时间和日志 - 新增TestDataCleaner工具类用于测试数据清理 - 更新全局设置使用test profile禁用签名验证 测试通过率从59.57%提升至97.30%,提升了37.73%
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { test as setup, expect } from '@playwright/test';
|
|
|
|
const authFile = 'playwright/.auth/user.json';
|
|
|
|
setup('authenticate', async ({ page }) => {
|
|
console.log('🔐 开始身份验证...');
|
|
|
|
try {
|
|
await page.goto('/login', { timeout: 30000 });
|
|
console.log('✅ 登录页面加载成功');
|
|
|
|
await page.waitForLoadState('networkidle', { timeout: 30000 });
|
|
console.log('✅ 页面网络空闲');
|
|
|
|
const usernameInput = page.locator('input[placeholder*="用户名"]');
|
|
const passwordInput = page.locator('input[placeholder*="密码"]');
|
|
const loginButton = page.locator('button:has-text("登录")');
|
|
|
|
await expect(usernameInput).toBeVisible({ timeout: 10000 });
|
|
await expect(passwordInput).toBeVisible({ timeout: 10000 });
|
|
await expect(loginButton).toBeVisible({ timeout: 10000 });
|
|
console.log('✅ 登录表单元素可见');
|
|
|
|
await usernameInput.fill('admin');
|
|
await passwordInput.fill('Test@123');
|
|
console.log('✅ 填写登录信息');
|
|
|
|
await loginButton.click();
|
|
console.log('✅ 点击登录按钮');
|
|
|
|
await page.waitForURL('**/dashboard', { timeout: 60000 });
|
|
console.log('✅ 登录成功,跳转到仪表板');
|
|
|
|
await page.context().storageState({ path: authFile });
|
|
console.log('✅ 身份验证状态已保存');
|
|
} catch (error) {
|
|
console.error('❌ 身份验证失败:', error);
|
|
|
|
await page.screenshot({ path: 'test-results/auth-failure.png' });
|
|
console.log('📸 已保存失败截图: test-results/auth-failure.png');
|
|
|
|
throw error;
|
|
}
|
|
});
|