/** * 발주관리 화면 결재 시스템 E2E 테스트 * 메뉴: 구매관리 → 발주관리 * 실행: npx tsx frontend/scripts/purchase-order-approval-test.ts */ import { chromium } from "playwright"; import { writeFileSync } from "fs"; const BASE_URL = "http://localhost:9771"; const LOGIN_ID = "wace"; const LOGIN_PW = "qlalfqjsgh11"; const results: string[] = []; const screenshotDir = "/Users/gbpark/ERP-node/approval-test-screenshots"; async function main() { const browser = await chromium.launch({ headless: true }); const context = await browser.newContext({ viewport: { width: 1280, height: 900 } }); const page = await context.newPage(); const screenshot = async (name: string) => { const path = `${screenshotDir}/${name}.png`; await page.screenshot({ path, fullPage: true }); results.push(` 스크린샷: ${name}.png`); }; try { // Step 1: 로그인 results.push("\n=== Step 1: 로그인 ==="); await page.goto(BASE_URL, { waitUntil: "domcontentloaded", timeout: 30000 }); await screenshot("01-login-page"); const userIdInput = page.getByPlaceholder("사용자 ID를 입력하세요").or(page.locator('#userId, input[name="userId"]')); const pwInput = page.getByPlaceholder("비밀번호를 입력하세요").or(page.locator('#password, input[name="password"]')); const loginBtn = page.getByRole("button", { name: "로그인" }).or(page.locator('button[type="submit"]')); await userIdInput.first().fill(LOGIN_ID); await pwInput.first().fill(LOGIN_PW); await loginBtn.first().click(); await page.waitForURL((url) => !url.toString().includes("/login"), { timeout: 30000 }); await page.waitForLoadState("domcontentloaded"); await page.waitForTimeout(5000); // 메뉴 로드 대기 await screenshot("02-after-login"); results.push(" OK: 로그인 완료, 대시보드 로드"); // Step 2: 구매관리 → 발주관리 메뉴 이동 (또는 직접 URL) results.push("\n=== Step 2: 구매관리 → 발주관리 메뉴 이동 ==="); const purchaseMenu = page.locator('text="구매관리"').first(); const hasPurchaseMenu = (await purchaseMenu.count()) > 0; let poScreenLoaded = false; if (hasPurchaseMenu) { await purchaseMenu.click(); await page.waitForTimeout(800); await screenshot("03-purchase-menu-expanded"); const poMenu = page.locator('text="발주관리"').or(page.locator('text="발주 관리"')).first(); const hasPoMenu = (await poMenu.count()) > 0; if (hasPoMenu) { await poMenu.click(); await page.waitForTimeout(3000); await screenshot("04-po-screen-loaded"); poScreenLoaded = true; results.push(" OK: 메뉴로 발주관리 화면 이동 완료"); } } if (!poScreenLoaded) { results.push(" INFO: 메뉴에서 발주관리 미발견, 직접 URL로 이동"); const allMenuTexts = await page.locator("aside a, aside button, aside [role='menuitem']").allTextContents(); results.push(` 메뉴 목록: ${JSON.stringify(allMenuTexts.slice(0, 30))}`); await page.goto(`${BASE_URL}/screen/COMPANY_7_064`, { waitUntil: "domcontentloaded", timeout: 20000 }); await page.waitForTimeout(4000); await screenshot("04-po-screen-loaded"); results.push(" OK: /screen/COMPANY_7_064 직접 이동 완료"); } // Step 3: 그리드 컬럼 확인 results.push("\n=== Step 3: 그리드 컬럼 확인 ==="); await page.waitForTimeout(2000); await screenshot("05-grid-columns"); const headers = await page.locator("table th, [role='columnheader']").allTextContents(); const headerTexts = headers.map((h) => h.trim()).filter((h) => h.length > 0); results.push(` 컬럼 목록: ${JSON.stringify(headerTexts)}`); const hasApprovalColumn = headerTexts.some((h) => h.includes("결재상태")); results.push(hasApprovalColumn ? " OK: '결재상태' 컬럼 확인됨" : " FAIL: '결재상태' 컬럼 없음"); // 결재상태 값 확인 (작성중 등) const statusCellTexts = await page.locator("table tbody td").allTextContents(); const approvalValues = statusCellTexts.filter((t) => ["작성중", "결재중", "결재완료", "반려"].some((s) => t.includes(s)) ); results.push(` 결재상태 값: ${approvalValues.length > 0 ? approvalValues.join(", ") : "데이터 없음 또는 해당 값 없음"}`); // Step 4: 행 선택 후 결재 요청 버튼 클릭 results.push("\n=== Step 4: 행 선택 및 결재 요청 버튼 클릭 ==="); const firstRow = page.locator("table tbody tr, [role='row']").first(); const hasRows = (await firstRow.count()) > 0; if (hasRows) { await firstRow.click({ force: true }); await page.waitForTimeout(500); await screenshot("06-row-selected"); results.push(" OK: 첫 번째 행 선택"); } else { results.push(" INFO: 데이터 행 없음, 행 선택 없이 진행"); } const approvalBtn = page.getByRole("button", { name: "결재 요청" }).or(page.locator('button:has-text("결재 요청")')); const hasApprovalBtn = (await approvalBtn.count()) > 0; if (!hasApprovalBtn) { results.push(" FAIL: '결재 요청' 버튼 없음"); } else { await approvalBtn.first().click({ force: true }); await page.waitForTimeout(2000); await screenshot("07-approval-modal-opened"); const modal = page.locator('[role="dialog"]'); const modalOpened = (await modal.count()) > 0; results.push(modalOpened ? " OK: 결재 모달 열림" : " FAIL: 결재 모달 열리지 않음"); } // Step 5: 결재자 검색 테스트 results.push("\n=== Step 5: 결재자 검색 테스트 ==="); const searchInput = page.getByPlaceholder("이름 또는 사번으로 검색...").or( page.locator('input[placeholder*="검색"]') ); const hasSearchInput = (await searchInput.count()) > 0; if (!hasSearchInput) { results.push(" FAIL: 결재자 검색 입력 필드 없음"); } else { await searchInput.first().fill("김"); await page.waitForTimeout(2000); await screenshot("08-approver-search-results"); // 검색 결과 확인 (ApprovalRequestModal: div.max-h-48 내부 button) const searchResults = page.locator( '[role="dialog"] div.max-h-48 button, [role="dialog"] div.overflow-y-auto button' ); const resultCount = await searchResults.count(); const resultTexts = await searchResults.allTextContents(); results.push(` 검색 결과 수: ${resultCount}명`); if (resultTexts.length > 0) { const names = resultTexts.map((t) => t.trim()).filter((t) => t.length > 0); results.push(` 결재자 목록: ${JSON.stringify(names.slice(0, 10))}`); } // "검색 결과가 없습니다" 또는 "검색 중" 메시지 확인 const noResultsMsg = page.locator('text="검색 결과가 없습니다"'); const searchingMsg = page.locator('text="검색 중"'); if ((await noResultsMsg.count()) > 0) results.push(" (검색 결과 없음 메시지 표시됨)"); if ((await searchingMsg.count()) > 0) results.push(" (검색 중 메시지 표시됨 - 대기 부족 가능)"); } // 최종 스크린샷 await screenshot("09-final-state"); } catch (err: any) { results.push(`\nERROR: ${err.message}`); await page.screenshot({ path: `${screenshotDir}/error.png`, fullPage: true }).catch(() => {}); } finally { await browser.close(); } const output = results.join("\n"); console.log("\n" + "=".repeat(60)); console.log("발주관리 결재 시스템 테스트 결과"); console.log("=".repeat(60)); console.log(output); console.log("=".repeat(60)); writeFileSync("/Users/gbpark/ERP-node/approval-test-report.txt", output); } main();