Commit 0d108388a95505c5929c6a98451810d90348bd4a

Authored by 赵旭婷
1 parent 0247a9d4

新增账目管理测试用例,客户分组PO封装

pages/accountPage.ts 0 → 100644
  1 +import { Page, Locator, expect } from '@playwright/test';
  2 +import { BasePage } from './basePage';
  3 +
  4 +/**
  5 + * 账目管理页面选择器
  6 + */
  7 +const selectors = {
  8 + // 导航
  9 + moreMenu: 'text=更多 >',
  10 + accountMenu: 'text=账目管理',
  11 +
  12 + // 操作按钮
  13 + addButton: 'text=新增',
  14 + saveButton: 'text=保存',
  15 +
  16 + // 表单字段
  17 + accountNameInput: 'uni-input:has-text("科目名称") input',
  18 + remarkTextarea: 'uni-scroll-view textarea',
  19 +
  20 + // 收支类型单选
  21 + incomeRadio: '.nut-radio-group > uni-view:nth-child(1) > .nut-icon',
  22 + expenseRadio: '.nut-radio-group > uni-view:nth-child(2) > .nut-icon',
  23 +};
  24 +
  25 +/**
  26 + * 账目管理页面类
  27 + * 处理账目管理相关操作
  28 + */
  29 +export class AccountPage extends BasePage {
  30 + // 导航定位器
  31 + readonly moreMenu: Locator;
  32 + readonly accountMenu: Locator;
  33 +
  34 + // 操作按钮
  35 + readonly addButton: Locator;
  36 + readonly saveButton: Locator;
  37 + readonly editButton: Locator;
  38 +
  39 + // 表单字段
  40 + readonly accountNameInput: Locator;
  41 + readonly remarkTextarea: Locator;
  42 +
  43 + // 收支类型
  44 + readonly incomeRadio: Locator;
  45 + readonly expenseRadio: Locator;
  46 +
  47 + constructor(page: Page) {
  48 + super(page);
  49 +
  50 + this.moreMenu = page.getByText('更多 >');
  51 + this.accountMenu = page.getByText('账目管理').first();
  52 + this.addButton = page.getByText('新增', { exact: true });
  53 + this.saveButton = page.locator('uni-button.execute-btn').filter({ hasText: '保存' });
  54 + this.editButton = page.locator('uni-button').filter({ hasText: '修改' });
  55 + this.accountNameInput = page.locator('uni-input').filter({ hasText: '科目名称' }).getByRole('textbox');
  56 + this.remarkTextarea = page.locator('uni-scroll-view textarea');
  57 + this.incomeRadio = page.locator('.nut-radio-group > uni-view:nth-child(1) > .nut-icon');
  58 + this.expenseRadio = page.locator('.nut-radio-group > uni-view:nth-child(2) > .nut-icon');
  59 + }
  60 +
  61 + /**
  62 + * 进入账目管理页面
  63 + */
  64 + async openAccountManagement(): Promise<void> {
  65 + await this.navigate('/');
  66 + await this.moreMenu.click();
  67 + await this.page.waitForTimeout(500);
  68 + await this.accountMenu.click();
  69 + await this.page.waitForLoadState('networkidle', { timeout: 30000 });
  70 + }
  71 +
  72 + /**
  73 + * 点击新增按钮
  74 + */
  75 + async clickAddButton(): Promise<void> {
  76 + await this.addButton.click();
  77 + await this.page.waitForTimeout(500);
  78 + }
  79 +
  80 + /**
  81 + * 填写账目名称
  82 + * @param name 账目名称
  83 + */
  84 + async fillAccountName(name: string): Promise<void> {
  85 + await this.accountNameInput.click();
  86 + await this.accountNameInput.fill(name);
  87 + }
  88 +
  89 + /**
  90 + * 选择收支类型
  91 + * @param type '收入' 或 '支出'
  92 + */
  93 + async selectIncomeType(type: '收入' | '支出'): Promise<void> {
  94 + if (type === '支出') {
  95 + await this.expenseRadio.click();
  96 + }
  97 + // 收入是默认选项,无需选择
  98 + }
  99 +
  100 + /**
  101 + * 填写备注
  102 + * @param remark 备注内容
  103 + */
  104 + async fillRemark(remark: string): Promise<void> {
  105 + await this.remarkTextarea.click();
  106 + await this.remarkTextarea.fill(remark);
  107 + }
  108 +
  109 + /**
  110 + * 保存账目
  111 + */
  112 + async saveAccount(): Promise<void> {
  113 + await this.saveButton.click();
  114 + await this.page.waitForTimeout(1000);
  115 + }
  116 +
  117 + /**
  118 + * 搜索账目
  119 + * @param name 账目名称
  120 + */
  121 + async searchAccount(name: string): Promise<void> {
  122 + await this.page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').click();
  123 + await this.page.locator('uni-input').filter({ hasText: '账目名称' }).getByRole('textbox').fill(name);
  124 + await this.page.waitForTimeout(1000);
  125 + }
  126 +
  127 + /**
  128 + * 验证账目是否存在
  129 + * @param name 账目名称
  130 + * @returns 是否存在
  131 + */
  132 + async verifyAccountExists(name: string): Promise<boolean> {
  133 + const isVisible = await this.page.getByText(name, { exact: true }).isVisible().catch(() => false);
  134 + return isVisible;
  135 + }
  136 +
  137 + /**
  138 + * 删除账目
  139 + * @param name 账目名称
  140 + */
  141 + async deleteAccount(name: string): Promise<void> {
  142 + // 搜索账目
  143 + await this.searchAccount(name);
  144 + await this.page.waitForTimeout(500);
  145 + // 点击删除按钮
  146 + await this.page.getByText('删除').click();
  147 + await this.page.waitForTimeout(500);
  148 + // 确认删除
  149 + await this.page.getByText('确定').click();
  150 + await this.page.waitForTimeout(1000);
  151 + }
  152 +
  153 + /**
  154 + * 验证账目删除成功
  155 + * @param name 账目名称
  156 + * @returns 是否删除成功
  157 + */
  158 + async verifyAccountDeleted(name: string): Promise<boolean> {
  159 + await this.searchAccount(name);
  160 + await this.page.waitForTimeout(500);
  161 + const isVisible = await this.page.getByText(name, { exact: true }).isVisible().catch(() => false);
  162 + return !isVisible;
  163 + }
  164 +
  165 + /**
  166 + * 点击修改按钮
  167 + */
  168 + async clickEditButton(): Promise<void> {
  169 + await this.editButton.click();
  170 + await this.page.waitForTimeout(500);
  171 + }
  172 +
  173 + /**
  174 + * 修改账目完整流程
  175 + * @param originalName 原账目名称
  176 + * @param newName 新账目名称
  177 + * @param incomeType 收支类型(收入/支出)
  178 + * @param remark 备注
  179 + */
  180 + async updateAccount(originalName: string, newName: string, incomeType?: '收入' | '支出', remark?: string): Promise<void> {
  181 + // 搜索原账目
  182 + await this.searchAccount(originalName);
  183 + await this.page.waitForTimeout(500);
  184 + // 点击修改按钮
  185 + await this.clickEditButton();
  186 + // 修改账目名称
  187 + await this.accountNameInput.click();
  188 + await this.accountNameInput.fill(newName);
  189 + // 修改收支类型
  190 + if (incomeType === '支出') {
  191 + await this.expenseRadio.click();
  192 + }
  193 + // 修改备注
  194 + if (remark) {
  195 + await this.remarkTextarea.click();
  196 + await this.remarkTextarea.fill(remark);
  197 + }
  198 + // 保存
  199 + await this.saveAccount();
  200 + }
  201 +
  202 + /**
  203 + * 清除搜索框
  204 + */
  205 + async clearSearchBox(): Promise<void> {
  206 + await this.page.locator('.nut-icon.nutui-iconfont.nut-icon-circle-close').click();
  207 + await this.page.waitForTimeout(500);
  208 + }
  209 +
  210 + /**
  211 + * 新增账目完整流程
  212 + * @param accountName 账目名称
  213 + * @param incomeType 收支类型(默认'收入')
  214 + * @param remark 备注
  215 + */
  216 + async createAccount(accountName: string, incomeType: '收入' | '支出' = '收入', remark?: string): Promise<void> {
  217 + await this.openAccountManagement();
  218 + await this.clickAddButton();
  219 + await this.fillAccountName(accountName);
  220 + await this.selectIncomeType(incomeType);
  221 + if (remark) {
  222 + await this.fillRemark(remark);
  223 + }
  224 + await this.saveAccount();
  225 + }
  226 +
  227 + /**
  228 + * 验证账目创建成功
  229 + * @param accountName 账目名称
  230 + * @returns 是否创建成功
  231 + */
  232 + async verifyAccountCreated(accountName: string): Promise<boolean> {
  233 + await this.searchAccount(accountName);
  234 + return await this.verifyAccountExists(accountName);
  235 + }
  236 +}
