新增e2e测试脚本,修复部分问题
This commit was merged in pull request #51.
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class CheckInManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly datePicker: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').first();
|
||||
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.datePicker = page.locator('.el-date-editor').or(page.locator('.el-date-picker'));
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到数据统计页面(含签到统计)...');
|
||||
await this.page.goto('/statistics');
|
||||
|
||||
await this.page.waitForURL('**/statistics', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
// statistics page uses stat cards, not tables
|
||||
const statCard = this.page.locator('.stat-card, .el-card, .summary-card');
|
||||
await statCard.first().waitFor({ state: 'visible', timeout: 15000 });
|
||||
|
||||
await expect(this.page).toHaveURL(/.*statistics/);
|
||||
|
||||
console.log('数据统计页面加载完成(签到管理查看)');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/checkin-management-error-${Date.now()}.png` });
|
||||
console.error('导航到签到管理页面失败:', error);
|
||||
throw new Error(`导航到签到管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async waitForTableReady() {
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
).catch(() => {
|
||||
console.log('表格没有数据,继续执行');
|
||||
});
|
||||
}
|
||||
|
||||
async searchByDate(date: string) {
|
||||
const dateInput = this.datePicker.locator('input').first();
|
||||
if (await dateInput.count() > 0) {
|
||||
await dateInput.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await dateInput.fill(date);
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async verifyTableHasRecords(): Promise<boolean> {
|
||||
try {
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
return true;
|
||||
} catch {
|
||||
console.log('签到表格没有记录');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getRecordCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async verifySignInDataLoaded(): Promise<boolean> {
|
||||
try {
|
||||
const signInSection = this.page.locator('.stat-card, .el-card, .signin-section, .chart-container');
|
||||
await signInSection.first().waitFor({ state: 'visible', timeout: 10000 });
|
||||
console.log('签到数据区域已加载');
|
||||
return true;
|
||||
} catch {
|
||||
console.log('签到数据区域未找到,尝试备选方式');
|
||||
return await this.verifyTableHasRecords();
|
||||
}
|
||||
}
|
||||
|
||||
async getTotalSignIns(): Promise<string> {
|
||||
const statCards = this.page.locator('.stat-card');
|
||||
if (await statCards.count() > 0) {
|
||||
return (await statCards.nth(0).textContent()) || '0';
|
||||
}
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
async getSuccessSignIns(): Promise<string> {
|
||||
const statCards = this.page.locator('.stat-card');
|
||||
if (await statCards.count() > 1) {
|
||||
return (await statCards.nth(1).textContent()) || '0';
|
||||
}
|
||||
return 'N/A';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class CoachManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly nicknameInput: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').first();
|
||||
this.createButton = page.getByRole('button', { name: '新增教练' }).or(page.locator('button:has-text("新增教练")'));
|
||||
this.searchInput = page.locator('input[placeholder*="搜索教练"]').or(page.locator('input[placeholder*="搜索"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
this.nicknameInput = page.locator('.el-dialog .el-form-item').filter({ hasText: '昵称' }).or(page.locator('.el-dialog .el-form-item').filter({ hasText: '姓名' })).locator('input');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到教练管理页面...');
|
||||
await this.page.goto('/coach');
|
||||
|
||||
await this.page.waitForURL('**/coach', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 });
|
||||
|
||||
await expect(this.page).toHaveURL(/.*coach/);
|
||||
|
||||
console.log('教练管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/coach-management-error-${Date.now()}.png` });
|
||||
|
||||
console.error('导航到教练管理页面失败:', error);
|
||||
|
||||
throw new Error(`导航到教练管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async waitForTableReady() {
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
).catch(() => {
|
||||
console.log('表格没有数据,继续执行');
|
||||
});
|
||||
}
|
||||
|
||||
async clickCreate() {
|
||||
await this.createButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async fillCoachForm(coachData: {
|
||||
name?: string;
|
||||
nickname?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}) {
|
||||
// Normalize property names from spec
|
||||
const name = coachData.name || coachData.nickname || '';
|
||||
const phone = coachData.phone || '';
|
||||
const email = coachData.email || '';
|
||||
const username = coachData.username || '';
|
||||
const password = coachData.password || '';
|
||||
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
|
||||
// 姓名 / 昵称
|
||||
const nameInput = dialog.locator('.el-form-item').filter({ hasText: '姓名' }).or(dialog.locator('.el-form-item').filter({ hasText: '昵称' })).locator('input');
|
||||
if (await nameInput.count() > 0) {
|
||||
await nameInput.fill(name);
|
||||
} else if (await dialog.locator('input').count() > 0) {
|
||||
await dialog.locator('input').first().fill(name);
|
||||
}
|
||||
|
||||
// 手机号
|
||||
const phoneInput = dialog.locator('.el-form-item').filter({ hasText: '手机' }).locator('input');
|
||||
if (await phoneInput.count() > 0) {
|
||||
await phoneInput.fill(phone);
|
||||
} else if (await dialog.locator('input').count() > 1) {
|
||||
await dialog.locator('input').nth(1).fill(phone);
|
||||
}
|
||||
|
||||
// 邮箱
|
||||
const emailInput = dialog.locator('.el-form-item').filter({ hasText: '邮箱' }).locator('input');
|
||||
if (await emailInput.count() > 0) {
|
||||
await emailInput.fill(email);
|
||||
} else if (await dialog.locator('input').count() > 2) {
|
||||
await dialog.locator('input').nth(2).fill(email);
|
||||
}
|
||||
|
||||
// 用户名
|
||||
const usernameInput = dialog.locator('.el-form-item').filter({ hasText: '用户名' }).locator('input');
|
||||
if (await usernameInput.count() > 0) {
|
||||
await usernameInput.fill(username);
|
||||
} else if (await dialog.locator('input').count() > 3) {
|
||||
await dialog.locator('input').nth(3).fill(username);
|
||||
}
|
||||
|
||||
// 密码
|
||||
const passwordInput = dialog.locator('input[type="password"]');
|
||||
if (await passwordInput.count() > 0) {
|
||||
await passwordInput.fill(password);
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const submitButton = dialog.getByRole('button', { name: '确定' }).or(dialog.locator('button:has-text("确定")'));
|
||||
|
||||
await submitButton.click();
|
||||
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async waitForSuccessMessage(timeout: number = 10000): Promise<boolean> {
|
||||
try {
|
||||
const message = this.page.locator('.el-message--success').or(this.page.locator('.el-message'));
|
||||
await message.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log('等待成功消息超时,检查是否有错误消息');
|
||||
|
||||
try {
|
||||
const errorMessage = this.page.locator('.el-message--error').or(this.page.locator('.el-message--warning'));
|
||||
if (await errorMessage.count() > 0) {
|
||||
const errorText = await errorMessage.first().textContent();
|
||||
console.log('发现错误消息:', errorText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('没有发现错误消息');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async editCoach(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .edit-button`)).click();
|
||||
}
|
||||
|
||||
async deleteCoach(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '删除' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
const confirmDialog = this.page.locator('.el-message-box');
|
||||
await confirmDialog.getByRole('button', { name: '确定' }).or(confirmDialog.locator('button:has-text("确定")')).click();
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async isSuccessMessageVisible(): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async clickAdd(): Promise<void> {
|
||||
await this.clickCreate();
|
||||
}
|
||||
|
||||
async waitForDialogClose(): Promise<void> {
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.page.locator('.el-dialog').waitFor({ state: 'hidden', timeout: 10000 }).catch(() => {
|
||||
console.log('对话框可能已关闭或不存在');
|
||||
});
|
||||
}
|
||||
|
||||
async clickEditOnFirstRow(): Promise<void> {
|
||||
await this.editCoach(1);
|
||||
}
|
||||
|
||||
async getCoachCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,54 @@ export class DashboardPage {
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Gym 业务模块导航方法
|
||||
// ============================================
|
||||
|
||||
async navigateToMemberManagement() {
|
||||
const memberMenu = this.page.locator('.el-sub-menu__title:has-text("会员管理")');
|
||||
await memberMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
const memberMenuItem = this.page.locator('.el-menu-item:has-text("会员管理")');
|
||||
await memberMenuItem.click();
|
||||
await this.page.waitForURL('**/members', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToGroupCourseManagement() {
|
||||
const courseMenu = this.page.locator('.el-sub-menu__title:has-text("团课管理")');
|
||||
await courseMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
const courseMenuItem = this.page.locator('.el-menu-item:has-text("团课管理")');
|
||||
await courseMenuItem.click();
|
||||
await this.page.waitForURL('**/group-courses', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToCoachManagement() {
|
||||
const coachMenuItem = this.page.locator('.el-menu-item:has-text("教练管理")');
|
||||
await coachMenuItem.click();
|
||||
await this.page.waitForURL('**/coaches', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToCheckInManagement() {
|
||||
const checkInMenuItem = this.page.locator('.el-menu-item:has-text("签到管理")');
|
||||
await checkInMenuItem.click();
|
||||
await this.page.waitForURL('**/checkin', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToStatisticsDashboard() {
|
||||
const statsMenu = this.page.locator('.el-sub-menu__title:has-text("数据统计")');
|
||||
await statsMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
const statsMenuItem = this.page.locator('.el-menu-item:has-text("数据统计看板")');
|
||||
await statsMenuItem.click();
|
||||
await this.page.waitForURL('**/statistics', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async getUsername(): Promise<string | null> {
|
||||
return await this.userInfo.textContent();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class GroupCourseManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').first();
|
||||
this.createButton = page.getByRole('button', { name: '新增团课' }).or(page.locator('button:has-text("新增团课")'));
|
||||
this.searchInput = page.locator('input[placeholder*="搜索课程"]').or(page.locator('input[placeholder*="搜索"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到团课管理页面...');
|
||||
await this.page.goto('/courses');
|
||||
|
||||
await this.page.waitForURL('**/courses', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 });
|
||||
|
||||
await expect(this.page).toHaveURL(/.*courses/);
|
||||
|
||||
console.log('团课管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/group-course-management-error-${Date.now()}.png` });
|
||||
|
||||
console.error('导航到团课管理页面失败:', error);
|
||||
|
||||
throw new Error(`导航到团课管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async waitForTableReady() {
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
).catch(() => {
|
||||
console.log('表格没有数据,继续执行');
|
||||
});
|
||||
}
|
||||
|
||||
async clickCreate() {
|
||||
await this.createButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async fillCourseForm(courseData: {
|
||||
name?: string;
|
||||
courseName?: string;
|
||||
typeId?: string;
|
||||
coachId?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
duration?: number;
|
||||
location?: string;
|
||||
maxMembers?: number | string;
|
||||
description?: string;
|
||||
}) {
|
||||
// Normalize property names from spec to POM
|
||||
const name = courseData.name || courseData.courseName || '';
|
||||
const startTime = courseData.startTime || '';
|
||||
const endTime = courseData.endTime || courseData.startTime || '';
|
||||
const location = courseData.location || '';
|
||||
const maxMembers = String(courseData.maxMembers || '30');
|
||||
const typeId = courseData.typeId;
|
||||
const coachId = courseData.coachId;
|
||||
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
|
||||
// 课程名称
|
||||
const nameInput = dialog.locator('.el-form-item').filter({ hasText: '课程名称' }).locator('input');
|
||||
if (await nameInput.count() > 0) {
|
||||
await nameInput.fill(name);
|
||||
} else {
|
||||
await dialog.locator('input').first().fill(name);
|
||||
}
|
||||
|
||||
// 课程类型(下拉选择)
|
||||
const typeSelect = dialog.locator('.el-form-item').filter({ hasText: '课程类型' }).locator('.el-select');
|
||||
if (await typeSelect.count() > 0) {
|
||||
await typeSelect.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const dropdown = this.page.locator('.el-select-dropdown:not(.is-hidden)').or(this.page.locator('.el-popper:not([style*="display: none"])'));
|
||||
await dropdown.first().waitFor({ state: 'visible', timeout: 5000 }).catch(() => {
|
||||
console.log('课程类型下拉框未显示,使用body层级定位');
|
||||
});
|
||||
const options = this.page.locator('.el-select-dropdown__item').or(this.page.locator('.el-popper .el-select-dropdown__item'));
|
||||
const visibleOptions = options.locator('visible=true');
|
||||
const optionCount = await visibleOptions.count();
|
||||
|
||||
if (optionCount > 0) {
|
||||
if (typeId) {
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await visibleOptions.nth(i).textContent();
|
||||
if (optionText && optionText.includes(typeId)) {
|
||||
await visibleOptions.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await visibleOptions.first().click();
|
||||
}
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
// 教练(下拉选择)
|
||||
const coachSelect = dialog.locator('.el-form-item').filter({ hasText: '教练' }).locator('.el-select');
|
||||
if (await coachSelect.count() > 0) {
|
||||
await coachSelect.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const options = this.page.locator('.el-select-dropdown__item').or(this.page.locator('.el-popper .el-select-dropdown__item'));
|
||||
const visibleOptions = options.locator('visible=true');
|
||||
const optionCount = await visibleOptions.count();
|
||||
|
||||
if (optionCount > 0) {
|
||||
if (coachId) {
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await visibleOptions.nth(i).textContent();
|
||||
if (optionText && optionText.includes(coachId)) {
|
||||
await visibleOptions.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await visibleOptions.first().click();
|
||||
}
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
// 开始时间(日期时间选择器)
|
||||
const startTimeInput = dialog.locator('.el-form-item').filter({ hasText: '开始时间' }).locator('input');
|
||||
if (await startTimeInput.count() > 0) {
|
||||
await startTimeInput.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await startTimeInput.fill(startTime);
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
// 结束时间(日期时间选择器)
|
||||
const endTimeInput = dialog.locator('.el-form-item').filter({ hasText: '结束时间' }).locator('input');
|
||||
if (await endTimeInput.count() > 0) {
|
||||
await endTimeInput.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await endTimeInput.fill(endTime);
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
// 上课地点
|
||||
const locationInput = dialog.locator('.el-form-item').filter({ hasText: '地点' }).or(dialog.locator('.el-form-item').filter({ hasText: '上课地点' })).locator('input');
|
||||
if (await locationInput.count() > 0) {
|
||||
await locationInput.fill(location);
|
||||
}
|
||||
|
||||
// 人数上限
|
||||
const maxMembersInput = dialog.locator('.el-form-item').filter({ hasText: '人数' }).or(dialog.locator('.el-form-item').filter({ hasText: '上限' })).locator('input');
|
||||
if (await maxMembersInput.count() > 0) {
|
||||
await maxMembersInput.fill(maxMembers);
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const submitButton = dialog.getByRole('button', { name: '确定' }).or(dialog.locator('button:has-text("确定")'));
|
||||
|
||||
await submitButton.click();
|
||||
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async waitForSuccessMessage(timeout: number = 10000): Promise<boolean> {
|
||||
try {
|
||||
const message = this.page.locator('.el-message--success').or(this.page.locator('.el-message'));
|
||||
await message.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log('等待成功消息超时,检查是否有错误消息');
|
||||
|
||||
try {
|
||||
const errorMessage = this.page.locator('.el-message--error').or(this.page.locator('.el-message--warning'));
|
||||
if (await errorMessage.count() > 0) {
|
||||
const errorText = await errorMessage.first().textContent();
|
||||
console.log('发现错误消息:', errorText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('没有发现错误消息');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async editCourse(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .edit-button`)).click();
|
||||
}
|
||||
|
||||
async deleteCourse(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '删除' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
const confirmDialog = this.page.locator('.el-message-box');
|
||||
await confirmDialog.getByRole('button', { name: '确定' }).or(confirmDialog.locator('button:has-text("确定")')).click();
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async isSuccessMessageVisible(): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async clickAdd(): Promise<void> {
|
||||
await this.clickCreate();
|
||||
}
|
||||
|
||||
async waitForDialogClose(): Promise<void> {
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.page.locator('.el-dialog').waitFor({ state: 'hidden', timeout: 10000 }).catch(() => {
|
||||
console.log('对话框可能已关闭或不存在');
|
||||
});
|
||||
}
|
||||
|
||||
async clickEditOnFirstRow(): Promise<void> {
|
||||
await this.editCourse(1);
|
||||
}
|
||||
|
||||
async clickDeleteOnFirstRow(): Promise<void> {
|
||||
await this.deleteCourse(1);
|
||||
}
|
||||
|
||||
async getCourseCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class MemberManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').first();
|
||||
this.createButton = page.getByRole('button', { name: '新增会员' }).or(page.locator('button:has-text("新增会员")'));
|
||||
this.searchInput = page.locator('input[placeholder*="搜索会员"]').or(page.locator('input[placeholder*="搜索"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到会员管理页面...');
|
||||
await this.page.goto('/members');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await expect(this.page).toHaveURL(/.*members/);
|
||||
|
||||
console.log('会员管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/member-management-error-${Date.now()}.png` });
|
||||
|
||||
console.error('导航到会员管理页面失败:', error);
|
||||
|
||||
throw new Error(`导航到会员管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async waitForTableReady() {
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
).catch(() => {
|
||||
console.log('表格没有数据,继续执行');
|
||||
});
|
||||
}
|
||||
|
||||
async clickCreate() {
|
||||
await this.createButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async fillMemberForm(memberData: {
|
||||
name: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
gender: string;
|
||||
}) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
|
||||
const inputs = dialog.locator('input');
|
||||
|
||||
// 姓名
|
||||
const nameInput = dialog.locator('.el-form-item').filter({ hasText: '姓名' }).locator('input');
|
||||
if (await nameInput.count() > 0) {
|
||||
await nameInput.fill(memberData.name);
|
||||
} else if (await inputs.count() > 0) {
|
||||
await inputs.first().fill(memberData.name);
|
||||
}
|
||||
|
||||
// 手机号
|
||||
const phoneInput = dialog.locator('.el-form-item').filter({ hasText: '手机' }).locator('input');
|
||||
if (await phoneInput.count() > 0) {
|
||||
await phoneInput.fill(memberData.phone);
|
||||
} else if (await inputs.count() > 1) {
|
||||
await inputs.nth(1).fill(memberData.phone);
|
||||
}
|
||||
|
||||
// 邮箱
|
||||
const emailInput = dialog.locator('.el-form-item').filter({ hasText: '邮箱' }).locator('input');
|
||||
if (await emailInput.count() > 0) {
|
||||
await emailInput.fill(memberData.email);
|
||||
} else if (await inputs.count() > 2) {
|
||||
await inputs.nth(2).fill(memberData.email);
|
||||
}
|
||||
|
||||
// 性别(下拉选择)
|
||||
if (memberData.gender) {
|
||||
const genderSelect = dialog.locator('.el-form-item').filter({ hasText: '性别' }).locator('.el-select');
|
||||
if (await genderSelect.count() > 0) {
|
||||
await genderSelect.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const genderText = memberData.gender === '1' || memberData.gender === '男' ? '男' : '女';
|
||||
const dropdown = this.page.locator('.el-select-dropdown');
|
||||
if (await dropdown.count() > 0) {
|
||||
const options = dropdown.locator('.el-select-dropdown__item');
|
||||
const optionCount = await options.count();
|
||||
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await options.nth(i).textContent();
|
||||
if (optionText && optionText.includes(genderText)) {
|
||||
await options.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const submitButton = dialog.getByRole('button', { name: '确定' }).or(dialog.locator('button:has-text("确定")'));
|
||||
|
||||
await submitButton.click();
|
||||
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async waitForSuccessMessage(timeout: number = 10000): Promise<boolean> {
|
||||
try {
|
||||
const message = this.page.locator('.el-message--success').or(this.page.locator('.el-message'));
|
||||
await message.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log('等待成功消息超时,检查是否有错误消息');
|
||||
|
||||
try {
|
||||
const errorMessage = this.page.locator('.el-message--error').or(this.page.locator('.el-message--warning'));
|
||||
if (await errorMessage.count() > 0) {
|
||||
const errorText = await errorMessage.first().textContent();
|
||||
console.log('发现错误消息:', errorText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('没有发现错误消息');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async editMember(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .edit-button`)).click();
|
||||
}
|
||||
|
||||
async deleteMember(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '删除' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
const confirmDialog = this.page.locator('.el-message-box');
|
||||
await confirmDialog.getByRole('button', { name: '确定' }).or(confirmDialog.locator('button:has-text("确定")')).click();
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async isSuccessMessageVisible(): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getMemberCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async clickEditOnFirstRow(): Promise<void> {
|
||||
await this.editMember(1);
|
||||
}
|
||||
|
||||
async fillEditForm(newNickname: string, gender: string): Promise<void> {
|
||||
await this.fillMemberForm({ name: newNickname, phone: '', email: '', gender });
|
||||
}
|
||||
|
||||
async clickAdd(): Promise<void> {
|
||||
await this.clickCreate();
|
||||
}
|
||||
|
||||
async waitForDialogClose(): Promise<void> {
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.page.locator('.el-dialog').waitFor({ state: 'hidden', timeout: 10000 }).catch(() => {
|
||||
console.log('对话框可能已关闭或不存在');
|
||||
});
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class StatisticsDashboardPage {
|
||||
readonly page: Page;
|
||||
readonly summaryCards: Locator;
|
||||
readonly statCards: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.summaryCards = page.locator('.el-card').or(page.locator('.statistics-card')).or(page.locator('.summary-card')).or(page.locator('.dashboard-card'));
|
||||
this.statCards = page.locator('.stat-card').or(page.locator('.el-card')).or(page.locator('.summary-card'));
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到数据统计页面...');
|
||||
await this.page.goto('/statistics');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(this.page).toHaveURL(/.*statistics/);
|
||||
|
||||
console.log('数据统计页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/statistics-dashboard-error-${Date.now()}.png` });
|
||||
|
||||
console.error('导航到数据统计页面失败:', error);
|
||||
|
||||
throw new Error(`导航到数据统计页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async verifyStatisticsLoaded(): Promise<boolean> {
|
||||
try {
|
||||
await this.summaryCards.first().waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
const cardCount = await this.summaryCards.count();
|
||||
console.log(`数据统计页面加载完成,找到 ${cardCount} 个统计卡片`);
|
||||
|
||||
return cardCount > 0;
|
||||
} catch (error) {
|
||||
console.log('统计卡片未找到,尝试备选选择器');
|
||||
|
||||
const altCards = this.page.locator('.statistics-container').or(this.page.locator('.dashboard-container'));
|
||||
if (await altCards.count() > 0) {
|
||||
await altCards.first().waitFor({ state: 'visible', timeout: 10000 });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getSummaryCardCount(): Promise<number> {
|
||||
return await this.summaryCards.count();
|
||||
}
|
||||
|
||||
async getSummaryCardText(index: number): Promise<string | null> {
|
||||
if (await this.summaryCards.count() > index) {
|
||||
return await this.summaryCards.nth(index).textContent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async verifyStatCardsLoaded(): Promise<boolean> {
|
||||
try {
|
||||
await this.statCards.first().waitFor({ state: 'visible', timeout: 15000 });
|
||||
const cardCount = await this.statCards.count();
|
||||
console.log(`统计卡片加载完成,共 ${cardCount} 个`);
|
||||
return cardCount > 0;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getCardValue(index: number): Promise<string> {
|
||||
const cards = this.statCards;
|
||||
if (await cards.count() > index) {
|
||||
return (await cards.nth(index).textContent()) || '0';
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
async verifySectionCardsLoaded(): Promise<void> {
|
||||
await this.page.waitForTimeout(500);
|
||||
const allCards = this.page.locator('.el-card, .stat-card, .chart-container');
|
||||
if (await allCards.count() > 0) {
|
||||
console.log(`详细统计区域已加载,共 ${await allCards.count()} 个卡片/图表`);
|
||||
}
|
||||
}
|
||||
|
||||
async switchRange(range: string): Promise<void> {
|
||||
const rangeBtn = this.page.locator('.el-radio-button').filter({ hasText: range }).or(this.page.locator('button').filter({ hasText: range }));
|
||||
if (await rangeBtn.count() > 0) {
|
||||
await rangeBtn.first().click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
}
|
||||
|
||||
async switchTab(tabName: string): Promise<void> {
|
||||
const tab = this.page.locator('.el-tabs__item').filter({ hasText: tabName }).or(this.page.locator('.el-tab-pane')).filter({ hasText: tabName }).or(this.page.locator('[role="tab"]').filter({ hasText: tabName }));
|
||||
if (await tab.count() > 0) {
|
||||
await tab.first().click();
|
||||
await this.page.waitForTimeout(800);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user