71 lines
3.0 KiB
TypeScript
71 lines
3.0 KiB
TypeScript
import { test as setup } from '@playwright/test';
|
|
import { readIndexedDB } from '@/utils/indexedDBUtils';
|
|
import fs from 'fs';
|
|
|
|
const firstAuthFile = '.auth/admin_first.json';
|
|
const secondAuthFile = '.auth/admin_second.json';
|
|
|
|
const regex = /^https?:\/\/(www\.)?hlk\.meiguanjia\.net\/?(#\s)?$/;
|
|
|
|
/** @param personalizedPages 营销-个性化页面*/
|
|
const personalizedPages = '/#/marketing/brand/personalized';
|
|
|
|
class testAccount {
|
|
constructor(account: string, password: string, path: string) {
|
|
this.account = account;
|
|
this.password = password;
|
|
this.path = path;
|
|
}
|
|
|
|
account: string;
|
|
password: string;
|
|
path: string;
|
|
}
|
|
|
|
const allAccounts = [
|
|
new testAccount(process.env.boss_account!, process.env.boss_password!, firstAuthFile),
|
|
new testAccount(process.env.boss_account_2!, process.env.boss_password_2!, secondAuthFile),
|
|
];
|
|
|
|
for (let a of allAccounts) {
|
|
setup(`租户${a.account}总部管理员登录`, async ({ page, baseURL }) => {
|
|
const account = a.account;
|
|
const password = a.password;
|
|
const savePath = a.path;
|
|
|
|
const $phonePassIcon = page
|
|
.locator('div', { has: page.getByRole('textbox', { name: '请输入您的手机号码' }) })
|
|
.locator('.pass_svg');
|
|
|
|
await page.goto(baseURL!);
|
|
await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(account);
|
|
await page.getByRole('textbox', { name: '请输入登录密码' }).fill(password);
|
|
await page.getByLabel('请同意慧来客隐私政策和用户协议').check();
|
|
await $phonePassIcon.waitFor();
|
|
await page.getByRole('button', { name: /登\s录/ }).click();
|
|
await page.getByRole('button', { name: /开\s单/ }).waitFor();
|
|
|
|
if (regex.test(baseURL!)) {
|
|
await page.goto(personalizedPages);
|
|
await page.getByRole('button', { name: '新增模块' }).waitFor();
|
|
const $sideIframe = page.locator('.side iframe').contentFrame();
|
|
const $logo = $sideIframe.locator('.bar_item', { hasText: '我的' }).locator('.logo');
|
|
await $logo.waitFor();
|
|
await page.reload();
|
|
|
|
await page.getByRole('textbox', { name: '请输入您的手机号码' }).fill(account);
|
|
await page.getByRole('textbox', { name: '请输入登录密码' }).fill(password);
|
|
await page.getByLabel('请同意慧来客隐私政策和用户协议').check();
|
|
await $phonePassIcon.waitFor();
|
|
await page.getByRole('button', { name: /登\s录/ }).click();
|
|
await page.getByRole('button', { name: /开\s单/ }).waitFor();
|
|
}
|
|
const result = await page.evaluate(async readIndexedDBFnString => {
|
|
const readIndexedDBFn = new Function('return ' + readIndexedDBFnString)();
|
|
return await readIndexedDBFn();
|
|
}, readIndexedDB.toString());
|
|
fs.writeFileSync('.auth/admin_first_indexeddb.json', JSON.stringify(result));
|
|
await page.context().storageState({ path: savePath });
|
|
});
|
|
}
|