test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名 - 新增 UAT 测试套件与 journey 测试用例 - 优化测试辅助工具与数据工厂 - 更新 playwright 认证状态
This commit is contained in:
@@ -92,12 +92,12 @@ export class TestDataManager {
|
||||
await this.page.goto('/system/config');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
const testRows = this.page.locator('.el-table__row').filter({ hasText: 'test' });
|
||||
const testRows = this.page.locator('.ant-table__row').filter({ hasText: 'test' });
|
||||
const count = await testRows.count();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const row = testRows.nth(i);
|
||||
const deleteButton = row.locator('.el-button--danger').first();
|
||||
const deleteButton = row.locator('.ant-btn--danger').first();
|
||||
|
||||
if (await deleteButton.isVisible()) {
|
||||
await deleteButton.click();
|
||||
@@ -121,12 +121,12 @@ export class TestDataManager {
|
||||
await this.page.goto('/system/notice');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
const testRows = this.page.locator('.el-table__row').filter({ hasText: '测试通知' });
|
||||
const testRows = this.page.locator('.ant-table__row').filter({ hasText: '测试通知' });
|
||||
const count = await testRows.count();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const row = testRows.nth(i);
|
||||
const deleteButton = row.locator('.el-button--danger').first();
|
||||
const deleteButton = row.locator('.ant-btn--danger').first();
|
||||
|
||||
if (await deleteButton.isVisible()) {
|
||||
await deleteButton.click();
|
||||
@@ -150,12 +150,12 @@ export class TestDataManager {
|
||||
await this.page.goto('/files');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
const testRows = this.page.locator('.el-table__row').filter({ hasText: 'test' });
|
||||
const testRows = this.page.locator('.ant-table__row').filter({ hasText: 'test' });
|
||||
const count = await testRows.count();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const row = testRows.nth(i);
|
||||
const deleteButton = row.locator('.el-button--danger').first();
|
||||
const deleteButton = row.locator('.ant-btn--danger').first();
|
||||
|
||||
if (await deleteButton.isVisible()) {
|
||||
await deleteButton.click();
|
||||
|
||||
@@ -57,12 +57,12 @@ export class TestStabilityHelper {
|
||||
|
||||
async handleModal(): Promise<void> {
|
||||
try {
|
||||
const modal = this.page.locator('.el-dialog, .el-message-box');
|
||||
const modal = this.page.locator('.ant-modal, .ant-message-box');
|
||||
const isVisible = await modal.isVisible({ timeout: 2000 });
|
||||
|
||||
if (isVisible) {
|
||||
const confirmButton = modal.locator('.el-button--primary').first();
|
||||
const cancelButton = modal.locator('.el-button--default').first();
|
||||
const confirmButton = modal.locator('.ant-btn--primary').first();
|
||||
const cancelButton = modal.locator('.ant-btn--default').first();
|
||||
|
||||
if (await confirmButton.isVisible({ timeout: 1000 })) {
|
||||
await confirmButton.click();
|
||||
@@ -77,7 +77,7 @@ export class TestStabilityHelper {
|
||||
|
||||
async waitForLoadingComplete(): Promise<void> {
|
||||
try {
|
||||
const loading = this.page.locator('.el-loading-mask, .loading');
|
||||
const loading = this.page.locator('.ant-spin-container, .loading');
|
||||
await loading.waitFor({ state: 'hidden', timeout: 10000 });
|
||||
} catch (error) {
|
||||
console.log('Loading element not found or timeout');
|
||||
@@ -95,7 +95,7 @@ export class TestStabilityHelper {
|
||||
const table = this.page.locator(tableSelector);
|
||||
await expect(table).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const rows = table.locator('.el-table__row');
|
||||
const rows = table.locator('.ant-table__row');
|
||||
const rowCount = await rows.count();
|
||||
expect(rowCount).toBeGreaterThanOrEqual(minRows);
|
||||
});
|
||||
@@ -125,7 +125,7 @@ export class TestStabilityHelper {
|
||||
|
||||
async getErrorMessage(): Promise<string | null> {
|
||||
try {
|
||||
const errorElement = this.page.locator('.el-message--error, .error-message');
|
||||
const errorElement = this.page.locator('.ant-message-error, .error-message');
|
||||
const isVisible = await errorElement.isVisible({ timeout: 2000 });
|
||||
|
||||
if (isVisible) {
|
||||
|
||||
@@ -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