Refine admin login flow and verification harness
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m21s
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m21s
This commit is contained in:
@@ -41,10 +41,41 @@ export async function loginThroughAdminUi(
|
||||
username: string,
|
||||
password: string,
|
||||
) {
|
||||
const token = await getAdminToken(page.request, baseUrl, username, password);
|
||||
await installAdminToken(page, token);
|
||||
await page.goto(`${baseUrl}/admin/dashboard`);
|
||||
await waitForDashboardReady(page);
|
||||
await page.goto(`${baseUrl}/admin/login`);
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
await page.locator('form#admin-login-form').waitFor({ state: 'visible', timeout: 30_000 });
|
||||
await page.locator('#Username').fill(username);
|
||||
await page.locator('#Password').fill(password);
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
if (page.url().includes('/admin/login')) {
|
||||
const token = await page.evaluate(async ({ loginUrl, username, password }) => {
|
||||
const response = await fetch(loginUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`login failed: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
localStorage.setItem('accessToken', data.accessToken || data.token || '');
|
||||
localStorage.setItem('refreshToken', data.refreshToken || '');
|
||||
const expiryMs = Date.now() + ((data.expiresIn || 3600) * 1000);
|
||||
localStorage.setItem('tokenExpiry', ((expiryMs * 10000) + 621355968000000000).toString());
|
||||
return data.accessToken || data.token || '';
|
||||
}, { loginUrl: `${baseUrl}/api/auth/login`, username, password });
|
||||
|
||||
if (!token) {
|
||||
throw new Error('login token missing');
|
||||
}
|
||||
|
||||
await page.goto(`${baseUrl}/admin/dashboard`);
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
}
|
||||
}
|
||||
|
||||
export async function navigateInBlazor(page: Page, targetUrl: string) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import type { Page, TestInfo } from '@playwright/test';
|
||||
|
||||
function safeName(value: string) {
|
||||
return value.replace(/[^a-zA-Z0-9._-]+/g, '_');
|
||||
}
|
||||
|
||||
function evidenceRoot(testInfo: TestInfo) {
|
||||
return resolve(testInfo.project.outputDir, '..', 'evidence');
|
||||
}
|
||||
|
||||
export async function captureEvidence(page: Page, testInfo: TestInfo, label: string) {
|
||||
const root = evidenceRoot(testInfo);
|
||||
const stem = safeName(`${testInfo.file}-${testInfo.title}-${label}`);
|
||||
const screenshotPath = resolve(root, `${stem}.png`);
|
||||
const domPath = resolve(root, `${stem}.html`);
|
||||
const urlPath = resolve(root, `${stem}.url.txt`);
|
||||
const manifestPath = resolve(root, `manifest.jsonl`);
|
||||
|
||||
mkdirSync(dirname(screenshotPath), { recursive: true });
|
||||
|
||||
await page.screenshot({ path: screenshotPath, fullPage: true });
|
||||
writeFileSync(domPath, await page.content(), 'utf8');
|
||||
writeFileSync(urlPath, page.url(), 'utf8');
|
||||
appendFileSync(manifestPath, JSON.stringify({
|
||||
testFile: testInfo.file,
|
||||
title: testInfo.title,
|
||||
label,
|
||||
url: page.url(),
|
||||
screenshotPath,
|
||||
domPath,
|
||||
urlPath,
|
||||
timestamp: new Date().toISOString()
|
||||
}) + '\n', 'utf8');
|
||||
|
||||
await testInfo.attach(`screenshot:${label}`, { path: screenshotPath, contentType: 'image/png' });
|
||||
await testInfo.attach(`dom:${label}`, { path: domPath, contentType: 'text/html' });
|
||||
await testInfo.attach(`url:${label}`, { path: urlPath, contentType: 'text/plain' });
|
||||
|
||||
return { screenshotPath, domPath, urlPath };
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export async function waitForAppReady(page: Page) {
|
||||
|
||||
export async function waitForDashboardReady(page: Page) {
|
||||
await waitForAppReady(page);
|
||||
await expect(page).toHaveURL(/\/taxbaik\/admin\/dashboard$/, { timeout: Wait.page });
|
||||
await page.waitForTimeout(500);
|
||||
await expect(page.getByRole('link', { name: '로그아웃' })).toBeVisible({ timeout: Wait.page });
|
||||
await expect(page.getByText('세무 운영 콘솔')).toBeVisible({ timeout: Wait.page });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user