This repository has been archived on 2025-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
hlk_autotest/tests/pages/homeNavigationPage.ts
LingandRX 6517e4192c feat: 初始化慧来客自动化测试项目
- 添加项目配置文件和环境变量设置
- 创建测试用例目录结构和命名规范
- 实现基础测试 fixture 和页面对象模型
- 添加示例测试用例和数据生成器
- 配置 playwright 和 gitignore 文件
2024-12-22 19:18:27 +08:00

64 lines
1.7 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
export class HomeNavigation {
page: Page;
$$moduleList: Locator;
subPages: { name: string; url?: string[] }[];
/**
* @param {Page} page
*/
constructor(page: Page) {
this.page = page;
this.$$moduleList = this.page.locator('.left_box .link_item');
this.subPages = [
{ name: '收银' },
{ name: '预约' },
{ name: '顾客' },
{ name: '流水' },
{ name: '库存' },
{ name: '目标' },
{ name: '营销' },
{ name: '报表' },
{ name: '设置' },
{ name: '其他' },
];
}
/**
* 跳转到对应模块
* @param {string} pageName 模块名称
* - 收银
* - 预约
* - 顾客
* - 流水
* - 库存
* - 目标
* - 营销
* - 报表
* - 设置
* - 其他
*/
gotoModule = async (pageName: string) => {
const $active = this.$$moduleList.locator('.active_arrow');
if (!this.subPages.some(item => item.name === pageName)) {
throw new Error(`Page ${pageName} does not exist`);
}
// 模块定位器
const $module = this.$$moduleList.filter({ hasText: pageName });
// 模块选中按钮
const $moduleActive = $module.locator('.active_arrow');
// 等待选中按钮出现
await $active.waitFor();
await expect(async () => {
if (!(await $moduleActive.isVisible())) {
await $module.click();
}
await $moduleActive.waitFor({ timeout: 5000 });
}).toPass({ timeout: 10_000 });
};
}