新增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,158 @@
const { sleep } = require('../helpers/automator');
class ProfilePage {
/**
* @param {object} miniProgram - miniprogram-automator 实例
*/
constructor(miniProgram) {
this.mp = miniProgram;
}
/**
* 等待个人中心页加载完成
*/
async waitForLoad() {
const page = await this.mp.currentPage();
await page.waitFor('.profile-page', { timeout: 10000 });
await sleep(1500); // 等待异步数据加载
return page;
}
/**
* 获取教练基本信息
* @returns {Promise<{username: string, coachId: string}>}
*/
async getCoachInfo() {
const page = await this.mp.currentPage();
const info = {};
try {
const nameEl = await page.$('.user-name');
info.username = nameEl ? (await nameEl.text()).trim() : '';
const idEl = await page.$('.detail-value');
info.coachId = idEl ? (await idEl.text()).trim() : '';
} catch (e) {
// 忽略
}
return info;
}
/**
* 获取违规记录
* @returns {Promise<Array<{courseName: string, type: string, time: string}>>}
*/
async getViolationRecords() {
const page = await this.mp.currentPage();
const records = [];
try {
// 先检查是否有违规记录
const statNumber = await page.$('.stats-card .stat-number');
if (statNumber) {
const countText = (await statNumber.text()).trim();
const count = parseInt(countText, 10);
if (count > 0) {
const cards = await page.$$('.violation-card');
for (const card of cards) {
try {
const courseEl = await card.$('.violation-course');
const tagEl = await card.$('.violation-tag text');
const timeEl = await card.$('.violation-time');
records.push({
courseName: courseEl ? (await courseEl.text()).trim() : '',
type: tagEl ? (await tagEl.text()).trim() : '',
time: timeEl ? (await timeEl.text()).trim() : ''
});
} catch (e) {
// 跳过无法解析的记录
}
}
}
}
} catch (e) {
// 忽略
}
return records;
}
/**
* 获取违规次数统计
*/
async getViolationCount() {
const page = await this.mp.currentPage();
try {
const statNumber = await page.$('.stats-card .stat-number');
if (statNumber) {
const text = (await statNumber.text()).trim();
return parseInt(text, 10);
}
} catch (e) {
// 忽略
}
return 0;
}
/**
* 获取业绩数据
* @returns {Promise<{totalLessons: string, attendanceRate: string, compositeScore: string}>}
*/
async getPerformance() {
const page = await this.mp.currentPage();
const perf = {};
try {
const perfNumbers = await page.$$('.perf-number');
if (perfNumbers.length >= 4) {
perf.totalLessons = (await perfNumbers[0].text()).trim();
// perfNumbers[1] = totalAttendees
perf.attendanceRate = (await perfNumbers[2].text()).trim();
perf.fullnessRate = (await perfNumbers[3].text()).trim();
}
const scoreEl = await page.$('.score-badge');
perf.compositeScore = scoreEl ? (await scoreEl.text()).trim() : '';
} catch (e) {
// 忽略
}
return perf;
}
/**
* 点击退出登录
*/
async logout() {
const page = await this.mp.currentPage();
const logoutBtn = await page.$('.logout-btn');
if (logoutBtn) {
await logoutBtn.tap();
await sleep(1000);
// 确认弹窗需要额外处理
// MiniTest 中弹窗按钮难以直接操作,这里只触发点击
}
}
/**
* 返回上一页
*/
async goBack() {
const page = await this.mp.currentPage();
try {
const backBtn = await page.$('.back-btn');
if (backBtn) {
await backBtn.tap();
await sleep(1000);
}
} catch (e) {
// 备用:使用系统返回
await this.mp.navigateBack();
}
}
}
module.exports = ProfilePage;