57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
/**
|
|
* 搜索页 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 };
|