增加 后端,后台管理系统,uniapp会员端的自动化测试。

This commit is contained in:
2026-07-21 18:09:29 +08:00
parent df0e68469b
commit 6b60b3b4da
64 changed files with 13095 additions and 376 deletions
@@ -0,0 +1,57 @@
import { Page, Locator, expect } from '@playwright/test';
export class BannerManagementPage {
readonly page: Page;
readonly table: Locator;
readonly createButton: Locator;
readonly searchInput: Locator;
readonly searchButton: Locator;
readonly successMessage: Locator;
readonly pagination: 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[name*="keyword"]'));
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.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
}
async goto() {
console.log('导航到轮播图管理页面...');
await this.page.goto('/banners');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*banners/);
console.log('轮播图管理页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async clickCreate() {
await this.createButton.click();
await this.page.waitForTimeout(500);
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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,57 @@
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 pagination: 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[name*="keyword"]'));
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.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
}
async goto() {
console.log('导航到教练管理页面...');
await this.page.goto('/coach');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*coach/);
console.log('教练管理页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async clickCreate() {
await this.createButton.click();
await this.page.waitForTimeout(500);
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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,55 @@
import { Page, Locator, expect } from '@playwright/test';
export class CourseLabelManagementPage {
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[name*="keyword"]'));
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() {
console.log('导航到团课标签页面...');
await this.page.goto('/courses/labels');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*courses\/labels/);
console.log('团课标签页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async clickCreate() {
await this.createButton.click();
await this.page.waitForTimeout(500);
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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,55 @@
import { Page, Locator, expect } from '@playwright/test';
export class CourseRecommendManagementPage {
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[name*="keyword"]'));
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() {
console.log('导航到团课推荐页面...');
await this.page.goto('/courses/recommend');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*courses\/recommend/);
console.log('团课推荐页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async clickCreate() {
await this.createButton.click();
await this.page.waitForTimeout(500);
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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,55 @@
import { Page, Locator, expect } from '@playwright/test';
export class CourseTypeManagementPage {
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[name*="keyword"]'));
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() {
console.log('导航到团课类型页面...');
await this.page.goto('/courses/types');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*courses\/types/);
console.log('团课类型页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async clickCreate() {
await this.createButton.click();
await this.page.waitForTimeout(500);
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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,61 @@
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;
readonly pagination: 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[name*="keyword"]'));
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.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
}
async goto() {
console.log('导航到团课管理页面...');
await this.page.goto('/courses');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*courses/);
console.log('团课管理页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async clickCreate() {
await this.createButton.click();
await this.page.waitForTimeout(500);
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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 editRow(rowNumber: number) {
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).click();
}
}
@@ -0,0 +1,50 @@
import { Page, Locator, expect } from '@playwright/test';
export class MemberCardManagementPage {
readonly page: Page;
readonly table: Locator;
readonly searchInput: Locator;
readonly searchButton: Locator;
readonly successMessage: Locator;
readonly pagination: 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.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
this.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
}
async goto() {
console.log('导航到会员卡管理页面...');
await this.page.goto('/member-cards');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*member-cards/);
console.log('会员卡管理页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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,54 @@
import { Page, Locator, expect } from '@playwright/test';
export class MemberManagementPage {
readonly page: Page;
readonly table: Locator;
readonly searchInput: Locator;
readonly searchButton: Locator;
readonly successMessage: Locator;
readonly pagination: 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.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
this.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
}
async goto() {
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('会员管理页面加载完成');
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
{ timeout: 5000 }
).catch(() => console.log('表格没有数据,继续执行'));
}
async search(keyword: string) {
await this.searchInput.fill(keyword);
await this.searchButton.click();
await this.page.waitForTimeout(500);
}
async getRowCount(): 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 viewMember(rowNumber: number) {
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '查看' }).click();
}
}
@@ -0,0 +1,37 @@
import { Page, Locator, expect } from '@playwright/test';
export class StatisticsDashboardPage {
readonly page: Page;
readonly dashboard: Locator;
readonly chartArea: Locator;
constructor(page: Page) {
this.page = page;
this.dashboard = page.locator('.statistics-dashboard, .dashboard-container');
this.chartArea = page.locator('.chart, [class*="chart"], canvas');
}
async goto() {
console.log('导航到数据统计看板...');
await this.page.goto('/statistics');
await this.page.waitForLoadState('networkidle');
await expect(this.page).toHaveURL(/.*statistics/);
console.log('数据统计看板加载完成');
}
async isDashboardVisible(): Promise<boolean> {
try {
return await this.dashboard.isVisible({ timeout: 10000 });
} catch {
return await this.page.locator('body').isVisible();
}
}
async getChartCount(): Promise<number> {
return await this.chartArea.count();
}
async containsText(text: string): Promise<boolean> {
return await this.page.getByText(text).count() > 0;
}
}