- 更新环境变量配置方式,使用 dotenv 库 - 重构员工登录和权限相关代码,提高可维护性 - 优化测试数据结构,增加类型注解 - 删除冗余代码,提高代码可读性
38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import { test as setup, expect } from '@playwright/test';
|
|
import { getEnvVar } from '@/utils/envUtils';
|
|
|
|
const employee = [
|
|
{
|
|
phone: process.env.staff1_account,
|
|
password: process.env.staff1_password,
|
|
authFile: '.auth/user_1.json',
|
|
},
|
|
{
|
|
phone: process.env.staff2_account,
|
|
password: process.env.staff2_password,
|
|
authFile: '.auth/user_2.json',
|
|
},
|
|
];
|
|
|
|
setup.describe('员工登录', () => {
|
|
for (const e of employee) {
|
|
setup(`门店员工登录_${e.phone}`, async ({ page }) => {
|
|
const phone = e.phone || '';
|
|
const password = e.password || '';
|
|
const baseUrl = getEnvVar('BASE_URL');
|
|
const $phone = page.getByRole('textbox', { name: '请输入您的手机号码' });
|
|
const $password = page.getByRole('textbox', { name: '请输入登录密码' });
|
|
const $login = page.getByRole('button', { name: /登\s录/ });
|
|
await page.goto(baseUrl);
|
|
await $phone.fill(phone);
|
|
const checkPhone = page.locator('.ant-row', { has: $phone }).locator('.pass_svg');
|
|
await expect(checkPhone).toBeVisible();
|
|
await $password.fill(password);
|
|
await page.getByLabel('请同意慧来客隐私政策和用户协议').check();
|
|
await $login.click();
|
|
await expect(page.getByRole('button', { name: /开\s单/ })).toBeEnabled();
|
|
await page.context().storageState({ path: e.authFile });
|
|
});
|
|
}
|
|
});
|