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

122 lines
4.0 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 CardBalanceChangeReportPage {
page: Page;
private readonly _reportIndex: reportData[];
/**
* 储值卡卡金变动表
*/
constructor(page: Page) {
this.page = page;
this._reportIndex = [
{
name: '期初',
content: [
{ name: '期初卡金', index: -1 },
{ name: '期初赠金', index: -1 },
],
},
{
name: '消费',
content: [
{ name: '消费卡金', index: -1 },
{ name: '消费赠金', index: -1 },
],
},
{
name: '开充卡',
content: [
{ name: '开充卡金', index: -1 },
{ name: '开充赠金', index: -1 },
],
},
{
name: '调整',
content: [
{ name: '修改卡金', index: -1 },
{ name: '修改赠金', index: -1 },
],
},
{
name: '转移',
content: [
{ name: '转移卡金', index: -1 },
{ name: '转移赠金', index: -1 },
],
},
{
name: '结余',
content: [
{ name: '结余卡金', index: -1 },
{ name: '结余赠金', index: -1 },
],
},
{
name: '变动',
content: [
{ name: '卡金变动', index: -1 },
{ name: '赠金变动', index: -1 },
],
},
];
}
get reportIndex() {
return this._reportIndex;
}
/**
* 更新报表数据索引
*/
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._reportIndex) {
for (const content of category.content!) {
// 第一列是会员卡名称,故+1
content.index =
headers.findIndex(headerText => {
return headerText === content.name;
}) + 1;
}
}
};
/**
* 获取指定卡的报表数据
* @param cardName 卡名称
* @param cardData 卡数据
*/
getSpecifyCardReportData = async (cardName: string, cardData: reportData[]) => {
const tdLocator = this.page
.locator('.table_sub-box .m-table__body-wrapper tr', { hasText: cardName })
.first()
.locator('td');
await tdLocator.first().waitFor();
const headers = await tdLocator.allInnerTexts();
for (const category of this._reportIndex) {
const cardCategoryIndex = cardData.findIndex(card => card.name === category.name);
if (cardCategoryIndex === -1) {
// 为空时初始化一个对象
const obj = {
name: category.name,
content: category.content?.map(item => ({ ...item, value: 0, lastValue: 0 })),
};
cardData.push(obj);
}
const cardCategory = cardData.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!]);
}
}
};
}