// @ts-check import { test, expect } from '@/fixtures/staff_common.js'; import { Employees } from '@/common/userconfig'; test.describe('目标-目标设置', () => { test('门店设置一店', async ({ page, baseURL, numberInput }) => { const goal = '100'; //目标金额 let verifys; //校验值 const employeeA = Employees.FirstShop.Employee_3.name; await page.goto(baseURL ?? ''); await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(process.env.staff1_account ?? ''); await page.locator('.pass_svg').waitFor(); await page.getByRole('textbox', { name: '请输入登录密码' }).fill(process.env.staff1_password ?? ''); await page.getByRole('textbox', { name: '请输入登录密码' }).press('Enter'); await page.getByRole('button', { name: '同意并登录' }).click(); // await page.getByText('美容顾问 一店顾问').click(); // End of authentication steps. await expect(page.getByText('收银', { exact: true })).toBeVisible(); await page.waitForLoadState('networkidle'); await page .locator('div') .filter({ hasText: /^目标$/ }) .first() .click(); await page.getByRole('button', { name: '设置目标' }).click(); // 员工A内行数 let nowRowA = 0; const allTrA = page.locator('.popupComTableStyle .m-table__fixed-left tbody tr'); const countA = await allTrA.count(); // 获取项目处于第几行 for (let i = 0; i < countA; i++) { const trA = allTrA.nth(i); const employee = await trA.locator('.popupEmployeeName').first().innerText(); console.log(employee); if (employee.includes(employeeA)) { nowRowA = i; break; } } await page .locator('.popupComTableStyle .m-table__body .main-table-body_tr') .nth(nowRowA) .locator('.m-table-cell') .nth(1) .click(); await numberInput.setValue('common', Number(goal)); await numberInput.confirmValue(); await page.getByRole('button', { name: '保 存' }).click(); // 员工A外行数 let nowRowB = 0; const allTrB = page.locator('.tableStyle .m-table__fixed-left tbody tr'); const countB = await allTrB.count(); // 获取项目处于第几行 for (let i = 0; i < countB; i++) { const trB = allTrB.nth(i); const employee = await trB.locator('.employeeName').first().innerText(); console.log(employee); if (employee.includes(employeeA)) { nowRowB = i; break; } } const verify = await page .locator('.tableStyle .m-table__body-wrapper tbody tr') .nth(nowRowB) .locator('.is-right .targetValue') .nth(0) .innerText(); if (verify === '--') { verifys = 0; } else { verifys = verify; } // 对比输入的目标 expect.soft(verifys).toBe(goal); // 清理 await page.getByRole('button', { name: '设置目标' }).click(); // 员工A内行数 for (let i = 0; i < countA; i++) { const trA = allTrA.nth(i); const employee = await trA.locator('.popupEmployeeName').first().innerText(); console.log(employee); if (employee.includes(employeeA)) { nowRowA = i; break; } } await page .locator('.popupComTableStyle .m-table__body .main-table-body_tr') .nth(nowRowA) .locator('.m-table-cell') .nth(1) .click(); await numberInput.setValue('common', 0); await numberInput.confirmValue(); await page.getByRole('button', { name: '保 存' }).click(); }); test('门店设置二店', async ({ page, baseURL }) => { await page.goto(baseURL ?? ''); await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(process.env.staff2_account ?? ''); await page.locator('.pass_svg').waitFor(); await page.getByRole('textbox', { name: '请输入登录密码' }).fill(process.env.staff2_password ?? ''); await page.getByRole('textbox', { name: '请输入登录密码' }).press('Enter'); await page.getByRole('button', { name: '同意并登录' }).click(); try { await page.locator('.versionModal_main_content').waitFor({ timeout: 5000 }); await page.locator('.versionModal_main_content .close_icon').click(); } catch { console.log('无版本更新'); } await expect(page.getByText('收银', { exact: true })).toBeVisible(); await page.waitForLoadState('networkidle'); await page .locator('div') .filter({ hasText: /^目标$/ }) .first() .click(); await page.getByRole('button', { name: '设置目标' }).waitFor(); await page.getByRole('button', { name: '设置目标' }).click(); await expect.soft(page.locator('.popup_content', { hasText: '温馨提示' })).toBeVisible(); const WarmReminder = await page.locator('.popup_content .content div').innerText(); console.log(WarmReminder); expect .soft(WarmReminder) .toBe('亲,该门店(AT测试二店)尚未开通目标管理功能,您不可为员工设置目标,也无法跟进员工目标完成情况。'); await page.getByRole('button', { name: '我知道了' }).click(); }); test('员工设置', async ({ page, numberInput }) => { // A员工李娜账号密码 const accountA = '139876543'; const passwordA = 'a123456'; // B员工刘强账号密码 const accountB = '134987612'; const passwordB = 'a123456'; const employeeA = Employees.FirstShop.Employee_4.name; // 刘强 const employeeB = Employees.FirstShop.Employee_8.name; // 刘强 const employeeC = Employees.FirstShop.Employee_9.name; // 周萍 const goalB = '100'; const goalC = '200'; let verifyB; //校验B员工 let verifyC; //校验C员工 let verify; //汇总 await page.goto(process.env.BASE_URL ?? ''); await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(accountA); await page.locator('.pass_svg').waitFor(); await page.getByRole('textbox', { name: '请输入登录密码' }).fill(passwordA); await page.getByRole('textbox', { name: '请输入登录密码' }).press('Enter'); await page.getByRole('button', { name: '同意并登录' }).click(); // await page.getByText('美容顾问 一店顾问').click(); // End of authentication steps. await expect(page.getByText('收银', { exact: true })).toBeVisible(); await page.waitForLoadState('networkidle'); await page .locator('div') .filter({ hasText: /^目标$/ }) .first() .click(); await page.getByRole('button', { name: '设置目标' }).click(); // 员工B内行数 let nowRowB = 0; const allTrB = page.locator('.popupComTableStyle .m-table__fixed-left tbody tr'); const countB = await allTrB.count(); // 获取项目处于第几行 for (let i = 0; i < countB; i++) { const trB = allTrB.nth(i); const employee = await trB.locator('.popupEmployeeName').first().innerText(); console.log(employee); if (employee.includes(employeeB)) { nowRowB = i; break; } } const code = page.locator('.popupComTableStyle .m-table__body .main-table-body_tr'); await code.nth(nowRowB).locator('.m-table-cell').nth(1).click(); await numberInput.setValue('common', Number(goalB)); await numberInput.confirmValue(); // 员工C内行数 let nowRowC = 0; const allTrC = page.locator('.popupComTableStyle .m-table__fixed-left tbody tr'); const countC = await allTrC.count(); // 获取项目处于第几行 for (let i = 0; i < countC; i++) { const trA = allTrC.nth(i); const employee = await trA.locator('.popupEmployeeName').first().innerText(); console.log(employee); if (employee.includes(employeeC)) { nowRowC = i; break; } } // 判断李娜在目标设置不存在 await expect( page .locator('.popupComTableStyle .m-table__fixed-left tbody tr') .locator('.popupEmployeeName', { hasText: employeeA }), ).not.toBeVisible(); await code.nth(nowRowC).locator('.m-table-cell').nth(1).click(); await numberInput.setValue('common', Number(goalC)); await numberInput.confirmValue(); await page.getByRole('button', { name: /保\s存/ }).click(); // 员工B外行数 const allTrBB = page.locator('.tableStyle .m-table__fixed-left tbody tr'); const nowRowBB = await allTrBB.allInnerTexts().then(text => { return text.findIndex(value => value.includes(employeeB)); }); if (nowRowBB === -1) { throw new Error('员工B不存在'); } const codes = page.locator('.tableStyle .m-table__body-wrapper tbody tr'); // 对比输入的目标 await expect(codes.nth(nowRowBB).locator('.is-right .targetValue').nth(0)).toContainText(goalB); // 员工C外行数 const allTrCC = page.locator('.tableStyle .m-table__fixed-left tbody tr'); const nowRowCC = await allTrCC.allInnerTexts().then(text => { return text.findIndex(value => value.includes(employeeC)); }); // 对比输入的目标 await expect(codes.nth(nowRowCC).locator('.is-right .targetValue').nth(0)).toContainText(goalC); // 总数 const allTr = page.locator('.tableStyle .m-table__fixed-left tbody tr'); let nowRow = await allTr.allInnerTexts().then(text => { return text.findIndex(value => value.includes('目标汇总')); }); // 对比输入的目标 await expect .soft(codes.nth(nowRow).locator('.is-right .targetValue').nth(0)) .toContainText(`${Number(goalB) + Number(goalC)}`); // 退出登录 await page.locator('.exit_btn').click(); await page.locator('.comfirm_btn').click(); await page.goto(process.env.BASE_URL ?? ''); await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(accountB); await page.locator('.pass_svg').waitFor(); await page.getByRole('textbox', { name: '请输入登录密码' }).fill(passwordB); await page.getByRole('textbox', { name: '请输入登录密码' }).press('Enter'); await page.waitForLoadState('networkidle'); await page .locator('div') .filter({ hasText: /^目标$/ }) .first() .click(); await expect(page.locator('.m-table__fixed-left .m-table-cell', { hasText: '日期' })).toBeVisible(); }); });