This repository has been archived on 2025-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
playwright-demo/tests/admin.setup.js
2024-10-16 16:20:53 +08:00

55 lines
2.3 KiB
JavaScript

const { test: setup, expect } = require('@playwright/test');
const path = require('path');
const authFile = path.join(__dirname, '../.auth/admin.json');
const zhbAuthFile = path.join(__dirname, '../.auth/zhb_admin.json');
const mgjAuthFile = path.join(__dirname, '../.auth/mgj_admin.json');
setup('hlk总部管理员登录', async ({ page, baseURL }) => {
const $account = page.getByRole('textbox', { name: '请输入您的手机号码' });
const $password = page.getByRole('textbox', { name: '请输入登录密码' });
const $loginBtn = page.getByRole('button', { name: /登\s录/ });
const account = process.env.ACCOUNT;
const password = process.env.PASSWORD;
await page.goto(baseURL);
await $account.fill(account);
const phoneStatsIcon = page.locator('.ant-row', { has: $account }).locator('.pass_svg');
await $password.fill(password);
await page.getByLabel('请同意慧来客隐私政策和用户协议').check();
await expect(phoneStatsIcon).toBeVisible();
await $loginBtn.click();
await expect(page.getByRole('button', { name: /开\s单/ })).toBeVisible();
await page.context().storageState({ path: authFile });
});
setup('zhb总部管理员登录', async ({ page }) => {
const baseURL = process.env.ZHB_BASE_URL;
const account = process.env.ZHB_ACCOUNT;
const password = process.env.ZHB_PASSWORD;
const $account = page.getByPlaceholder('账户');
const $password = page.getByPlaceholder('密码');
const $loginBtn = page.getByRole('button', { name: /登\s录/ });
await page.goto(baseURL);
await $account.fill(account);
await $password.fill(password);
await $loginBtn.click();
await expect(page.getByRole('heading', { name: '收银' })).toBeVisible();
await page.context().storageState({ path: zhbAuthFile });
});
setup('mgj管理员登录', async ({ page }) => {
const baseURL = process.env.MGJ_BASE_URL;
const account = process.env.MGJ_ACCOUNT;
const password = process.env.MGJ_PASSWORD;
await page.goto(baseURL);
await page.getByPlaceholder('请输入您的用户名').fill(account);
await page.getByPlaceholder('请输入密码').fill(password);
await page.getByText('登录', { exact: true }).click();
await expect(page.getByRole('link', { name: '管理层' })).toBeVisible();
await page.context().storageState({ path: mgjAuthFile });
});