Commit 14eb0ef29f348328832039c9987d2e4be11f0825

Authored by 赵旭婷
1 parent e892e9ad

新增采购单复制创建、采购单编辑保存

pages/purchasePage.ts
... ... @@ -124,6 +124,16 @@ export class PurchasePage extends BasePage {
124 124 // 存储温度
125 125 readonly storageTemperatureInput: Locator;
126 126  
  127 + // 编辑修改
  128 + readonly editButton: Locator;
  129 +
  130 + // 入账日期
  131 + readonly entryDateField: Locator;
  132 +
  133 + // 批次别名
  134 + readonly batchAliasInput: Locator;
  135 + readonly batchAliasClearIcon: Locator;
  136 +
127 137 constructor(page: Page) {
128 138 super(page);
129 139  
... ... @@ -188,6 +198,16 @@ export class PurchasePage extends BasePage {
188 198  
189 199 // 存储温度
190 200 this.storageTemperatureInput = page.locator('uni-view:nth-child(9) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__value > .nut-input__input > .uni-input-wrapper > .uni-input-input');
  201 +
  202 + // 编辑修改
  203 + this.editButton = page.getByText('修改', { exact: true });
  204 +
  205 + // 入账日期
  206 + this.entryDateField = page.locator('uni-view:nth-child(7) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__value > .nut-input__mask');
  207 +
  208 + // 批次别名
  209 + this.batchAliasInput = page.locator('uni-view:nth-child(8) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__value > .nut-input__input > .uni-input-wrapper > .uni-input-input');
  210 + this.batchAliasClearIcon = page.locator('uni-view:nth-child(8) > .nut-cell__value > .nut-form-item__body__slots > .nut-input > .nut-input__clear > .nut-input__clear-icon');
191 211 }
192 212  
193 213 /**
... ... @@ -636,6 +656,31 @@ export class PurchasePage extends BasePage {
636 656 }
637 657  
638 658 /**
  659 + * 选择入账日期:打开日历 → 翻到上一月 → 选择15号
  660 + */
  661 + async selectEntryDate(): Promise<void> {
  662 + await this.entryDateField.click();
  663 + await this.page.waitForTimeout(500);
  664 + await this.page.locator('.uni-calendar__header-btn').first().click();
  665 + await this.page.waitForTimeout(300);
  666 + await this.page.locator('uni-view').filter({ hasText: /^15$/ }).nth(2).click();
  667 + await this.page.waitForTimeout(300);
  668 + }
  669 +
  670 + /**
  671 + * 清除并输入批次别名
  672 + * @param alias 批次别名
  673 + */
  674 + async clearAndEnterBatchAlias(alias: string): Promise<void> {
  675 + await this.batchAliasInput.click();
  676 + await this.page.waitForTimeout(300);
  677 + await this.batchAliasClearIcon.click();
  678 + await this.page.waitForTimeout(300);
  679 + await this.batchAliasInput.click();
  680 + await this.batchAliasInput.fill(alias);
  681 + }
  682 +
  683 + /**
639 684 * 清除采购列表搜索框内容
640 685 */
641 686 async clearSearchInPurchaseList(): Promise<void> {
... ... @@ -645,6 +690,15 @@ export class PurchasePage extends BasePage {
645 690 }
646 691  
647 692 /**
  693 + * 点击采购列表的修改按钮进入编辑页
  694 + */
  695 + async clickEditButton(): Promise<void> {
  696 + await this.editButton.click();
  697 + await this.page.waitForLoadState('networkidle', { timeout: 30000 });
  698 + await this.page.waitForTimeout(1000);
  699 + }
  700 +
  701 + /**
648 702 * 验证采购列表中存在商品
649 703 * @param productName 商品名称
650 704 */
... ...
tests/purchase.spec.ts
... ... @@ -535,4 +535,139 @@ test.describe(&#39;采购入库&#39;, () =&gt; {
535 535 await purchasePage.expectPurchaseOrderStatusPaid();
536 536 });
537 537 });
  538 +
  539 + test('采购单编辑保存', async ({ page }, testInfo) => {
  540 + test.setTimeout(60000);
  541 + const purchasePage = new PurchasePage(page);
  542 +
  543 + // 添加allure元素
  544 + await allure.epic('仓储管理');
  545 + await allure.feature('采购入库');
  546 + await allure.story('采购单编辑保存');
  547 +
  548 + // 测试数据
  549 + let supplierName: string;
  550 + let warehouseName: string;
  551 + let productName: string;
  552 + let newSupplierName: string;
  553 + let newWarehouseName: string;
  554 +
  555 + // 步骤1:进入采购入库页面
  556 + await allure.step('进入采购入库页面', async () => {
  557 + await purchasePage.openPurchaseInbound();
  558 + });
  559 +
  560 + // 步骤2:随机选择商品
  561 + await allure.step('随机选择商品', async () => {
  562 + productName = await purchasePage.selectRandomProduct();
  563 + console.log('商品:', productName);
  564 + });
  565 +
  566 + // 步骤3:输入数量
  567 + await allure.step('输入数量', async () => {
  568 + await purchasePage.enterQuantity('1');
  569 + });
  570 +
  571 + // 步骤4:输入单价
  572 + await allure.step('输入单价', async () => {
  573 + await purchasePage.enterPrice('1');
  574 + });
  575 +
  576 + // 步骤5:点击完成
  577 + await allure.step('点击完成', async () => {
  578 + await purchasePage.clickDone();
  579 + });
  580 +
  581 + // 步骤6:随机选择供应商
  582 + await allure.step('随机选择供应商', async () => {
  583 + supplierName = await purchasePage.getRandomSupplier();
  584 + console.log('供应商:', supplierName);
  585 + });
  586 +
  587 + // 步骤7:随机选择仓库
  588 + await allure.step('随机选择仓库', async () => {
  589 + warehouseName = await purchasePage.getRandomWarehouse();
  590 + console.log('仓库:', warehouseName);
  591 + });
  592 +
  593 + // 步骤8:点击保存
  594 + await allure.step('点击保存', async () => {
  595 + await purchasePage.clickSave();
  596 + });
  597 +
  598 + // 步骤9:搜索商品
  599 + await allure.step('搜索商品', async () => {
  600 + await purchasePage.searchInPurchaseList(productName);
  601 + });
  602 +
  603 + // 步骤10:点击修改按钮进入编辑页
  604 + await allure.step('点击修改按钮', async () => {
  605 + await purchasePage.clickEditButton();
  606 + });
  607 +
  608 + // 步骤11:连续添加两个商品
  609 + await allure.step('添加第一个商品', async () => {
  610 + const name = await purchasePage.selectRandomProduct();
  611 + console.log('添加商品1:', name);
  612 + await purchasePage.enterQuantity('1');
  613 + await purchasePage.enterPrice('1');
  614 + await purchasePage.clickDone();
  615 + });
  616 +
  617 + await allure.step('添加第二个商品', async () => {
  618 + const name = await purchasePage.selectRandomProduct();
  619 + console.log('添加商品2:', name);
  620 + await purchasePage.enterQuantity('1');
  621 + await purchasePage.enterPrice('1');
  622 + await purchasePage.clickDone();
  623 + });
  624 +
  625 + // 步骤12:填写货款优惠
  626 + await allure.step('填写货款优惠', async () => {
  627 + await purchasePage.clickSubtotal();
  628 + await purchasePage.enterSubtotalAmount('1');
  629 + });
  630 +
  631 + // 步骤13:添加入库费用
  632 + await allure.step('添加入库费用', async () => {
  633 + await purchasePage.addExpense(0, '1');
  634 + });
  635 +
  636 + // 步骤14:换选供应商
  637 + await allure.step('换选供应商', async () => {
  638 + newSupplierName = await purchasePage.getRandomSupplier();
  639 + console.log('新供应商:', newSupplierName);
  640 + });
  641 +
  642 + // 步骤15:换选仓库
  643 + await allure.step('换选仓库', async () => {
  644 + newWarehouseName = await purchasePage.getRandomWarehouse();
  645 + console.log('新仓库:', newWarehouseName);
  646 + });
  647 +
  648 + // 步骤16:选择入账日期
  649 + await allure.step('选择入账日期', async () => {
  650 + await purchasePage.selectEntryDate();
  651 + });
  652 +
  653 + // 步骤17:清除并输入批次别名
  654 + await allure.step('输入批次别名', async () => {
  655 + await purchasePage.clearAndEnterBatchAlias('批次003');
  656 + });
  657 +
  658 + // 步骤18:点击保存
  659 + await allure.step('点击保存', async () => {
  660 + await purchasePage.clickSave();
  661 + });
  662 +
  663 + // 步骤19:按供应商搜索
  664 + await allure.step('按供应商搜索', async () => {
  665 + await purchasePage.searchInPurchaseList(newSupplierName);
  666 + });
  667 +
  668 + // 步骤20:验证采购列表中存在该商品
  669 + await allure.step('验证采购列表中存在该商品', async () => {
  670 + await purchasePage.expectPurchaseListContainsProduct(productName);
  671 + });
  672 + });
538 673 });
539 674 \ No newline at end of file
... ...