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/report/performanceDetailReport.ts
LingandRX 6517e4192c feat: 初始化慧来客自动化测试项目
- 添加项目配置文件和环境变量设置
- 创建测试用例目录结构和命名规范
- 实现基础测试 fixture 和页面对象模型
- 添加示例测试用例和数据生成器
- 配置 playwright 和 gitignore 文件
2024-12-22 19:18:27 +08:00

86 lines
3.2 KiB
TypeScript

import { type Locator, type Page } from '@playwright/test';
import { type reportData } from './reportPage';
export class PerformanceDetailReportPage {
page: Page;
private readonly _reportData: reportData[];
private subTables: { name: string; locator: Locator }[];
/**
* 业绩明细表
*/
constructor(page: Page) {
this.page = page;
this._reportData = [
{
name: '项目销售',
content: [
{ name: '数量', value: 0, lastValue: 0, index: -1 },
{ name: '金额', value: 0, lastValue: 0, index: -1 },
{ name: '现金业绩', value: 0, lastValue: 0, index: -1 },
],
},
];
this.subTables = [
{ name: '项目销售', locator: this.page.locator('.SERVICE_SALE_table') },
{ name: '项目消耗', locator: this.page.locator('.SERVICE_table') },
{ name: '项目套餐包销售', locator: this.page.locator('.PACKAGE_table') },
{ name: '项目卖品销售', locator: this.page.locator('.GOODS_table') },
{ name: '卡销售', locator: this.page.locator('.CARD_table') },
];
}
get reportData(): reportData[] {
return this._reportData;
}
/**
* 更新各个表格的索引
*/
updateReportDataIndex = async () => {
for (const subReportData of this._reportData) {
const subTable = this.subTables.find(subTable => subTable.name === subReportData.name);
if (!subTable || !subTable.locator) {
throw new Error(`${subTable}`);
}
const currentTableLocator = subTable.locator;
await currentTableLocator.waitFor();
const allHeader = await currentTableLocator
.locator('.m-table__header-wrapper tr')
.nth(1)
.locator('th')
.allInnerTexts();
for (const content of subReportData.content!) {
content.index = allHeader.findIndex(headerText => {
return headerText === content.name;
});
}
}
};
/**
* 获取子表的合计
*/
updateReportDataForTableTotal = async () => {
for (const subReportData of this._reportData) {
const subTable = this.subTables.find(subTable => subTable.name === subReportData.name);
if (!subTable || !subTable.locator) {
throw new Error(`${subTable}`);
}
const currentTableLocator = subTable.locator;
await currentTableLocator.waitFor();
const allFooterText = await currentTableLocator
.locator('.table_sub-box .m-table-footer td')
.allInnerTexts();
for (const content of subReportData.content!) {
// 第一个是合计,故+1
const currentIndex = content.index! + 1;
content.lastValue = content.value;
content.value = Number(
allFooterText[currentIndex].trim() === '--' ? 0 : allFooterText[currentIndex].trim(),
);
}
}
};
}