增加 后端,后台管理系统,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,53 @@
/**
* 课程详情页 Page Object
*/
class CourseDetailPage {
constructor(miniProgram) {
this.mp = miniProgram;
}
async waitForReady() {
const page = await this.mp.currentPage();
await page.waitFor(2000);
console.log('课程详情页加载完成');
}
async getPath() {
const page = await this.mp.currentPage();
return page.path;
}
/**
* 点击预约按钮
*/
async clickBook() {
const page = await this.mp.currentPage();
const bookBtn = await page.$('.booking-btn');
if (bookBtn) {
// 检查按钮是否禁用
const disabled = await bookBtn.attribute('disabled');
if (disabled === 'true' || disabled === 'disabled') {
console.log('预约按钮已禁用(课程不可预约)');
return false;
}
await bookBtn.tap();
console.log('点击预约按钮');
return true;
}
console.log('未找到预约按钮');
return false;
}
async containsText(text) {
const page = await this.mp.currentPage();
const wxml = await page.wxml();
return wxml.includes(text);
}
async getPageData() {
const page = await this.mp.currentPage();
return await page.data();
}
}
module.exports = { CourseDetailPage };
+77
View File
@@ -0,0 +1,77 @@
/**
* 首页 Page Object
*/
class HomePage {
constructor(miniProgram) {
this.mp = miniProgram;
}
/**
* 获取当前页面实例
*/
async currentPage() {
return await this.mp.currentPage();
}
/**
* 等待首页加载完成
*/
async waitForReady() {
const page = await this.mp.currentPage();
await page.waitFor(3000);
console.log('首页加载完成');
}
/**
* 获取页面路径
*/
async getPath() {
const page = await this.mp.currentPage();
return page.path;
}
/**
* 点击搜索入口
*/
async clickSearch() {
const page = await this.mp.currentPage();
const searchEl = await page.$('.search-bar, .search-icon, [class*="search"]');
if (searchEl) {
await searchEl.tap();
console.log('点击搜索入口');
}
}
/**
* 点击课程卡片
*/
async clickCourseCard(index = 0) {
const page = await this.mp.currentPage();
const cards = await page.$$('.recommend-card, .course-card, .course-item, [class*="course"]');
if (cards.length > index) {
await cards[index].tap();
console.log(`点击第${index + 1}个课程卡片`);
} else {
console.log(`未找到课程卡片 (寻找 index=${index}, 找到 ${cards.length} 个)`);
}
}
/**
* 检查页面是否包含指定文本
*/
async containsText(text) {
const page = await this.mp.currentPage();
const wxml = await page.wxml();
return wxml.includes(text);
}
/**
* 获取页面数据
*/
async getPageData() {
const page = await this.mp.currentPage();
return await page.data();
}
}
module.exports = { HomePage };
+55
View File
@@ -0,0 +1,55 @@
/**
* 登录页 Page Object
*/
class LoginPage {
constructor(miniProgram) {
this.mp = miniProgram;
}
/**
* 等待登录页渲染
*/
async waitForReady() {
const page = await this.mp.currentPage();
await page.waitFor(2000);
console.log('登录页加载完成');
}
/**
* 点击微信授权登录按钮
*/
async clickWechatLogin() {
const page = await this.mp.currentPage();
const loginBtn = await page.$('.login-btn, button[open-type="getUserInfo"], .wechat-login');
if (loginBtn) {
await loginBtn.tap();
console.log('点击微信授权登录');
}
}
/**
* 获取当前页面路径
*/
async getPath() {
const page = await this.mp.currentPage();
return page.path;
}
/**
* 检查是否在当前页面
*/
async isCurrentPage() {
const path = await this.getPath();
return path.includes('login');
}
/**
* 获取页面数据
*/
async getPageData() {
const page = await this.mp.currentPage();
return await page.data();
}
}
module.exports = { LoginPage };
@@ -0,0 +1,92 @@
/**
* 我的课程页 Page Object
*/
class MyCoursesPage {
constructor(miniProgram) {
this.mp = miniProgram;
}
async waitForReady() {
const page = await this.mp.currentPage();
await page.waitFor(2000);
console.log('我的课程页加载完成');
}
async getPath() {
const page = await this.mp.currentPage();
return page.path;
}
/**
* 点击取消预约按钮
*/
async clickCancelBooking(index = 0) {
const page = await this.mp.currentPage();
const cancelBtns = await page.$$('.cancel-btn');
if (cancelBtns.length > index) {
await cancelBtns[index].tap();
console.log(`取消第${index + 1}个预约`);
}
}
/**
* 扫码签到:mock wx.scanCode 后点击签到按钮
* @param {string} courseName 课程名称(如"流瑜伽"- 用于匹配对应 booking card
*/
async scanSignIn(courseName) {
const page = await this.mp.currentPage();
// 先通过 page data 确认目标课程存在
const pageData = await page.data();
const bookings = pageData.bookings || [];
const targetBooking = bookings.find(b => b.courseName === courseName);
if (!targetBooking) {
console.log(`未在数据中找到「${courseName}」的预约记录`);
return false;
}
const targetIndex = bookings.indexOf(targetBooking);
console.log(`${courseName}」在 bookings[${targetIndex}]`);
// 通过 DOM 元素匹配
const cards = await page.$$('.booking-card');
console.log(`找到 ${cards.length} 个预约卡片`);
if (cards.length > targetIndex) {
const signBtn = await cards[targetIndex].$('.signin-btn');
if (signBtn) {
await signBtn.tap();
console.log(`点击「${courseName}」扫码签到按钮`);
return true;
}
console.log('未找到 signin-btn,尝试 wxml 匹配');
// 回退:通过 wxml 匹配
for (let i = 0; i < cards.length; i++) {
const wxml = await cards[i].wxml();
if (wxml.includes(courseName)) {
const btn = await cards[i].$('.signin-btn');
if (btn) {
await btn.tap();
console.log('点击扫码签到按钮');
return true;
}
}
}
}
console.log(`未找到「${courseName}」的签到按钮`);
return false;
}
async containsText(text) {
const page = await this.mp.currentPage();
const wxml = await page.wxml();
return wxml.includes(text);
}
async getPageData() {
const page = await this.mp.currentPage();
return await page.data();
}
}
module.exports = { MyCoursesPage };
@@ -0,0 +1,36 @@
/**
* 个人中心页 Page Object
*/
class ProfilePage {
constructor(miniProgram) {
this.mp = miniProgram;
}
async waitForReady() {
const page = await this.mp.currentPage();
await page.waitFor(2000);
console.log('个人中心页加载完成');
}
async getPath() {
const page = await this.mp.currentPage();
return page.path;
}
/**
* 获取会员信息
*/
async getMemberInfo() {
const page = await this.mp.currentPage();
const data = await page.data();
return data;
}
async containsText(text) {
const page = await this.mp.currentPage();
const wxml = await page.wxml();
return wxml.includes(text);
}
}
module.exports = { ProfilePage };
+56
View File
@@ -0,0 +1,56 @@
/**
* 搜索页 Page Object
*/
class SearchPage {
constructor(miniProgram) {
this.mp = miniProgram;
}
async waitForReady() {
const page = await this.mp.currentPage();
await page.waitFor(2000);
console.log('搜索页加载完成');
}
async getPath() {
const page = await this.mp.currentPage();
return page.path;
}
/**
* 输入搜索关键词
*/
async search(keyword) {
const page = await this.mp.currentPage();
const searchInput = await page.$('input[type="text"], .search-input, input');
if (searchInput) {
await searchInput.input(keyword);
console.log(`搜索关键词: ${keyword}`);
}
}
async containsText(text) {
const page = await this.mp.currentPage();
const wxml = await page.wxml();
return wxml.includes(text);
}
async getPageData() {
const page = await this.mp.currentPage();
return await page.data();
}
/**
* 点击搜索结果
*/
async clickResult(index = 0) {
const page = await this.mp.currentPage();
const results = await page.$$('.result-item, .course-item, .search-result');
if (results.length > index) {
await results[index].tap();
console.log(`点击第${index + 1}个搜索结果`);
}
}
}
module.exports = { SearchPage };