... ...
pages/customerGroupPage.ts 0 → 100644
  1 +import { Page, Locator, expect } from '@playwright/test';
  2 +import { BasePage } from './basePage';
  3 +
  4 +/**
  5 + * 客户分组页面选择器
  6 + */
  7 +const selectors = {
  8 + // 导航
  9 + moreMenu: 'text=更多 >',
  10 + customerGroupMenu: 'text=客户分组',
  11 +
  12 + // 操作按钮
  13 + newButton: 'text=新建',
  14 + confirmButton: 'text=确定',
  15 + saveButton: 'text=保存',
  16 + deleteButton: 'text=删除',
  17 + editButton: 'text=编辑',
  18 +
  19 + // 表单字段
  20 + groupNameInput: 'text=分组名称*',
  21 + sortInput: 'textbox',
  22 +
  23 + // 搜索
  24 + searchInput: 'textbox',
  25 + clearSearchButton: '.nut-searchbar__search-icon',
  26 +};
  27 +
  28 +/**
  29 + * 客户分组页面类
  30 + * 处理客户分组相关操作
  31 + */
  32 +export class CustomerGroupPage extends BasePage {
  33 + // 导航定位器
  34 + readonly moreMenu: Locator;
  35 + readonly customerGroupMenu: Locator;
  36 +
  37 + // 操作按钮
  38 + readonly newButton: Locator;
  39 + readonly confirmButton: Locator;
  40 + readonly saveButton: Locator;
  41 + readonly deleteButton: Locator;
  42 + readonly editButton: Locator;
  43 +
  44 + // 表单字段
  45 + readonly groupNameInput: Locator;
  46 + readonly sortInput: Locator;
  47 +
  48 + // 搜索
  49 + readonly searchInput: Locator;
  50 + readonly clearSearchButton: Locator;
  51 +
  52 + constructor(page: Page) {
  53 + super(page);
  54 +
  55 + this.moreMenu = page.getByText('更多 >');
  56 + this.customerGroupMenu = page.getByText('客户分组').first();
  57 + this.newButton = page.getByText('新建');
  58 + this.confirmButton = page.getByText('确定');
  59 + this.saveButton = page.getByText('保存');
  60 + this.deleteButton = page.getByText('删除');
  61 + this.editButton = page.getByText('编辑');
  62 + this.groupNameInput = page.locator('uni-view').filter({ hasText: /^分组名称\*$/ }).first();
  63 + this.sortInput = page.getByRole('textbox').nth(2);
  64 + this.searchInput = page.getByRole('textbox');
  65 + this.clearSearchButton = page.locator('.nut-searchbar__search-icon');
  66 + }
  67 +
  68 + /**
  69 + * 进入客户分组页面
  70 + */
  71 + async openCustomerGroupManagement(): Promise<void> {
  72 + await this.navigate('/');
  73 + await this.moreMenu.click();
  74 + await this.page.waitForTimeout(500);
  75 + await this.customerGroupMenu.click();
  76 + await this.page.waitForLoadState('networkidle', { timeout: 30000 });
  77 + }
  78 +
  79 + /**
  80 + * 点击新建按钮
  81 + */
  82 + async clickNewButton(): Promise<void> {
  83 + await this.newButton.click();
  84 + await this.page.waitForTimeout(500);
  85 + }
  86 +
  87 + /**
  88 + * 填写分组名称
  89 + * @param name 分组名称
  90 + */
  91 + async fillGroupName(name: string): Promise<void> {
  92 + await this.page.getByRole('textbox').nth(1).click();
  93 + await this.page.getByRole('textbox').nth(1).fill(name);
  94 + }
  95 +
  96 + /**
  97 + * 填写排序号
  98 + * @param sort 排序号
  99 + */
  100 + async fillSortNumber(sort: string): Promise<void> {
  101 + await this.page.getByRole('textbox').nth(2).click();
  102 + await this.page.getByRole('textbox').nth(2).fill(sort);
  103 + }
  104 +
  105 + /**
  106 + * 点击确定按钮
  107 + */
  108 + async clickConfirm(): Promise<void> {
  109 + await this.confirmButton.click();
  110 + await this.page.waitForTimeout(1000);
  111 + }
  112 +
  113 + /**
  114 + * 搜索分组
  115 + * @param name 分组名称
  116 + */
  117 + async searchGroup(name: string): Promise<void> {
  118 + await this.searchInput.click();
  119 + await this.searchInput.fill(name);
  120 + await this.page.waitForTimeout(500);
  121 + }
  122 +
  123 + /**
  124 + * 点击清除搜索按钮
  125 + */
  126 + async clearSearch(): Promise<void> {
  127 + await this.clearSearchButton.click();
  128 + await this.page.waitForTimeout(2000);
  129 + }
  130 +
  131 + /**
  132 + * 点击编辑按钮
  133 + */
  134 + async clickEdit(): Promise<void> {
  135 + await this.editButton.click();
  136 + await this.page.waitForTimeout(500);
  137 + }
  138 +
  139 + /**
  140 + * 点击删除按钮
  141 + */
  142 + async clickDelete(): Promise<void> {
  143 + await this.deleteButton.click();
  144 + await this.page.waitForTimeout(500);
  145 + }
  146 +
  147 + /**
  148 + * 验证分组是否存在(验证前先搜索)
  149 + * @param name 分组名称
  150 + * @returns 是否存在
  151 + */
  152 + async verifyGroupExists(name: string): Promise<boolean> {
  153 + await this.searchGroup(name);
  154 + await this.page.waitForTimeout(500);
  155 + const count = await this.page.locator('uni-view').filter({ hasText: new RegExp(`^${name}$`) }).count();
  156 + return count > 0;
  157 + }
  158 +
  159 + /**
  160 + * 验证分组是否不存在
  161 + * @param name 分组名称
  162 + * @returns 是否不存在
  163 + */
  164 + async verifyGroupNotExists(name: string): Promise<boolean> {
  165 + const count = await this.page.locator('uni-view').filter({ hasText: new RegExp(`^${name}$`) }).count();
  166 + return count === 0;
  167 + }
  168 +
  169 + /**
  170 + * 新增客户分组完整流程
  171 + * @param groupName 分组名称
  172 + * @param sortNumber 排序号(可选)
  173 + */
  174 + async createGroup(groupName: string, sortNumber?: string): Promise<void> {
  175 + await this.openCustomerGroupManagement();
  176 + await this.clickNewButton();
  177 + await this.fillGroupName(groupName);
  178 + if (sortNumber) {
  179 + await this.fillSortNumber(sortNumber);
  180 + }
  181 + await this.clickConfirm();
  182 + }
  183 +
  184 + /**
  185 + * 修改客户分组完整流程
  186 + * @param originalName 原分组名称
  187 + * @param newName 新分组名称
  188 + * @param newSortNumber 新排序号(可选)
  189 + */
  190 + async updateGroup(originalName: string, newName: string, newSortNumber?: string): Promise<void> {
  191 + await this.searchGroup(originalName);
  192 + await this.page.locator('uni-view').filter({ hasText: new RegExp(`^${originalName}$`) }).first().click();
  193 + await this.page.waitForTimeout(500);
  194 + await this.clickEdit();
  195 + // 清空分组名称并填写新名称
  196 + await this.page.getByRole('textbox').nth(1).click();
  197 + await this.page.locator('.nut-input__clear-icon').first().click();
  198 + await this.page.getByRole('textbox').nth(1).click();
  199 + await this.page.getByRole('textbox').nth(1).fill(newName);
  200 + if (newSortNumber) {
  201 + await this.page.getByRole('textbox').nth(2).click();
  202 + await this.page.getByRole('textbox').nth(2).fill(newSortNumber);
  203 + }
  204 + await this.clickConfirm();
  205 + }
  206 +
  207 + /**
  208 + * 删除客户分组完整流程
  209 + * @param groupName 分组名称
  210 + */
  211 + async deleteGroup(groupName: string): Promise<void> {
  212 + await this.searchGroup(groupName);
  213 + await this.page.locator('uni-view').filter({ hasText: new RegExp(`^${groupName}$`) }).first().click();
  214 + await this.page.waitForTimeout(500);
  215 + await this.clickDelete();
  216 + await this.page.getByText('确定', { exact: true }).click();
  217 + await this.page.waitForTimeout(1000);
  218 + await this.clearSearch();
  219 + }
  220 +}
