78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
/**
|
|
* 首页 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 };
|