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 (!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(); }; }