supplier_grouping.spec.ts 4.22 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 ({ supplierGroupingPage }, testInfo) => {
    await allure.epic('供应商管理');
    await allure.feature('供应商分组');
    await allure.story('新增供应商分组');

    // 步骤1:生成随机分组信息
    const groupName = `自动${Date.now().toString().slice(-3)}`;
    const remark = '自动化测试';

    // 步骤2:进入供应商分组页面并点击新建
    await allure.step('进入供应商分组页面', async () => {
      await supplierGroupingPage.navigateToSupplierGrouping();
      await supplierGroupingPage.clickAddButton();
    });

    // 步骤3:填写分组信息
    await allure.step('填写分组信息', async () => {
      await supplierGroupingPage.fillGroupName(groupName);
      await supplierGroupingPage.fillRemark(remark);
    });

    // 步骤4:保存分组
    await allure.step('保存分组', async () => {
      await supplierGroupingPage.saveGrouping();
      await supplierGroupingPage.attachScreenshot(testInfo, '新增供应商分组成功截图');
    });

    // 步骤5:验证分组创建成功
    await allure.step('验证分组创建成功', async () => {
      const isCreated = await supplierGroupingPage.verifyGroupingCreated(groupName);
      expect(isCreated).toBeTruthy();
    });
  });

  test('修改供应商分组', async ({ supplierGroupingPage }, testInfo) => {
    await allure.epic('供应商管理');
    await allure.feature('供应商分组');
    await allure.story('修改供应商分组');

    // 步骤1:生成新的分组信息
    const newGroupName = `修改${Date.now().toString().slice(-2)}`;
    const newRemark = '自动化测试修改';

    // 步骤2:进入供应商分组页面
    await allure.step('进入供应商分组页面', async () => {
      await supplierGroupingPage.navigateToSupplierGrouping();
    });

    // 步骤3:点击编辑分组
    await allure.step('点击编辑分组', async () => {
      await supplierGroupingPage.clickEditButton();
    });

    // 步骤4:修改分组信息
    await allure.step('修改分组信息', async () => {
      await supplierGroupingPage.updateGrouping(newGroupName, newRemark);
      await supplierGroupingPage.attachScreenshot(testInfo, '修改供应商分组成功截图');
    });

    // 步骤5:验证分组修改成功
    await allure.step('验证分组修改成功', async () => {
      const isUpdated = await supplierGroupingPage.verifyGroupingUpdated(newGroupName);
      expect(isUpdated).toBeTruthy();
    });
  });

  test('删除供应商分组', async ({ supplierGroupingPage }, testInfo) => {
    await allure.epic('供应商管理');
    await allure.feature('供应商分组');
    await allure.story('删除供应商分组');

    // 步骤1:生成待删除的分组名称
    const groupName = `删除${Date.now().toString().slice(-2)}`;

    // 步骤2:先创建一个分组用于删除
    await allure.step('创建待删除的分组', async () => {
      await supplierGroupingPage.navigateToSupplierGrouping();
      await supplierGroupingPage.clickAddButton();
      await supplierGroupingPage.fillGroupName(groupName);
      await supplierGroupingPage.fillRemark('自动化测试');
      await supplierGroupingPage.saveGrouping();
    });

    // 步骤3:删除分组
    await allure.step('删除分组', async () => {
      await supplierGroupingPage.navigateToSupplierGrouping();
      await supplierGroupingPage.clickGroupingItem(groupName);
      await supplierGroupingPage.clickDeleteButton();
      await supplierGroupingPage.confirmDelete();
      await supplierGroupingPage.attachScreenshot(testInfo, '删除供应商分组成功截图');
    });

    // 步骤4:验证分组删除成功
    await allure.step('验证分组删除成功', async () => {
      const isDeleted = await supplierGroupingPage.verifyGroupingDeleted(groupName);
      expect(isDeleted).toBeTruthy();
    });
  });
});