account.spec.ts 4.13 KB
// import { test, expect } from '@playwright/test';
// import * as allure from 'allure-js-commons';

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

//   // 强制测试串行执行
//   test.describe.configure({ mode: 'serial' });

//   /**
//    * 生成随机账目名称(三个字+"费",带时间戳后缀防止重复)
//    */
//   function generateAccountName(): string {
//     const prefixes = ['管理', '维护', '看管', '保管', '仓储', '代理', '服务', '咨询', '技术', '运营'];
//     const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
//     const timestamp = Date.now().toString().slice(-4);
//     return `${prefix}费${timestamp}`;
//   }

//   /**
//    * 生成随机收支类型
//    */
//   function generateIncomeType(): '收入' | '支出' {
//     return Math.random() > 0.5 ? '收入' : '支出';
//   }

//   /**
//    * 生成包含"自动化"的备注
//    */
//   function generateRemark(): string {
//     const timestamp = Date.now().toString().slice(-6);
//     return `自动化测试备注${timestamp}`;
//   }

//   test('新增账目', async ({ page }, testInfo) => {
//     // 添加allure元素
//     await allure.epic('账目管理');
//     await allure.feature('账目信息');
//     await allure.story('新增账目');

//     // 生成随机账目数据
//     const accountName = generateAccountName();
//     const incomeType = generateIncomeType();
//     const remark = generateRemark();
    
//     console.log('账目名称:', accountName);
//     console.log('收支类型:', incomeType);
//     console.log('备注:', remark);

//     // 步骤1:进入账目管理页面
//     await allure.step('进入账目管理页面', async () => {
//       await page.goto('/');
//       await page.waitForLoadState('networkidle', { timeout: 30000 });
//       await page.getByText('更多 >').click();
//       await page.waitForTimeout(500);
//       await page.getByText('账目管理').first().click();
//       await page.waitForLoadState('networkidle', { timeout: 30000 });
//     });

//     // 步骤2:点击新增按钮
//     await allure.step('点击新增按钮', async () => {
//       await page.getByText('新增', { exact: true }).click();
//       await page.waitForTimeout(500);
//     });

//     // 步骤3:填写账目表单
//     await allure.step('填写账目表单', async () => {
//       // 填写账目名称
//       await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').click();
//       await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').fill(accountName);
      
//       // 选择收支类型
//       if (incomeType === '支出') {
//         await page.locator('.nut-radio-group > uni-view:nth-child(2) > .nut-icon').click();
//       }
//       // 收入是默认选项,无需选择
      
//       // 填写备注
//       await page.locator('uni-scroll-view').filter({ hasText: '账目名称*科目名称收支类别 收入 支出 启用状态备注请输入' }).locator('textarea').click();
//       await page.locator('uni-scroll-view').filter({ hasText: '账目名称*科目名称收支类别 收入 支出 启用状态备注请输入' }).locator('textarea').fill(remark);
//     });

//     // 步骤4:保存账目
//     await allure.step('保存账目', async () => {
//       await page.getByText('保存').click();
//       await page.waitForTimeout(1000);
//     });

//     // 步骤5:验证账目创建成功
//     await allure.step('验证账目创建成功', async () => {
//       await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').click();
//       await page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').fill(accountName);
//       await page.waitForTimeout(1000);
      
//       // 验证账目名称出现在列表中
//       const accountVisible = await page.locator(`uni-view:has-text("${accountName}")`).isVisible().catch(() => false);
//       expect(accountVisible).toBeTruthy();
//     });
//   });
// });