新增e2e测试脚本,修复部分问题
This commit was merged in pull request #51.
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* ProfilePage - 个人中心页 Page Object
|
||||
* 对应页面: pages/profile/profile
|
||||
*/
|
||||
class ProfilePage {
|
||||
constructor(miniProgram) {
|
||||
this.mp = miniProgram;
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待个人中心页加载完成
|
||||
*/
|
||||
async waitForLoad() {
|
||||
const { waitForPage } = require('../helpers/automator');
|
||||
return waitForPage(this.mp, 'pages/profile/profile');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员名称
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async getMemberName() {
|
||||
const page = await this.mp.currentPage();
|
||||
try {
|
||||
const nameEl = await page.$('.member-name');
|
||||
if (nameEl) {
|
||||
return await nameEl.text();
|
||||
}
|
||||
|
||||
// 尝试其他可能的选择器
|
||||
const nickEl = await page.$('.nickname');
|
||||
if (nickEl) {
|
||||
return await nickEl.text();
|
||||
}
|
||||
|
||||
const userEl = await page.$('.user-name');
|
||||
if (userEl) {
|
||||
return await userEl.text();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[ProfilePage] 获取会员名称异常:', e.message);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人中心所有信息
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async getProfileInfo() {
|
||||
const page = await this.mp.currentPage();
|
||||
const info = {
|
||||
name: '',
|
||||
phone: '',
|
||||
email: ''
|
||||
};
|
||||
|
||||
try {
|
||||
info.name = await this.getMemberName();
|
||||
|
||||
const phoneEl = await page.$('.member-phone');
|
||||
if (phoneEl) {
|
||||
info.phone = await phoneEl.text();
|
||||
}
|
||||
|
||||
const emailEl = await page.$('.member-email');
|
||||
if (emailEl) {
|
||||
info.email = await emailEl.text();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[ProfilePage] 获取个人信息异常:', e.message);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到我的课程页
|
||||
*/
|
||||
async navigateToMyCourses() {
|
||||
const { switchTab } = require('../helpers/automator');
|
||||
await switchTab(this.mp, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到首页
|
||||
*/
|
||||
async navigateToHome() {
|
||||
const { switchTab } = require('../helpers/automator');
|
||||
await switchTab(this.mp, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单项列表
|
||||
* @returns {Promise<Array>}
|
||||
*/
|
||||
async getMenuItems() {
|
||||
const page = await this.mp.currentPage();
|
||||
try {
|
||||
const menuItems = await page.$$('.menu-item');
|
||||
return menuItems || [];
|
||||
} catch (e) {
|
||||
console.warn('[ProfilePage] 获取菜单项异常:', e.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉刷新
|
||||
*/
|
||||
async pullDownRefresh() {
|
||||
const page = await this.mp.currentPage();
|
||||
try {
|
||||
await this.mp.callWxMethod('startPullDownRefresh', {});
|
||||
await this.mp.waitFor(2000);
|
||||
} catch (e) {
|
||||
console.warn('[ProfilePage] 下拉刷新异常:', e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ProfilePage;
|
||||
Reference in New Issue
Block a user