新增e2e测试脚本,修复部分问题
This commit was merged in pull request #51.
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* SearchPage - 团课搜索页 Page Object
|
||||
* 对应页面: pages/search/search
|
||||
*/
|
||||
class SearchPage {
|
||||
constructor(miniProgram) {
|
||||
this.mp = miniProgram;
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待搜索页加载完成
|
||||
*/
|
||||
async waitForLoad() {
|
||||
const { waitForPage } = require('../helpers/automator');
|
||||
return waitForPage(this.mp, 'pages/search/search');
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入搜索关键词
|
||||
* @param {string} keyword - 搜索关键词
|
||||
*/
|
||||
async searchCourses(keyword) {
|
||||
const page = await this.mp.currentPage();
|
||||
console.log(`[SearchPage] 搜索课程: "${keyword}"`);
|
||||
|
||||
try {
|
||||
// 查找搜索输入框并输入
|
||||
const searchInput = await page.$('input');
|
||||
if (searchInput) {
|
||||
await searchInput.input(keyword);
|
||||
}
|
||||
|
||||
// 查找搜索按钮并点击
|
||||
const searchBtn = await page.$('.search-btn');
|
||||
if (searchBtn) {
|
||||
await searchBtn.tap();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[SearchPage] 搜索操作异常:', e.message);
|
||||
}
|
||||
|
||||
await this.mp.waitFor(1500);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择日期范围
|
||||
* @param {string} start - 开始日期 YYYY-MM-DD
|
||||
* @param {string} end - 结束日期 YYYY-MM-DD
|
||||
*/
|
||||
async selectDateRange(start, end) {
|
||||
console.log(`[SearchPage] 选择日期范围: ${start} ~ ${end}`);
|
||||
// 日期选择通常由 picker 组件实现,通过触发 change 事件模拟
|
||||
const page = await this.mp.currentPage();
|
||||
try {
|
||||
const pickerElements = await page.$$('picker');
|
||||
if (pickerElements && pickerElements.length >= 2) {
|
||||
// 假设第一个是开始日期,第二个是结束日期
|
||||
await pickerElements[0].tap();
|
||||
await this.mp.waitFor(500);
|
||||
await pickerElements[1].tap();
|
||||
await this.mp.waitFor(500);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[SearchPage] 日期选择异常:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择时间段
|
||||
* @param {string} value - 时间段值(如 'morning', 'afternoon', 'evening')
|
||||
*/
|
||||
async selectPeriod(value) {
|
||||
console.log(`[SearchPage] 选择时间段: ${value}`);
|
||||
const page = await this.mp.currentPage();
|
||||
try {
|
||||
const periodBtn = await page.$(`.period-${value}`);
|
||||
if (periodBtn) {
|
||||
await periodBtn.tap();
|
||||
await this.mp.waitFor(1000);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[SearchPage] 时间段选择异常:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取课程列表
|
||||
* @returns {Promise<Array>} 课程列表
|
||||
*/
|
||||
async getCourseList() {
|
||||
const page = await this.mp.currentPage();
|
||||
try {
|
||||
const courseCards = await page.$$('.course-card');
|
||||
if (!courseCards || courseCards.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return courseCards;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取课程列表中的课程数量
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
async getCourseCount() {
|
||||
const list = await this.getCourseList();
|
||||
return list.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击指定索引的课程卡片
|
||||
* @param {number} index - 课程索引(从0开始)
|
||||
*/
|
||||
async clickCourse(index = 0) {
|
||||
const page = await this.mp.currentPage();
|
||||
console.log(`[SearchPage] 点击第 ${index} 个课程`);
|
||||
|
||||
try {
|
||||
const courseCards = await page.$$('.course-card');
|
||||
if (courseCards && courseCards[index]) {
|
||||
await courseCards[index].tap();
|
||||
await this.mp.waitFor(1500);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[SearchPage] 点击课程异常:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 TabBar 切换到首页
|
||||
*/
|
||||
async navigateToHome() {
|
||||
const { switchTab } = require('../helpers/automator');
|
||||
await switchTab(this.mp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SearchPage;
|
||||
Reference in New Issue
Block a user