test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名 - 新增 UAT 测试套件与 journey 测试用例 - 优化测试辅助工具与数据工厂 - 更新 playwright 认证状态
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
import { Page } from '@playwright/test';
|
||||
import { LoginPage } from '../pages/LoginPage';
|
||||
|
||||
export async function loginAsAdmin(page: Page) {
|
||||
await page.goto('/login');
|
||||
export async function loginAsAdmin(page: Page): Promise<void> {
|
||||
const loginPage = new LoginPage(page);
|
||||
await loginPage.goto();
|
||||
await loginPage.login('admin', 'Test@123');
|
||||
}
|
||||
|
||||
export async function logout(page: Page): Promise<void> {
|
||||
const loginPage = new LoginPage(page);
|
||||
await loginPage.logout();
|
||||
}
|
||||
|
||||
export async function navigateViaMenu(page: Page, menuLabel: string, subMenuLabel: string): Promise<void> {
|
||||
const subMenu = page.locator(`.ant-menu-submenu-title:has-text("${menuLabel}")`);
|
||||
if (await subMenu.isVisible()) {
|
||||
await subMenu.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
const menuItem = page.locator(`.ant-menu-item:has-text("${subMenuLabel}")`);
|
||||
await menuItem.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.locator('input[placeholder*="用户名"]').fill('admin');
|
||||
await page.locator('input[placeholder*="密码"]').fill('Test@123');
|
||||
await page.locator('button:has-text("登录")').click();
|
||||
|
||||
await page.waitForURL('**/dashboard', { timeout: 30000 });
|
||||
|
||||
const token = await page.evaluate(() => {
|
||||
return localStorage.getItem('token') || '';
|
||||
});
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function saveAuthState(page: Page) {
|
||||
const storage = await page.context().storageState();
|
||||
return storage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user