新增e2e测试脚本,修复部分问题

This commit was merged in pull request #51.
This commit is contained in:
2026-07-22 20:00:13 +08:00
parent 53d1ce6fb2
commit 4c07ec5455
105 changed files with 21700 additions and 318 deletions
@@ -0,0 +1,117 @@
/**
* MyCoursesPage - 我的课程页 Page Object
* 对应页面: pages/my-courses/my-courses
*/
class MyCoursesPage {
constructor(miniProgram) {
this.mp = miniProgram;
}
/**
* 等待我的课程页加载完成
*/
async waitForLoad() {
const { waitForPage } = require('../helpers/automator');
return waitForPage(this.mp, 'pages/my-courses/my-courses');
}
/**
* 获取预约列表
* @returns {Promise<Array>} 预约课程列表
*/
async getBookingList() {
const page = await this.mp.currentPage();
try {
const bookingCards = await page.$$('.booking-card');
return bookingCards || [];
} catch (e) {
console.warn('[MyCoursesPage] 获取预约列表异常:', e.message);
return [];
}
}
/**
* 获取预约数量
* @returns {Promise<number>}
*/
async getBookingCount() {
const list = await this.getBookingList();
return list.length;
}
/**
* 取消指定索引的预约
* @param {number} index - 预约索引(从0开始)
* @returns {Promise<boolean>}
*/
async cancelBooking(index = 0) {
const page = await this.mp.currentPage();
console.log(`[MyCoursesPage] 取消第 ${index} 个预约`);
try {
const bookingCards = await page.$$('.booking-card');
if (!bookingCards || !bookingCards[index]) {
console.warn('[MyCoursesPage] 未找到预约卡片');
return false;
}
// 点击取消按钮
const cancelBtn = await bookingCards[index].$('.cancel-btn');
if (cancelBtn) {
await cancelBtn.tap();
await this.mp.waitFor(500);
return true;
}
} catch (e) {
console.warn('[MyCoursesPage] 取消预约异常:', e.message);
}
return false;
}
/**
* 签到
* @param {string|number} courseId - 课程ID
* @returns {Promise<boolean>}
*/
async signIn(courseId) {
const page = await this.mp.currentPage();
console.log(`[MyCoursesPage] 签到课程: ${courseId}`);
try {
const signInBtn = await page.$('.sign-in-btn');
if (signInBtn) {
await signInBtn.tap();
await this.mp.waitFor(1500);
return true;
}
} catch (e) {
console.warn('[MyCoursesPage] 签到操作异常:', e.message);
}
return false;
}
/**
* 下拉刷新列表
*/
async pullDownRefresh() {
const page = await this.mp.currentPage();
try {
await this.mp.callWxMethod('startPullDownRefresh', {});
await this.mp.waitFor(2000);
} catch (e) {
console.warn('[MyCoursesPage] 下拉刷新异常:', e.message);
}
}
/**
* 通过 TabBar 切换到个人中心
*/
async navigateToProfile() {
const { switchTab } = require('../helpers/automator');
await switchTab(this.mp, 3);
}
}
module.exports = MyCoursesPage;