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

130 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { type Page } from '@playwright/test';
import { reportData } from './reportPage';
export class ItemSalesConsumptionAccessReportPage {
page: Page;
private readonly _reportDataIndex: reportData[];
/**
* 项目销耗存表
*/
constructor(page: Page) {
this.page = page;
this._reportDataIndex = [
{
name: '期初',
content: [
{ name: '期初金额', value: 0, lastValue: 0, index: -1 },
{ name: '期初数量', value: 0, lastValue: 0, index: -1 },
{ name: '期初赠送数量', value: 0, lastValue: 0, index: -1 },
],
},
{
name: '销售',
content: [
{ name: '销售金额', value: 0, lastValue: 0, index: -1 },
{ name: '销售数量', value: 0, lastValue: 0, index: -1 },
{ name: '赠送数量', value: 0, lastValue: 0, index: -1 },
{ name: '购买人数', value: 0, lastValue: 0, index: -1 },
{ name: '项目复购率', value: 0, lastValue: 0, index: -1 },
{ name: '项目销售占比', value: 0, lastValue: 0, index: -1 },
],
},
{
name: '消耗',
content: [
{ name: '消耗金额', value: 0, lastValue: 0, index: -1 },
{ name: '消耗数量', value: 0, lastValue: 0, index: -1 },
{ name: '消耗赠送数量', value: 0, lastValue: 0, index: -1 },
{ name: '消耗人数', value: 0, lastValue: 0, index: -1 },
{ name: '项目消耗占比', value: 0, lastValue: 0, index: -1 },
],
},
{
name: '调整',
content: [
{ name: '调整金额', value: 0, lastValue: 0, index: -1 },
{ name: '换出数量', value: 0, lastValue: 0, index: -1 },
{ name: '换入数量', value: 0, lastValue: 0, index: -1 },
{ name: '更改数量', value: 0, lastValue: 0, index: -1 },
{ name: '期初导入数量', value: 0, lastValue: 0, index: -1 },
],
},
{
name: '转移',
content: [
{ name: '转入金额', value: 0, lastValue: 0, index: -1 },
{ name: '转入成本', value: 0, lastValue: 0, index: -1 },
{ name: '转入数量', value: 0, lastValue: 0, index: -1 },
{ name: '转出金额', value: 0, lastValue: 0, index: -1 },
{ name: '转出成本', value: 0, lastValue: 0, index: -1 },
{ name: '转出数量', value: 0, lastValue: 0, index: -1 },
],
},
{
name: '结余',
content: [
{ name: '结余金额', value: 0, lastValue: 0, index: -1 },
{ name: '结余数量', value: 0, lastValue: 0, index: -1 },
{ name: '结余赠送数量', value: 0, lastValue: 0, index: -1 },
{ name: '过期结余金额', value: 0, lastValue: 0, index: -1 },
{ name: '过期结余数量', value: 0, lastValue: 0, index: -1 },
{ name: '过期结余赠送数量', value: 0, lastValue: 0, index: -1 },
],
},
];
}
/**
* 更新报表数据索引
*/
updateReportDataIndex = async () => {
const thLocator = this.page.locator('.m-table__header-wrapper tr').last().locator('th');
await thLocator.first().waitFor();
const headers = await thLocator.allInnerTexts();
for (const category of this._reportDataIndex) {
for (const content of category.content!) {
// 第一列是会员卡名称,故+1
content.index =
headers.findIndex(headerText => {
return headerText === content.name;
}) + 1;
}
}
};
/**
* 获取项目销售消耗报表数据
* @param itemName 项目名称
* @param itemData 项目数据
*/
getSpecifyItemReportData = async (itemName: string, itemData: reportData[]) => {
const tdLocator = this.page
.locator('.table_sub-box .m-table__body-wrapper tr', { hasText: itemName })
.first()
.locator('td');
await tdLocator.first().waitFor();
const headers = await tdLocator.allInnerTexts();
for (const category of this._reportDataIndex) {
const cardCategoryIndex = itemData.findIndex(card => card.name === category.name);
if (cardCategoryIndex === -1) {
// 为空时初始化一个对象
const obj = {
name: category.name,
content: category.content?.map(item => ({ ...item, value: 0, lastValue: 0 })),
};
itemData.push(obj);
}
const cardCategory = itemData.find(card => card.name === category.name);
if (!cardCategory || !cardCategory.content) {
throw new Error(`cardCategory${JSON.stringify(cardCategory)}`);
}
for (const content of cardCategory.content) {
content.lastValue = content.value;
content.value = Number(headers[content.index!] === '--' ? 0 : headers[content.index!]);
}
}
};
}