import { Page } from 'playwright'; export class CustomerAnalysisPage { page: Page; subPages: { name: string; url?: string[] }[]; /** * 顾客分析页面 */ constructor(page: Page) { this.page = page; this.subPages = [{ name: '项目余量分析' }, { name: '套餐消耗升单分析' }, { name: '顾客项目分析' }]; } /** * 跳转到子页面 * @param {string} subPageName - 子页面名称,支持以下选项: * - "项目余量分析" * - "套餐消耗升单分析" * - "顾客项目分析" */ gotoSubPage = async (subPageName: string) => { // 输入验证 if (!subPageName || typeof subPageName !== 'string') { throw new Error('Invalid subPageName parameter'); } // 异常处理 if (!this.subPages || !this.subPages.some(({ name }) => name === subPageName)) { throw new Error(`${subPageName} is not a valid sub page name`); } const $dropDown = this.page.locator('.top_tab .tab_item', { hasText: '顾客分析' }).locator('.ant-dropdown-link'); await $dropDown.click(); await this.page.getByRole('menuitem', { name: subPageName }).click(); }; }