supplier_update.spec.ts 2.77 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('编辑供应商');

    // 步骤1:生成新的供应商信息
    const supplierInfo = await allure.step('生成新的供应商信息', async () => {
      // 随机生成供应商名称前缀
      const namePrefixes = ['修改', '更新', '调整', '变更'];
      const namePrefix = namePrefixes[Math.floor(Math.random() * namePrefixes.length)];
      
      const info = await supplierPage.generateRandomSupplierInfo({
        namePrefix: namePrefix,
      });
      
      console.log('新供应商名称:', info.name);
      console.log('新负责人:', info.managerName);
      console.log('新手机号:', info.phone);
      console.log('新备注:', info.remark);
      
      return info;
    });

    // 步骤2:填写并提交供应商表单
    await allure.step('填写并提交供应商表单', async () => {
      // 进入供应商管理页面
      await supplierPage.navigateToSupplierManagement();
      
      // 选择供应商列表项(点击第一个)
      await supplierPage.clickSupplierItemByIndex(0);
      
      // 点击编辑按钮
      await supplierPage.clickEditButton();
      
      // 修改供应商名称
      await supplierPage.clearAndFillFormField(supplierPage.supplierNameInput, supplierInfo.name);
      
      // 修改负责人名称
      await supplierPage.clearAndFillFormField(supplierPage.managerNameInput, supplierInfo.managerName);
      
      // 修改手机号
      await supplierPage.clearAndFillFormField(supplierPage.phoneInput, supplierInfo.phone);
      
      // 选择供应商类型(必选字段)
      await supplierPage.selectSupplierType();
      
      // 绑定园区卡
      await supplierPage.selectParkCard('888800010617');
      
      // 修改备注
      await supplierPage.clearAndFillFormField(supplierPage.remarkInput, supplierInfo.remark || '');
      
      // 保存
      await supplierPage.clickConfirmButton();
      
      await supplierPage.attachScreenshot(testInfo, '编辑供应商成功截图');
    });

    // 步骤3:验证供应商修改成功
    await allure.step('验证供应商修改成功', async () => {
      const isUpdated = await supplierPage.verifySupplierCreated(supplierInfo.name);
      expect(isUpdated).toBeTruthy();
    });
  });
});