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

237 lines
12 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 { faker } from '@faker-js/faker/locale/zh_CN';
import { test, expect } from '@/fixtures/staff_common.js';
import { getListIndexForTargetElement } from '@/utils/utils.js';
test.describe('调货管理', () => {
test('门店要货', async ({ page, homeNavigation }) => {
// 使用产品
const goods = {
a: { no: 'aa100007', name: '肌因能量套', unitPrice: 10, quantity: 5 },
b: { no: 'aa100008', name: '肌因赋活尊享套', unitPrice: 15, quantity: 8 },
};
// 备注
const remark = '调货管理-门店要货' + faker.helpers.fromRegExp(/[0-9]{3}/);
let quantity = 0; // 数量
let unitPrice = 0; // 单价
let subtotal = 0; // 小计
let totalQuantity = 0; // 总数量
let totalPrice = 0; // 总价
await test.step('门店保存要货单', async () => {
await homeNavigation.gotoModule('库存');
await page.locator('.top_tab').getByText('调货管理').click();
// 展示单价和小计
await page.locator('.price_set').click();
await page.locator('.set_btn').getByRole('checkbox').check();
await page.getByRole('button', { name: /确\s认/ }).click();
// 选择产品a设置产品数量和单价
await page.locator('.panel tr', { hasText: goods.a.no }).click();
const goodsATr = page.locator('.bill_report tr', { hasText: goods.a.name });
await goodsATr.getByRole('spinbutton').first().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.a.quantity));
await page.locator('.number_tr button').nth(11).click();
await goodsATr.getByRole('spinbutton').last().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.a.unitPrice));
await page.locator('.number_tr button').nth(11).click();
// 选择产品b设置产品数量和单价
await page.locator('.panel tr', { hasText: goods.b.no }).click();
const goodsBTr = page.locator('.bill_report tr', { hasText: goods.b.name });
await goodsBTr.getByRole('spinbutton').first().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.b.quantity));
await page.locator('.number_tr button').nth(11).click();
await goodsBTr.getByRole('spinbutton').last().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.b.unitPrice));
await page.locator('.number_tr button').nth(11).click();
// 设置备注
await page.getByText('备注').click();
await page.getByPlaceholder('请输入1-100个字符备注内容').fill(remark);
await page.getByRole('button', { name: /确\s认/ }).click();
// 保存要货单
await page.getByRole('button', { name: /保\s存/ }).click();
await expect(page.getByRole('cell', { name: '门店要货备注' })).toBeInViewport();
});
await test.step('查看保存的要货单', async () => {
// 查看明细单据
const tableTrList = page.locator('.table_inner .main-table-body_tr');
const targetTr = tableTrList.filter({ hasText: remark }).filter({ hasText: '未提交' });
const targetIndex = await getListIndexForTargetElement(targetTr, tableTrList);
const fixedCell = page
.locator('.m-table-fixed-body')
.getByRole('cell', { name: '明细编辑删除' })
.nth(targetIndex);
await fixedCell.getByText('明细').click();
// 拿取商品a的数据
const goodsATr = page.locator('.popup_content tr', { hasText: goods.a.name });
quantity = Number(await goodsATr.locator('td').nth(2).innerText());
unitPrice = Number(await goodsATr.locator('td').nth(6).innerText());
subtotal = Number(await goodsATr.locator('td').nth(7).innerText());
totalPrice += unitPrice * quantity;
totalQuantity += quantity;
// 判断商品a的数据
expect.soft(quantity).toBe(goods.a.quantity);
expect.soft(unitPrice).toBe(goods.a.unitPrice);
expect(subtotal).toBe(goods.a.quantity * goods.a.unitPrice);
// 拿取商品b的数据
const goodsBTr = page.locator('.popup_content tr', { hasText: goods.b.name });
quantity = Number(await goodsBTr.locator('td').nth(2).innerText());
unitPrice = Number(await goodsBTr.locator('td').nth(6).innerText());
subtotal = Number(await goodsBTr.locator('td').nth(7).innerText());
totalPrice += unitPrice * quantity;
totalQuantity += quantity;
// 判断商品b的数据
expect.soft(quantity).toBe(goods.b.quantity);
expect.soft(unitPrice).toBe(goods.b.unitPrice);
expect.soft(subtotal).toBe(goods.b.quantity * goods.b.unitPrice);
// 判断合计数量、合计金额
expect.soft(totalPrice).toBe(goods.b.quantity * goods.b.unitPrice + goods.a.quantity * goods.a.unitPrice);
expect(totalQuantity).toBe(goods.a.quantity + goods.b.quantity);
// 关闭弹窗
await page.locator('.title > .close_icon > svg').click();
});
await test.step('门店提交要货单', async () => {
// 查看明细单据
let tableTrList = page.locator('.table_inner .main-table-body_tr');
let targetTr = tableTrList.filter({ hasText: remark }).filter({ hasText: '未提交' });
let targetIndex = await getListIndexForTargetElement(targetTr, tableTrList);
let fixedCell = page
.locator('.m-table-fixed-body')
.getByRole('cell', { name: '明细编辑删除' })
.nth(targetIndex);
await fixedCell.getByText('编辑').click();
await expect(page.getByText('要货单').nth(1)).toBeInViewport();
// 选择产品a设置产品数量和单价
await page.locator('.panel tr', { hasText: goods.a.no }).click();
let goodsTr = page.locator('.bill_report tr', { hasText: goods.a.name });
await goodsTr.getByRole('spinbutton').first().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.a.quantity * 2));
await page.locator('.number_tr button').nth(11).click();
await goodsTr.getByRole('spinbutton').last().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.a.unitPrice * 2));
await page.locator('.number_tr button').nth(11).click();
// 选择产品b设置产品数量和单价
await page.locator('.panel tr', { hasText: goods.b.no }).click();
goodsTr = page.locator('.bill_report tr', { hasText: goods.b.name });
await goodsTr.getByRole('spinbutton').first().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.b.quantity * 2));
await page.locator('.number_tr button').nth(11).click();
await goodsTr.getByRole('spinbutton').last().click();
await page.getByPlaceholder('请输入内容').fill(String(goods.b.unitPrice * 2));
await page.locator('.number_tr button').nth(11).click();
// 保存要货单
await page.getByRole('button', { name: /提\s交/ }).click();
await expect(page.getByRole('cell', { name: '门店要货备注' })).toBeInViewport();
});
await test.step('查看提交的要货单', async () => {
// 查看明细单据
const tableTrList = page.locator('.table_inner .main-table-body_tr');
const targetTr = tableTrList.filter({ hasText: remark }).filter({ hasText: '已提交' });
const targetIndex = await getListIndexForTargetElement(targetTr, tableTrList);
const fixedCell = page.locator('.m-table-fixed-body').getByRole('cell', { name: '明细' }).nth(targetIndex);
await fixedCell.getByText('明细').click();
totalQuantity = 0;
totalPrice = 0;
// 拿取商品a的数据
let goodsTr = page.locator('.popup_content tr', { hasText: goods.a.name });
quantity = Number(await goodsTr.locator('td').nth(2).innerText());
unitPrice = Number(await goodsTr.locator('td').nth(6).innerText());
subtotal = Number(await goodsTr.locator('td').nth(7).innerText());
totalPrice += unitPrice * quantity;
totalQuantity += quantity;
// 判断商品a的数据
expect.soft(quantity).toBe(goods.a.quantity * 2);
expect.soft(unitPrice).toBe(goods.a.unitPrice * 2);
expect.soft(subtotal).toBe(goods.a.quantity * goods.a.unitPrice * 4);
// 拿取商品b的数据
goodsTr = page.locator('.popup_content tr', { hasText: goods.b.name });
quantity = Number(await goodsTr.locator('td').nth(2).innerText());
unitPrice = Number(await goodsTr.locator('td').nth(6).innerText());
subtotal = Number(await goodsTr.locator('td').nth(7).innerText());
totalPrice += unitPrice * quantity;
totalQuantity += quantity;
// 判断商品b的数据
expect.soft(quantity).toBe(goods.b.quantity * 2);
expect.soft(unitPrice).toBe(goods.b.unitPrice * 2);
expect.soft(subtotal).toBe(goods.b.quantity * goods.b.unitPrice * 4);
// 判断合计数量、合计金额
expect
.soft(totalPrice)
.toBe((goods.b.quantity * goods.b.unitPrice + goods.a.quantity * goods.a.unitPrice) * 4);
expect(totalQuantity).toBe((goods.a.quantity + goods.b.quantity) * 2);
});
});
test('要货单', async ({ firstStaffPage, staffHomeNavigation, transferManagementPage }) => {
const goods = { no: 'aa100024', name: '茉莉精油', quantity: 10 };
const remark = '门店要货单' + faker.string.numeric(3);
await test.step('添加要货单', async () => {
await staffHomeNavigation.gotoModule('库存');
await firstStaffPage.locator('.top_tab .tab_item').getByText('调货管理').click();
await transferManagementPage.gotoSubPage('门店要货');
await firstStaffPage
.getByRole('row', { name: goods.no })
.and(firstStaffPage.getByRole('row', { name: goods.name }))
.click();
const goodsTr = firstStaffPage.locator('.bill_report tr', { hasText: goods.name });
await goodsTr.getByRole('spinbutton').first().click();
await firstStaffPage.getByPlaceholder('请输入内容').fill(String(goods.quantity));
await firstStaffPage.locator('.number_tr button').nth(11).click();
// 设置备注
await firstStaffPage.getByText('备注').click();
await firstStaffPage.getByPlaceholder('请输入1-100个字符备注内容').fill(remark);
await firstStaffPage.getByRole('button', { name: /确\s认/ }).click();
// 保存要货单
await firstStaffPage.getByRole('button', { name: /保\s存/ }).click();
// 跳转到要货单
await expect(firstStaffPage.getByRole('cell', { name: '门店要货备注' })).toBeVisible();
const billGoodsTr = firstStaffPage.locator('.m-table__body-wrapper tr', {
hasText: remark,
});
await expect(billGoodsTr).toBeVisible();
});
await test.step('删除要货单', async () => {
const tableTrList = firstStaffPage.locator('.table_inner .main-table-body_tr');
const targetTr = tableTrList.filter({ hasText: remark });
const targetIndex = await getListIndexForTargetElement(targetTr, tableTrList);
const fixedCell = firstStaffPage
.locator('.m-table-fixed-body')
.getByRole('cell', { name: '明细编辑删除' })
.nth(targetIndex);
await fixedCell.getByText('删除').click();
await firstStaffPage.getByRole('button', { name: /确\s认/ }).click();
const billGoodsTr = firstStaffPage.locator('.m-table__body-wrapper tr', {
hasText: remark,
});
await expect(billGoodsTr).not.toBeInViewport();
});
});
});