customer.spec.ts 4.88 KB
import { test, expect } from '../fixtures';
import { generateCustomerName, generateIdCard, generatePhoneNumber, generateDetailedAddress, generateCustomerInfo, getRandomImage } from '../utils/dataGenerator';
import * as allure from 'allure-js-commons';

/**
 * 客户管理测试
 */
test.describe('客户管理', () => {
  // 使用已保存的认证状态
  test.use({ storageState: 'auth.json' });

  test('新增客户', async ({ customerPage }, testInfo) => {
    // 添加allure元素
    await allure.epic('客户管理');
    await allure.feature('客户信息');
    await allure.story('创建新客户');

    // 步骤1:生成随机客户信息
    const customerInfo = await allure.step('生成随机客户信息', async (step) => {
      const name = generateCustomerName();
      const phone = generatePhoneNumber();
      const idCard = generateIdCard();
      const detailedAddress = generateDetailedAddress();
      
      
      console.log('生成的客户信息:', { name, phone, idCard, detailedAddress });
      
      return { name, phone, idCard, detailedAddress };
    });

    // 步骤2:执行新增客户操作
    await allure.step('填写并提交客户表单', async () => {
      await customerPage.gotoHome();
      
      // 从 test-data/img 目录随机选择一张图片
      const randomImage = getRandomImage();
      
      await customerPage.createCustomer(
        {
          name: customerInfo.name,
          phone: customerInfo.phone,
          idCard: customerInfo.idCard,
          detailedAddress: customerInfo.detailedAddress,
        },
        {
          creditLimit: '500',
          licensePlate: '渝ZY0706',
          province: '江苏省',
          city: '连云港市',
          district: '海州区',
          imagePath: randomImage || undefined, // 如果有图片则上传
        }
      );
      await customerPage.attachScreenshot(testInfo, '新增客户成功截图');
    });

    // 步骤3:验证客户创建成功
    await allure.step('验证客户创建成功', async () => {
      const isCreated = await customerPage.verifyCustomerCreated(customerInfo.name);
      expect(isCreated).toBeTruthy();
    });
  });

//   test('新增客户 - 仅必填信息', async ({ customerPage }, testInfo) => {
//     // 添加allure元素
//     await allure.epic('客户管理');
//     await allure.feature('客户信息');
//     await allure.story('创建新客户(仅必填信息)');

//     // 步骤1:生成随机客户信息
//     const customerInfo = await allure.step('生成随机客户信息', async (step) => {
//       const info = generateCustomerInfo();
//       console.log('生成的客户信息:', info);
//       return info;
//     });

//     // 步骤2:执行新增客户操作
//     await allure.step('填写并提交客户表单(仅必填信息)', async () => {
//       await customerPage.gotoHome();
//       await customerPage.createCustomer({
//         name: customerInfo.name,
//         phone: customerInfo.phone,
//         idCard: customerInfo.idCard,
//       });
//       await customerPage.attachScreenshot(testInfo, '新增客户成功截图');
//     });

//     // 步骤3:验证客户创建成功
//     await allure.step('验证客户创建成功', async () => {
//       const isCreated = await customerPage.verifyCustomerCreated(customerInfo.name);
//       expect(isCreated).toBeTruthy();
//     });
//   });

//   test('新增客户 - 带详细地址', async ({ customerPage }, testInfo) => {
//     // 添加allure元素
//     await allure.epic('客户管理');
//     await allure.feature('客户信息');
//     await allure.story('创建新客户(带详细地址)');

//     // 步骤1:生成随机客户信息
//     const customerInfo = await allure.step('生成随机客户信息', async (step) => {
//       const name = generateCustomerName();
//       const phone = generatePhoneNumber();
//       const idCard = generateIdCard();
//       const detailedAddress = generateDetailedAddress();
      
//       console.log('生成的客户信息:', { name, phone, idCard, detailedAddress });
      
//       return { name, phone, idCard, detailedAddress };
//     });

//     // 步骤2:执行新增客户操作
//     await allure.step('填写并提交客户表单', async () => {
//       await customerPage.gotoHome();
//       await customerPage.createCustomer(
//         {
//           name: customerInfo.name,
//           phone: customerInfo.phone,
//           idCard: customerInfo.idCard,
//         },
//         {
//           creditLimit: '10000',
//         }
//       );
//       await customerPage.attachScreenshot(testInfo, '新增客户成功截图');
//     });

//     // 步骤3:验证客户创建成功
//     await allure.step('验证客户创建成功', async () => {
//       const isCreated = await customerPage.verifyCustomerCreated(customerInfo.name);
//       expect(isCreated).toBeTruthy();
//     });
//   });
});