Files
termi-blog/playwright-smoke/tests/helpers.ts
limitcool ee0bec4a78
Some checks failed
docker-images / build-and-push (admin, admin, termi-astro-admin, admin/Dockerfile) (push) Successful in 52s
docker-images / build-and-push (backend, backend, termi-astro-backend, backend/Dockerfile) (push) Failing after 13s
docker-images / build-and-push (frontend, frontend, termi-astro-frontend, frontend/Dockerfile) (push) Successful in 32s
ui-regression / playwright-regression (push) Failing after 14m24s
test: add full playwright ui regression coverage
2026-04-02 00:55:34 +08:00

30 lines
1006 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, type APIRequestContext, type Page } from '@playwright/test'
export const MOCK_BASE_URL = 'http://127.0.0.1:5159'
export const ADMIN_COOKIE = {
name: 'termi_admin_session',
value: 'mock-admin-session',
domain: '127.0.0.1',
path: '/',
}
export async function resetMockState(request: APIRequestContext) {
const response = await request.post(`${MOCK_BASE_URL}/__playwright/reset`)
expect(response.ok()).toBeTruthy()
}
export async function getDebugState(request: APIRequestContext) {
const response = await request.get(`${MOCK_BASE_URL}/__playwright/state`)
expect(response.ok()).toBeTruthy()
return response.json()
}
export async function loginAdmin(page: Page) {
await page.goto('/login')
await page.getByLabel('用户名').fill('admin')
await page.getByLabel('密码').fill('admin123')
await page.getByRole('button', { name: '进入后台' }).click()
await expect(page).toHaveURL(/\/$/)
await expect(page.getByText('当前登录admin')).toBeVisible()
}