R7E 浏览器业务先行试运行证据回填
这个提交包含在:
@@ -1,8 +1,8 @@
|
||||
import { expect, type Page } from "@playwright/test";
|
||||
|
||||
import { logout } from "./auth";
|
||||
import { createAuthenticatedApiClient, logout, type AuthenticatedApiClient, type E2EUser } from "./auth";
|
||||
|
||||
export type LiveSmokeRole = "admin" | "employee";
|
||||
export type LiveSmokeRole = "admin" | "employee" | "manager" | "finance" | "financeMgr";
|
||||
|
||||
export type LiveSmokeUser = {
|
||||
role: LiveSmokeRole;
|
||||
@@ -24,18 +24,34 @@ export function getExpectedWecomStatus() {
|
||||
}
|
||||
|
||||
export function getLiveSmokeUser(role: LiveSmokeRole) {
|
||||
if (role === "admin") {
|
||||
return {
|
||||
role,
|
||||
identifier: requireEnv("LIVE_SMOKE_ADMIN_IDENTIFIER"),
|
||||
password: requireEnv("LIVE_SMOKE_ADMIN_PASSWORD"),
|
||||
};
|
||||
}
|
||||
const envByRole: Record<LiveSmokeRole, { identifier: string; password: string }> = {
|
||||
admin: {
|
||||
identifier: "LIVE_SMOKE_ADMIN_IDENTIFIER",
|
||||
password: "LIVE_SMOKE_ADMIN_PASSWORD",
|
||||
},
|
||||
employee: {
|
||||
identifier: "LIVE_SMOKE_EMPLOYEE_IDENTIFIER",
|
||||
password: "LIVE_SMOKE_EMPLOYEE_PASSWORD",
|
||||
},
|
||||
manager: {
|
||||
identifier: "LIVE_SMOKE_MANAGER_IDENTIFIER",
|
||||
password: "LIVE_SMOKE_MANAGER_PASSWORD",
|
||||
},
|
||||
finance: {
|
||||
identifier: "LIVE_SMOKE_FINANCE_IDENTIFIER",
|
||||
password: "LIVE_SMOKE_FINANCE_PASSWORD",
|
||||
},
|
||||
financeMgr: {
|
||||
identifier: "LIVE_SMOKE_FINANCE_MGR_IDENTIFIER",
|
||||
password: "LIVE_SMOKE_FINANCE_MGR_PASSWORD",
|
||||
},
|
||||
};
|
||||
const env = envByRole[role];
|
||||
|
||||
return {
|
||||
role,
|
||||
identifier: requireEnv("LIVE_SMOKE_EMPLOYEE_IDENTIFIER"),
|
||||
password: requireEnv("LIVE_SMOKE_EMPLOYEE_PASSWORD"),
|
||||
identifier: requireEnv(env.identifier),
|
||||
password: requireEnv(env.password),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -57,7 +73,14 @@ export async function loginLiveUser(page: Page, role: LiveSmokeRole): Promise<Li
|
||||
await page.getByTestId("login-identifier").fill(credentials.identifier);
|
||||
await page.getByTestId("login-password").fill(credentials.password);
|
||||
await page.getByTestId("login-submit").click();
|
||||
await expect(page).toHaveURL(/\/portal/);
|
||||
await expect(page).toHaveURL(/\/portal/, { timeout: 30_000 }).catch(async (error) => {
|
||||
const loginError = page.locator(".text-red-600, .text-red-700, [role='alert']").first();
|
||||
const message = (await loginError.textContent().catch(() => ""))?.trim();
|
||||
if (message) {
|
||||
throw new Error(`live 登录失败:${message}`);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
|
||||
const name = await readCurrentUserName(page);
|
||||
|
||||
@@ -70,3 +93,22 @@ export async function loginLiveUser(page: Page, role: LiveSmokeRole): Promise<Li
|
||||
export async function logoutLiveUser(page: Page, user?: Pick<LiveSmokeUser, "name">) {
|
||||
await logout(page, user?.name);
|
||||
}
|
||||
|
||||
export function getRequiredLiveUser(role: LiveSmokeRole): E2EUser {
|
||||
const credentials = getLiveSmokeUser(role);
|
||||
|
||||
return {
|
||||
identifier: credentials.identifier,
|
||||
password: credentials.password,
|
||||
name: role,
|
||||
};
|
||||
}
|
||||
|
||||
export async function loginLiveBrowserUser(page: Page, role: LiveSmokeRole): Promise<LiveSmokeUser> {
|
||||
return loginLiveUser(page, role);
|
||||
}
|
||||
|
||||
export async function createLiveApiClient(role: LiveSmokeRole): Promise<AuthenticatedApiClient> {
|
||||
const baseURL = process.env.LIVE_SMOKE_BASE_URL?.trim() || "https://oa.hyinda.com";
|
||||
return createAuthenticatedApiClient(getRequiredLiveUser(role), baseURL);
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户