... ...
scripts/save-auth.ts
... ... @@ -7,7 +7,7 @@ dotenv.config({ path: path.resolve(__dirname, &#39;../.env&#39;) });
7 7  
8 8 const TEST_PHONE = process.env.phone;
9 9 const TEST_USER_NAME = process.env.TEST_USER_NAME;
10   -const BASE_URL = process.env.BASE_URL || 'https://erp-pad.test.gszdtop.com';
  10 +const BASE_URL = process.env.BASE_URL ;
11 11  
12 12 if (!TEST_PHONE || !TEST_USER_NAME) {
13 13 throw new Error('phone 和 TEST_USER_NAME 环境变量未设置');
... ...
tests/account.spec.ts 0 → 100644
  1 +import { test, expect } from '@playwright/test';
  2 +import * as allure from 'allure-js-commons';
  3 +import { AccountPage } from '../pages/accountPage';
  4 +
  5 +/**
  6 + * 账目管理测试
  7 + */
  8 +test.describe('账目管理', () => {
  9 + // 使用已保存的认证状态
  10 + test.use({ storageState: 'auth.json' });
  11 +
  12 + // 强制测试串行执行
  13 + test.describe.configure({ mode: 'serial' });
  14 +
  15 + /**
  16 + * 生成随机账目名称(三个字+"费",带时间戳后缀防止重复)
  17 + */
  18 + function generateAccountName(): string {
  19 + const prefixes = ['管理', '维护', '看管', '保管', '仓储', '代理', '服务', '咨询', '技术', '运营'];
  20 + const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
  21 + const timestamp = Date.now().toString().slice(-4);
  22 + return `${prefix}费${timestamp}`;
  23 + }
  24 +
  25 + /**
  26 + * 生成随机收支类型
  27 + */
  28 + function generateIncomeType(): '收入' | '支出' {
  29 + return Math.random() > 0.5 ? '收入' : '支出';
  30 + }
  31 +
  32 + /**
  33 + * 生成包含"自动化"的备注
  34 + */
  35 + function generateRemark(): string {
  36 + const timestamp = Date.now().toString().slice(-6);
  37 + return `自动化测试备注${timestamp}`;
  38 + }
  39 +
  40 + test('新增账目', async ({ page }, testInfo) => {
  41 + const accountPage = new AccountPage(page);
  42 +
  43 + // 添加allure元素
  44 + await allure.epic('账目管理');
  45 + await allure.feature('账目信息');
  46 + await allure.story('新增账目');
  47 +
  48 + // 生成随机账目数据
  49 + const accountName = generateAccountName();
  50 + const incomeType = generateIncomeType();
  51 + const remark = generateRemark();
  52 +
  53 + console.log('账目名称:', accountName);
  54 + console.log('收支类型:', incomeType);
  55 + console.log('备注:', remark);
  56 +
  57 + // 步骤1:进入账目管理页面
  58 + await allure.step('进入账目管理页面', async () => {
  59 + await accountPage.openAccountManagement();
  60 + });
  61 +
  62 + // 步骤2:点击新增按钮
  63 + await allure.step('点击新增按钮', async () => {
  64 + await accountPage.clickAddButton();
  65 + });
  66 +
  67 + // 步骤3:填写账目表单
  68 + await allure.step('填写账目表单', async () => {
  69 + await accountPage.fillAccountName(accountName);
  70 + await accountPage.selectIncomeType(incomeType);
  71 + await accountPage.fillRemark(remark);
  72 + });
  73 +
  74 + // 步骤4:保存账目
  75 + await allure.step('保存账目', async () => {
  76 + await accountPage.saveAccount();
  77 + });
  78 +
  79 + // 步骤5:验证账目创建成功
  80 + await allure.step('验证账目创建成功', async () => {
  81 + await accountPage.searchAccount(accountName);
  82 + const isCreated = await accountPage.verifyAccountExists(accountName);
  83 + expect(isCreated).toBeTruthy();
  84 + });
  85 + });
  86 +
  87 + test('删除账目', async ({ page }, testInfo) => {
  88 + const accountPage = new AccountPage(page);
  89 +
  90 + // 添加allure元素
  91 + await allure.epic('账目管理');
  92 + await allure.feature('账目信息');
  93 + await allure.story('删除账目');
  94 +
  95 + // 生成随机账目数据
  96 + const accountName = generateAccountName();
  97 + console.log('待删除账目名称:', accountName);
  98 +
  99 + // 步骤1:新增账目
  100 + await allure.step('新增账目', async () => {
  101 + await accountPage.openAccountManagement();
  102 + await accountPage.clickAddButton();
  103 + await accountPage.fillAccountName(accountName);
  104 + await accountPage.saveAccount();
  105 + });
  106 +
  107 + // 步骤2:删除账目
  108 + await allure.step('删除账目', async () => {
  109 + await accountPage.deleteAccount(accountName);
  110 + });
  111 +
  112 + // 步骤3:验证账目删除成功
  113 + await allure.step('验证账目删除成功', async () => {
  114 + const isDeleted = await accountPage.verifyAccountDeleted(accountName);
  115 + expect(isDeleted).toBeTruthy();
  116 + });
  117 + });
  118 +
  119 + test('修改账目', async ({ page }, testInfo) => {
  120 + const accountPage = new AccountPage(page);
  121 +
  122 + // 添加allure元素
  123 + await allure.epic('账目管理');
  124 + await allure.feature('账目信息');
  125 + await allure.story('修改账目');
  126 +
  127 + // 生成随机账目数据
  128 + const originalName = generateAccountName();
  129 + const newName = generateAccountName();
  130 + const incomeType = generateIncomeType();
  131 + const remark = generateRemark();
  132 +
  133 + console.log('原账目名称:', originalName);
  134 + console.log('新账目名称:', newName);
  135 + console.log('收支类型:', incomeType);
  136 + console.log('备注:', remark);
  137 +
  138 + // 步骤1:新增账目
  139 + await allure.step('新增账目', async () => {
  140 + await accountPage.openAccountManagement();
  141 + await accountPage.clickAddButton();
  142 + await accountPage.fillAccountName(originalName);
  143 + await accountPage.saveAccount();
  144 + });
  145 +
  146 + // 步骤2:修改账目
  147 + await allure.step('修改账目', async () => {
  148 + await accountPage.updateAccount(originalName, newName, incomeType, remark);
  149 + });
  150 +
  151 + // 步骤3:验证账目修改成功
  152 + await allure.step('验证账目修改成功', async () => {
  153 + // 清除搜索框
  154 + await accountPage.clearSearchBox();
  155 + // 搜索修改后的账目名称
  156 + await accountPage.searchAccount(newName);
  157 + const isExists = await accountPage.verifyAccountExists(newName);
  158 + expect(isExists).toBeTruthy();
  159 + });
  160 + });
  161 +});
... ...
tests/customerGroup.spec.ts
1 1 import { test, expect } from '@playwright/test';
2 2 import * as allure from 'allure-js-commons';
  3 +import { CustomerGroupPage } from '../pages/customerGroupPage';
3 4  
4 5 /**
5 6 * 客户分组测试
... ... @@ -32,6 +33,8 @@ test.describe(&#39;客户分组&#39;, () =&gt; {
32 33 }
33 34  
34 35 test('新增客户分组', async ({ page }, testInfo) => {
  36 + const customerGroupPage = new CustomerGroupPage(page);
  37 +
35 38 // 添加allure元素
36 39 await allure.epic('客户管理');
37 40 await allure.feature('客户分组');
... ... @@ -43,47 +46,34 @@ test.describe(&#39;客户分组&#39;, () =&gt; {
43 46  
44 47 // 步骤1:进入客户分组页面
45 48 await allure.step('进入客户分组页面', async () => {
46   - await page.goto('/');
47   - await page.waitForLoadState('networkidle', { timeout: 30000 });
48   - await page.getByText('更多 >').click();
49   - await page.waitForTimeout(500);
50   - await page.getByText('客户分组').first().click();
51   - await page.waitForLoadState('networkidle', { timeout: 30000 });
  49 + await customerGroupPage.openCustomerGroupManagement();
52 50 });
53 51  
54 52 // 步骤2:点击新建按钮
55 53 await allure.step('点击新建按钮', async () => {
56   - await page.getByText('新建').click();
57   - await page.waitForTimeout(500);
  54 + await customerGroupPage.clickNewButton();
58 55 });
59 56  
60 57 // 步骤3:填写分组信息
61 58 await allure.step('填写分组信息', async () => {
62   - // 填写分组名称
63   - await page.getByRole('textbox').nth(1).click();
64   - await page.getByRole('textbox').nth(1).fill(groupName);
65   -
66   - // 填写备注/排序
67   - await page.getByRole('textbox').nth(2).click();
68   - await page.getByRole('textbox').nth(2).fill('自动化测试分组');
  59 + await customerGroupPage.fillGroupName(groupName);
69 60 });
70 61  
71 62 // 步骤4:保存分组
72 63 await allure.step('保存分组', async () => {
73   - await page.getByText('确定').click();
74   - await page.waitForTimeout(1000);
  64 + await customerGroupPage.clickConfirm();
75 65 });
76 66  
77   - // 步骤5:验证分组创建成功 - 使用正则匹配检查页面是否出现新增的内容
  67 + // 步骤5:验证分组创建成功
78 68 await allure.step('验证分组创建成功', async () => {
79   - await page.waitForTimeout(1000); // 等待页面刷新
80   - // 使用正则匹配分组名称
81   - const isGroupVisible = await page.locator('uni-view').filter({ hasText: new RegExp(`^${groupName}$`) }).first().isVisible({ timeout: 5000 }).catch(() => false);
82   - expect(isGroupVisible).toBeTruthy();
  69 + const isExists = await customerGroupPage.verifyGroupExists(groupName);
  70 + expect(isExists).toBeTruthy();
83 71 });
84 72 });
85 73  
86 74 test('修改客户分组', async ({ page }, testInfo) => {
  75 + const customerGroupPage = new CustomerGroupPage(page);
  76 +
87 77 // 添加allure元素
88 78 await allure.epic('客户管理');
89 79 await allure.feature('客户分组');
... ... @@ -92,71 +82,30 @@ test.describe(&#39;客户分组&#39;, () =&gt; {
92 82 // 先生成一个分组用于修改
93 83 const originalGroupName = generateGroupName();
94 84 const newGroupName = generateGroupName();
  85 + const newSortNumber = generateSortNumber();
95 86 console.log('原分组名称:', originalGroupName);
96 87 console.log('新分组名称:', newGroupName);
97 88  
98   - // 步骤1:进入客户分组页面并创建分组
99   - await allure.step('进入客户分组页面并创建分组', async () => {
100   - await page.goto('/');
101   - await page.waitForLoadState('networkidle', { timeout: 30000 });
102   - await page.getByText('更多 >').click();
103   - await page.waitForTimeout(500);
104   - await page.getByText('客户分组').first().click();
105   - await page.waitForLoadState('networkidle', { timeout: 30000 });
106   -
107   - // 创建分组
108   - await page.getByText('新建').click();
109   - await page.waitForTimeout(500);
110   - // 点击分组名称输入框
111   - await page.locator('uni-view').filter({ hasText: /^分组名称\*$/ }).first().click();
112   - await page.getByRole('textbox').nth(1).fill(originalGroupName);
113   - await page.getByText('确定').click();
114   - await page.waitForTimeout(1000);
  89 + // 步骤1:先创建分组
  90 + await allure.step('创建待修改的分组', async () => {
  91 + await customerGroupPage.createGroup(originalGroupName);
115 92 });
116 93  
117   - // 步骤2:搜索并修改分组
118   - await allure.step('搜索并修改分组', async () => {
119   - // 在搜索框中输入原分组名称
120   - await page.getByRole('textbox').click();
121   - await page.getByRole('textbox').fill(originalGroupName);
122   -
123   - // 点击搜索结果中的分组
124   - await page.locator('uni-view').filter({ hasText: new RegExp(`^${originalGroupName}$`) }).first().click();
125   - await page.waitForTimeout(500);
126   -
127   - // 点击编辑按钮
128   - await page.getByText('编辑').click();
129   - await page.waitForTimeout(500);
130   -
131   - // 清空分组名称并填写新名称
132   - await page.getByRole('textbox').nth(1).click();
133   - await page.locator('.nut-input__clear-icon').first().click();
134   - await page.getByRole('textbox').nth(1).click();
135   - await page.getByRole('textbox').nth(1).fill(newGroupName);
136   -
137   - // 直接填写新排序号(新增时未填写,无需清除)
138   - const newSortNumber = generateSortNumber();
139   - await page.getByRole('textbox').nth(2).click();
140   - await page.getByRole('textbox').nth(2).fill(newSortNumber);
141   -
142   - await page.getByText('确定').click();
143   - await page.waitForTimeout(1000);
  94 + // 步骤2:修改分组
  95 + await allure.step('修改分组', async () => {
  96 + await customerGroupPage.updateGroup(originalGroupName, newGroupName, newSortNumber);
144 97 });
145 98  
146   - // 步骤3:验证分组修改成功 - 使用搜索验证修改后的内容
  99 + // 步骤3:验证分组修改成功
147 100 await allure.step('验证分组修改成功', async () => {
148   - // 在搜索框中输入新分组名称进行验证
149   - await page.waitForTimeout(500);
150   - await page.getByRole('textbox').click();
151   - await page.getByRole('textbox').fill(newGroupName);
152   - await page.waitForTimeout(500);
153   -
154   - const isNewGroupVisible = await page.locator('uni-view').filter({ hasText: new RegExp(`^${newGroupName}$`) }).first().isVisible({ timeout: 5000 }).catch(() => false);
155   - expect(isNewGroupVisible).toBeTruthy();
  101 + const isExists = await customerGroupPage.verifyGroupExists(newGroupName);
  102 + expect(isExists).toBeTruthy();
156 103 });
157 104 });
158 105  
159 106 test('删除客户分组', async ({ page }, testInfo) => {
  107 + const customerGroupPage = new CustomerGroupPage(page);
  108 +
160 109 // 添加allure元素
161 110 await allure.epic('客户管理');
162 111 await allure.feature('客户分组');
... ... @@ -166,53 +115,20 @@ test.describe(&#39;客户分组&#39;, () =&gt; {
166 115 const groupName = generateGroupName();
167 116 console.log('待删除分组名称:', groupName);
168 117  
169   - // 步骤1:进入客户分组页面并创建分组
170   - await allure.step('进入客户分组页面并创建分组', async () => {
171   - await page.goto('/');
172   - await page.waitForLoadState('networkidle', { timeout: 30000 });
173   - await page.getByText('更多 >').click();
174   - await page.waitForTimeout(500);
175   - await page.getByText('客户分组').first().click();
176   - await page.waitForLoadState('networkidle', { timeout: 30000 });
177   -
178   - // 创建分组
179   - await page.getByText('新建').click();
180   - await page.waitForTimeout(500);
181   - await page.getByRole('textbox').nth(1).click();
182   - await page.getByRole('textbox').nth(1).fill(groupName);
183   - await page.getByText('确定').click();
184   - await page.waitForTimeout(1000);
  118 + // 步骤1:先创建分组
  119 + await allure.step('创建待删除的分组', async () => {
  120 + await customerGroupPage.createGroup(groupName);
185 121 });
186 122  
187   - // 步骤2:搜索并删除分组
188   - await allure.step('搜索并删除分组', async () => {
189   - // 在搜索框中输入分组名称
190   - await page.getByRole('textbox').click();
191   - await page.getByRole('textbox').fill(groupName);
192   -
193   - // 搜索后自动选中,直接点击删除按钮
194   - await page.getByText('删除').click();
195   - await page.waitForTimeout(500);
196   -
197   - // 确认删除
198   - await page.getByText('确定', { exact: true }).click();
199   - // await page.waitForTimeout(1000);
200   -
201   - // 点击清除按钮
202   - await page.locator('.nut-searchbar__search-icon').click();
203   - // 清除后等待页面刷新
204   - await page.waitForTimeout(1000);
  123 + // 步骤2:删除分组
  124 + await allure.step('删除分组', async () => {
  125 + await customerGroupPage.deleteGroup(groupName);
205 126 });
206 127  
207 128 // 步骤3:验证分组删除成功
208 129 await allure.step('验证分组删除成功', async () => {
209   - // 搜索已删除的分组名称
210   - await page.getByRole('textbox').fill(groupName);
211   - await page.waitForTimeout(1000);
212   -
213   - // 验证搜索结果中是否还能找到该分组(找不到才是删除成功)
214   - const count = await page.locator('uni-view').filter({ hasText: new RegExp(`^${groupName}$`) }).count();
215   - expect(count).toBe(0);
  130 + const isNotExists = await customerGroupPage.verifyGroupNotExists(groupName);
  131 + expect(isNotExists).toBeTruthy();
216 132 });
217 133 });
218 134 });
... ...