- Created a global setup file to handle user login and merchant selection based on identity verification. - Implemented a test specification to verify the identity verification tool and log merchant details.
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { test as setup } from '@playwright/test';
|
|
import { LoginPage } from '../src/page/LoginPage';
|
|
import { identityVerificationTool } from '../src/util/authUtil';
|
|
|
|
setup('state setup', async ({ page }) => {
|
|
const body = await identityVerificationTool('17770898274', 'a123456');
|
|
if (!body.status) {
|
|
console.log('身份验证失败,请选择租户');
|
|
let merchanName: string | undefined = undefined;
|
|
let employeeName: string | undefined = undefined;
|
|
const content = body?.content;
|
|
for (const merchant in content) {
|
|
if (content[merchant]?.merchantId === 373) {
|
|
merchanName = content[merchant]?.merchantName;
|
|
if (content[merchant]?.users.length > 0) {
|
|
employeeName = content[merchant]?.users[0]?.userName;
|
|
}
|
|
}
|
|
}
|
|
await page.goto(process.env.BASE_URL || 'http://localhost:3000');
|
|
const loginPage = new LoginPage(page);
|
|
await loginPage.user_login('17770898274', 'a123456');
|
|
await loginPage.user_select_merchant(merchanName || '美管家');
|
|
console.log(employeeName);
|
|
if (employeeName) {
|
|
await loginPage.user_select_employee(employeeName);
|
|
}
|
|
await page.pause();
|
|
await loginPage.user_login_success().waitFor();
|
|
await page.context().storageState({ path: 'state.json', indexedDB: true });
|
|
return;
|
|
}
|
|
console.log('身份验证成功');
|
|
await page.goto(process.env.BASE_URL || 'http://localhost:3000');
|
|
const loginPage = new LoginPage(page);
|
|
await loginPage.user_login('17770898274', 'a123456');
|
|
await page.pause();
|
|
await loginPage.user_login_success().waitFor();
|
|
await page.context().storageState({ path: 'state.json', indexedDB: true });
|
|
});
|