supplier_bill.spec.ts 2.9 KB
import { test, expect } from '../fixtures';
import * as allure from 'allure-js-commons';

/**
 * 供应商管理测试 - 录入欠款
 */
test.describe('供应商管理-录入欠款', () => {
  // 使用已保存的认证状态
  test.use({ storageState: 'auth.json' });
  
  // 强制测试串行执行
  test.describe.configure({ mode: 'serial' });

  test('录入欠款并验证应付金额增加', async ({ supplierPage }, testInfo) => {
    // 添加allure元素
    await allure.epic('供应商管理');
    await allure.feature('供应商信息');
    await allure.story('录入欠款');

    // 录入的欠款金额
    const debtAmount = '100';
    const remark = '测试录入欠款';

    // 步骤1:进入供应商管理页面并选择第2个供应商,记录原始应付金额和供应商名称
    let supplierName = '';
    const originalAmount = await allure.step('记录原始应付金额', async () => {
      await supplierPage.navigateToSupplierManagement();
      await supplierPage.clickSupplierItemByIndex(1);
      await supplierPage.page.waitForLoadState('networkidle');
      await supplierPage.page.waitForTimeout(300);
      return await supplierPage.parsePayableAmount();
    });
    console.log('录入前应付金额:', originalAmount);

    // 步骤2:点击录入欠款
    await allure.step('点击录入欠款', async () => {
      await supplierPage.clickRecordDebt();
    });

    // 步骤3:选择欠款方向(我方欠供应商)
    await allure.step('选择欠款方向', async () => {
      await supplierPage.selectDebtDirection('oweSupplier');
    });

    // 步骤4:选择赊欠日期(今日)
    await allure.step('选择赊欠日期', async () => {
      await supplierPage.selectDebtDate();
    });

    // 步骤5:填写赊欠金额
    await allure.step('填写赊欠金额', async () => {
      await supplierPage.fillDebtAmount(debtAmount);
    });

    // 步骤6:填写备注
    await allure.step('填写备注', async () => {
      await supplierPage.fillRemark(remark);
    });

    // 步骤7:保存欠款记录
    await allure.step('保存欠款记录', async () => {
      await supplierPage.saveDebt();
    });

    // 步骤8:验证欠款录入成功 - 搜索同一供应商查看应付金额
    const currentAmount = await allure.step('验证欠款录入成功', async () => {
      await supplierPage.navigateToSupplierManagement();
      await supplierPage.clickSupplierItemByIndex(1);
      await supplierPage.page.waitForLoadState('networkidle');
      await supplierPage.page.waitForTimeout(300);
      const amount = await supplierPage.parsePayableAmount();
      console.log('录入后应付金额:', amount);
      return amount;
    });
    
    // 验证应付金额增加了录入的金额
    expect(currentAmount).toBeCloseTo(originalAmount + parseFloat(debtAmount), 1);
    
    await supplierPage.attachScreenshot(testInfo, '录入欠款成功截图');
  });
});