Files
sam-hotfix/e2e/runner/gen-create-delete.js
김보곤 67d0a4c2fd feat: E2E 시나리오 생성기 및 감사 스크립트 17종 추가
- gen-*.js: 시나리오 자동 생성기 12종 (CRUD, edge, a11y, perf 등)
- search-*.js: 검색/버튼 감사 수집기 3종
- revert-hard-actions.js: 하드 액션 복원 유틸
- _gen_writer.py: 생성기 보조 스크립트

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 16:59:15 +09:00

456 lines
24 KiB
JavaScript

#!/usr/bin/env node
/**
* Create + Delete CRUD 테스트 시나리오 생성기
*
* 각 페이지에서 테스트 데이터를 생성(CREATE)하고 삭제(DELETE)하는 전체 흐름 테스트.
* E2E_TEST_ 접두사 데이터만 사용, 테스트 종료 시 반드시 삭제.
*
* Usage:
* node e2e/runner/gen-create-delete.js
*
* Output:
* e2e/scenarios/create-delete-board.json
* e2e/scenarios/create-delete-acc-bills.json
* e2e/scenarios/create-delete-acc-deposit.json
*/
const fs = require('fs');
const path = require('path');
const SCENARIOS_DIR = path.resolve(__dirname, '..', 'scenarios');
// ════════════════════════════════════════════════════════════════
// COMMON HELPERS (shared across all evaluate scripts)
// ════════════════════════════════════════════════════════════════
const HELPERS = `const w=ms=>new Promise(r=>setTimeout(r,ms));const sv=(el,v)=>{const p=el.tagName==='TEXTAREA'?HTMLTextAreaElement.prototype:HTMLInputElement.prototype;const ns=Object.getOwnPropertyDescriptor(p,'value')?.set;if(ns)ns.call(el,v);else el.value=v;el.dispatchEvent(new Event('input',{bubbles:true}));el.dispatchEvent(new Event('change',{bubbles:true}));};const ts=window.__E2E_TS__||(()=>{const n=new Date();const p=v=>v.toString().padStart(2,'0');return n.getFullYear()+p(n.getMonth()+1)+p(n.getDate())+'_'+p(n.getHours())+p(n.getMinutes())+p(n.getSeconds());})();window.__E2E_TS__=ts;`;
// ════════════════════════════════════════════════════════════════
// PAGE CONFIGURATIONS
// ════════════════════════════════════════════════════════════════
const PAGES = {
// ─── 자유게시판 ─────────────────────────────────────────────
'board': {
id: 'create-delete-board',
name: 'Create+Delete 테스트: 자유게시판',
menuNavigation: { level1: '게시판', level2: '자유게시판' },
expectedUrl: '/boards/free',
// CREATE: click 글쓰기 → fill title+content → click 등록
createScript: [
`(async()=>{`, HELPERS,
`const R={phase:'CREATE',ts};`,
`const testTitle='E2E_TEST_게시글_'+ts;`,
`R.testTitle=testTitle;`,
// Click 글쓰기 button
`const btn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='글쓰기'||/등록|작성/.test(b.innerText?.trim()));`,
`if(!btn){R.error='글쓰기 버튼 없음';return JSON.stringify(R);}`,
`btn.click();await w(2500);`,
`R.url=location.pathname+location.search;`,
// Fill title
`const titleInput=document.querySelector('input[placeholder*="제목"]')||document.querySelector('input[type="text"]');`,
`if(!titleInput){R.error='제목 입력란 없음';return JSON.stringify(R);}`,
`sv(titleInput,testTitle);await w(200);`,
// Fill content (textarea)
`const contentArea=document.querySelector('textarea[placeholder*="내용"]')||document.querySelector('textarea');`,
`if(contentArea){sv(contentArea,'E2E 자동 테스트 게시글입니다. 자동 삭제 예정.');await w(200);}`,
// Click 등록 submit button
`const submitBtn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='등록');`,
`if(!submitBtn){R.error='등록 버튼 없음';return JSON.stringify(R);}`,
`submitBtn.click();await w(3000);`,
// Check result
`R.urlAfter=location.pathname+location.search;`,
`R.navigatedBack=!location.search.includes('mode=new');`,
`R.ok=true;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
// VERIFY: search for the created post in the list
verifyScript: [
`(async()=>{`, HELPERS,
`const R={phase:'VERIFY_CREATE'};`,
`await w(1000);`,
// Check if we're on list page
`R.url=location.pathname;`,
`const rows=document.querySelectorAll('table tbody tr,[class*="list"] [class*="item"]');`,
`R.rowCount=rows.length;`,
// Search for E2E_TEST_ data
`const found=Array.from(rows).find(r=>r.innerText?.includes('E2E_TEST_'));`,
`R.found=!!found;`,
`if(found){R.foundText=found.innerText?.substring(0,80);}`,
`R.ok=R.found;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
// DELETE: find the E2E_TEST_ post → open → delete → confirm
deleteScript: [
`(async()=>{`, HELPERS,
`const R={phase:'DELETE'};`,
// Find and click the E2E_TEST_ row using specific ts
`const rows=Array.from(document.querySelectorAll('table tbody tr'));`,
`const targetRow=rows.find(r=>r.innerText?.includes(ts))||rows.find(r=>r.innerText?.includes('E2E_TEST_'));`,
`if(!targetRow){R.error='E2E_TEST_ 데이터 없음';R.ok=false;return JSON.stringify(R);}`,
`R.targetText=targetRow.innerText?.substring(0,60);R.ts=ts;`,
`targetRow.click();await w(2500);`,
`R.detailUrl=location.pathname+location.search;`,
// Find and click 삭제 button
`const delBtn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='삭제');`,
`if(!delBtn){R.error='삭제 버튼 없음';R.ok=false;return JSON.stringify(R);}`,
`delBtn.click();await w(1000);`,
// Confirm deletion dialog
`const confirmBtn=Array.from(document.querySelectorAll('[role="alertdialog"] button,[role="dialog"] button,button')).find(b=>/확인|삭제|예|Yes/.test(b.innerText?.trim())&&b!==delBtn&&b.offsetParent!==null);`,
`if(confirmBtn){confirmBtn.click();await w(3000);}`,
`R.urlAfter=location.pathname+location.search;`,
`R.ok=true;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
// VERIFY DELETE: check that E2E_TEST_ data is gone from list
verifyDeleteScript: [
`(async()=>{`, HELPERS,
`const R={phase:'VERIFY_DELETE'};`,
`await w(1000);`,
`R.url=location.pathname;R.ts=ts;`,
`const rows=document.querySelectorAll('table tbody tr');`,
`R.rowCount=rows.length;`,
`const found=Array.from(rows).find(r=>r.innerText?.includes(ts));`,
`R.stillExists=!!found;`,
`R.ok=!found;`,
`if(found)R.warn='E2E_TEST_ 데이터가 여전히 존재 - 수동 삭제 필요';`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
},
// ─── 어음관리 ───────────────────────────────────────────────
'bills': {
id: 'create-delete-acc-bills',
name: 'Create+Delete 테스트: 어음관리',
menuNavigation: { level1: '회계관리', level2: '어음관리' },
expectedUrl: '/accounting/bills',
createScript: [
`(async()=>{`, HELPERS,
`const R={phase:'CREATE',ts};`,
`const testId='E2E'+ts.replace(/_/g,'').substring(4,10);`,
`R.testId=testId;`,
// Click 어음 등록
`const btn=Array.from(document.querySelectorAll('button')).find(b=>/어음.*등록|등록/.test(b.innerText?.trim()));`,
`if(!btn){R.error='등록 버튼 없음';return JSON.stringify(R);}`,
`btn.click();await w(2500);`,
`R.url=location.pathname+location.search;`,
// Fill 어음번호 (required)
`const numInput=document.querySelector('input[placeholder*="어음번호"]')||Array.from(document.querySelectorAll('input[type="text"]')).find(i=>i.offsetParent!==null&&!i.readOnly&&!i.disabled);`,
`if(numInput){sv(numInput,'E2E_TEST_'+testId);await w(200);}`,
// Select 구분 combobox (first one - default is 수취, leave as-is)
// Select 거래처 combobox (required)
`const combos=Array.from(document.querySelectorAll('button[role="combobox"]')).filter(b=>b.offsetParent!==null);`,
`R.comboCount=combos.length;`,
// 거래처 combobox - typically the second one
`for(let i=0;i<combos.length;i++){`,
` const cb=combos[i];`,
` const label=cb.closest('[class*=field],[class*=Field],[class*=form-item]')?.querySelector('label')?.innerText||'';`,
` if(label.includes('거래처')||i===1){`,
` cb.click();await w(600);`,
` const lb=document.querySelector('[role="listbox"]');`,
` if(lb){const opt=lb.querySelector('[role="option"]');if(opt){opt.click();await w(400);R.selectedClient=opt.innerText?.trim().substring(0,30);}}`,
` else{document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true}));await w(200);}`,
` break;`,
` }`,
`}`,
// Fill 금액
`const amtInput=document.querySelector('input[placeholder*="금액"]');`,
`if(amtInput){sv(amtInput,'10000');await w(200);}`,
// 발행일/만기일 datepicker - click the date buttons and select today
`const dateButtons=Array.from(document.querySelectorAll('button')).filter(b=>b.innerText?.trim()==='날짜 선택'&&b.offsetParent!==null);`,
`R.dateCount=dateButtons.length;`,
`for(const db of dateButtons){`,
` db.click();await w(500);`,
` const today=document.querySelector('[aria-selected="true"]')||document.querySelector('button[name="day"].bg-primary')||Array.from(document.querySelectorAll('button[name="day"],td button')).find(b=>b.getAttribute('aria-selected')==='true'||b.classList.contains('bg-primary'));`,
` if(today){today.click();await w(300);}`,
` else{document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true}));await w(300);}`,
`}`,
// Fill 비고
`const noteInput=document.querySelector('input[placeholder*="비고"]');`,
`if(noteInput){sv(noteInput,'E2E_TEST_어음_'+ts);await w(200);}`,
// Click 등록 submit
`const submitBtn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='등록'&&b.offsetParent!==null);`,
`if(!submitBtn){R.error='등록 버튼 없음';return JSON.stringify(R);}`,
`submitBtn.click();await w(3000);`,
`R.urlAfter=location.pathname+location.search;`,
`R.navigatedBack=!location.search.includes('mode=new');`,
`R.ok=true;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
verifyScript: [
`(async()=>{`, HELPERS,
`const R={phase:'VERIFY_CREATE'};`,
`await w(1000);`,
`R.url=location.pathname;`,
`const rows=document.querySelectorAll('table tbody tr');`,
`R.rowCount=rows.length;`,
`const found=Array.from(rows).find(r=>r.innerText?.includes('E2E_TEST_')||r.innerText?.includes('E2E'));`,
`R.found=!!found;`,
`if(found)R.foundText=found.innerText?.substring(0,80);`,
`R.ok=R.found;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
deleteScript: [
`(async()=>{`, HELPERS,
`const R={phase:'DELETE'};`,
`const rows=Array.from(document.querySelectorAll('table tbody tr'));`,
`const targetRow=rows.find(r=>r.innerText?.includes(ts))||rows.find(r=>r.innerText?.includes('E2E_TEST_')||r.innerText?.includes('E2E'));`,
`if(!targetRow){R.error='E2E_TEST_ 데이터 없음';R.ok=false;return JSON.stringify(R);}`,
`R.targetText=targetRow.innerText?.substring(0,60);`,
`targetRow.click();await w(2500);`,
`R.detailUrl=location.pathname+location.search;`,
`const delBtn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='삭제');`,
`if(!delBtn){R.error='삭제 버튼 없음';R.ok=false;return JSON.stringify(R);}`,
`delBtn.click();await w(1000);`,
`const confirmBtn=Array.from(document.querySelectorAll('[role="alertdialog"] button,[role="dialog"] button,button')).find(b=>/확인|삭제|예|Yes/.test(b.innerText?.trim())&&b!==delBtn&&b.offsetParent!==null);`,
`if(confirmBtn){confirmBtn.click();await w(3000);}`,
`R.urlAfter=location.pathname+location.search;`,
`R.ok=true;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
verifyDeleteScript: [
`(async()=>{`, HELPERS,
`const R={phase:'VERIFY_DELETE'};`,
`await w(1000);`,
`R.url=location.pathname;`,
// Navigate back to list if still on detail
`if(location.search.includes('mode=view')){`,
` const backBtn=Array.from(document.querySelectorAll('button,a')).find(b=>/목록/.test(b.innerText?.trim()));`,
` if(backBtn){backBtn.click();await w(2000);}`,
` else{history.back();await w(2000);}`,
`}`,
`const rows=document.querySelectorAll('table tbody tr');`,
`R.rowCount=rows.length;`,
`const found=Array.from(rows).find(r=>r.innerText?.includes(ts));`,
`R.stillExists=!!found;`,
`R.ok=!found;R.ts=ts;`,
`if(found)R.warn='E2E_TEST_ 데이터가 여전히 존재 - 수동 삭제 필요';`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
},
// ─── 입금관리 ───────────────────────────────────────────────
'deposit': {
id: 'create-delete-acc-deposit',
name: 'Create+Delete 테스트: 입금관리',
menuNavigation: { level1: '회계관리', level2: '입금관리' },
expectedUrl: '/accounting/deposits',
createScript: [
`(async()=>{`, HELPERS,
`const R={phase:'CREATE',ts};`,
// Click 입금등록
`const btn=Array.from(document.querySelectorAll('button')).find(b=>/입금.*등록|입금등록|등록/.test(b.innerText?.trim()));`,
`if(!btn){R.error='등록 버튼 없음';return JSON.stringify(R);}`,
`btn.click();await w(2500);`,
`R.url=location.pathname+location.search;`,
// Fill 입금자명
`const nameInput=document.querySelector('input[placeholder*="입금자명"]')||document.querySelector('input[placeholder*="입금자"]');`,
`if(nameInput){sv(nameInput,'E2E_TEST_입금자_'+ts);await w(200);}`,
// Fill 입금금액
`const amtInput=document.querySelector('input[placeholder*="입금금액"]')||document.querySelector('input[type="number"]');`,
`if(amtInput){sv(amtInput,'50000');await w(200);}`,
// Fill 적요
`const noteInput=document.querySelector('input[placeholder*="적요"]');`,
`if(noteInput){sv(noteInput,'E2E_TEST_입금_'+ts);await w(200);}`,
// Select 거래처 combobox
`const combos=Array.from(document.querySelectorAll('button[role="combobox"]')).filter(b=>b.offsetParent!==null);`,
`R.comboCount=combos.length;`,
`for(const cb of combos){`,
` const label=cb.closest('[class*=field],[class*=Field],[class*=form-item]')?.querySelector('label')?.innerText||'';`,
` if(label.includes('거래처')){`,
` cb.click();await w(600);`,
` const lb=document.querySelector('[role="listbox"]');`,
` if(lb){const opt=lb.querySelector('[role="option"]');if(opt){opt.click();await w(400);}}`,
` else{document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true}));await w(200);}`,
` break;`,
` }`,
`}`,
// Select 입금 유형 combobox
`for(const cb of combos){`,
` const label=cb.closest('[class*=field],[class*=Field],[class*=form-item]')?.querySelector('label')?.innerText||'';`,
` if(label.includes('입금 유형')||label.includes('유형')){`,
` cb.click();await w(600);`,
` const lb=document.querySelector('[role="listbox"]');`,
` if(lb){const opt=lb.querySelector('[role="option"]');if(opt){opt.click();await w(400);}}`,
` else{document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true}));await w(200);}`,
` break;`,
` }`,
`}`,
// Click 등록 submit
`const submitBtn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='등록'&&b.offsetParent!==null);`,
`if(!submitBtn){R.error='등록 버튼 없음';return JSON.stringify(R);}`,
`submitBtn.click();await w(3000);`,
`R.urlAfter=location.pathname+location.search;`,
`R.navigatedBack=!location.search.includes('mode=new');`,
`R.ok=true;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
verifyScript: [
`(async()=>{`, HELPERS,
`const R={phase:'VERIFY_CREATE'};`,
`await w(1000);`,
`R.url=location.pathname;`,
`const rows=document.querySelectorAll('table tbody tr');`,
`R.rowCount=rows.length;`,
`const found=Array.from(rows).find(r=>r.innerText?.includes('E2E_TEST_'));`,
`R.found=!!found;`,
`if(found)R.foundText=found.innerText?.substring(0,80);`,
`R.ok=R.found;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
deleteScript: [
`(async()=>{`, HELPERS,
`const R={phase:'DELETE'};`,
`const rows=Array.from(document.querySelectorAll('table tbody tr'));`,
`const targetRow=rows.find(r=>r.innerText?.includes(ts))||rows.find(r=>r.innerText?.includes('E2E_TEST_'));`,
`if(!targetRow){R.error='E2E_TEST_ 데이터 없음';R.ok=false;return JSON.stringify(R);}`,
`R.targetText=targetRow.innerText?.substring(0,60);R.ts=ts;`,
`targetRow.click();await w(2500);`,
`R.detailUrl=location.pathname+location.search;`,
`const delBtn=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='삭제');`,
`if(!delBtn){R.error='삭제 버튼 없음';R.ok=false;return JSON.stringify(R);}`,
`delBtn.click();await w(1000);`,
`const confirmBtn=Array.from(document.querySelectorAll('[role="alertdialog"] button,[role="dialog"] button,button')).find(b=>/확인|삭제|예|Yes/.test(b.innerText?.trim())&&b!==delBtn&&b.offsetParent!==null);`,
`if(confirmBtn){confirmBtn.click();await w(3000);}`,
`R.urlAfter=location.pathname+location.search;`,
`R.ok=true;`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
verifyDeleteScript: [
`(async()=>{`, HELPERS,
`const R={phase:'VERIFY_DELETE'};`,
`await w(1000);`,
`R.url=location.pathname;`,
`if(location.search.includes('mode=view')){`,
` const backBtn=Array.from(document.querySelectorAll('button,a')).find(b=>/목록/.test(b.innerText?.trim()));`,
` if(backBtn){backBtn.click();await w(2000);}`,
` else{history.back();await w(2000);}`,
`}`,
`const rows=document.querySelectorAll('table tbody tr');`,
`R.rowCount=rows.length;`,
`const found=Array.from(rows).find(r=>r.innerText?.includes(ts));`,
`R.stillExists=!!found;`,
`R.ok=!found;R.ts=ts;`,
`if(found)R.warn='E2E_TEST_ 데이터가 여전히 존재 - 수동 삭제 필요';`,
`return JSON.stringify(R);`,
`})()`,
].join(''),
},
};
// ════════════════════════════════════════════════════════════════
// SCENARIO GENERATOR
// ════════════════════════════════════════════════════════════════
function generateScenario(pageKey) {
const page = PAGES[pageKey];
const steps = [];
let id = 1;
const p = page.menuNavigation;
const prefix = `[${p.level1} > ${p.level2}]`;
// ─── SETUP ───
steps.push({ id: id++, name: `${prefix} 페이지 로드 대기`, action: 'wait', timeout: 3000 });
steps.push({ id: id++, name: `${prefix} 테이블 로드 대기`, action: 'wait_for_table', timeout: 5000 });
// ─── CREATE PHASE ───
steps.push({
id: id++, name: `${prefix} [CREATE] 데이터 생성`,
action: 'evaluate', script: page.createScript, timeout: 30000, phase: 'CREATE',
});
// Wait for navigation back to list after form submission
steps.push({ id: id++, name: `${prefix} [CREATE] 생성 후 대기`, action: 'wait', timeout: 3000 });
// If still on form page, go back to list
steps.push({
id: id++, name: `${prefix} [CREATE] 목록 복귀`,
action: 'evaluate', timeout: 10000, phase: 'CREATE',
script: `(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));const onForm=location.search.includes('mode=new')||location.search.includes('mode=edit')||new RegExp('/(new|[0-9]+|[0-9a-f]{8,})$').test(location.pathname);if(onForm){const btn=Array.from(document.querySelectorAll('button,a')).find(b=>/목록|취소|뒤로/.test(b.innerText?.trim()));if(btn){btn.click();await w(2000);}else{history.back();await w(2000);}}return JSON.stringify({url:location.pathname+location.search});})()`,
});
steps.push({ id: id++, name: `${prefix} [CREATE] 목록 안정화 대기`, action: 'wait', timeout: 2000 });
// ─── VERIFY CREATE PHASE ───
steps.push({
id: id++, name: `${prefix} [VERIFY] 생성 데이터 확인`,
action: 'evaluate', script: page.verifyScript, timeout: 15000, phase: 'VERIFY',
});
// ─── DELETE PHASE ───
steps.push({
id: id++, name: `${prefix} [DELETE] 데이터 삭제`,
action: 'evaluate', script: page.deleteScript, timeout: 30000, phase: 'DELETE', critical: true,
});
steps.push({ id: id++, name: `${prefix} [DELETE] 삭제 후 대기`, action: 'wait', timeout: 3000 });
// Navigate back to list if stuck on detail page
steps.push({
id: id++, name: `${prefix} [DELETE] 목록 복귀`,
action: 'evaluate', timeout: 10000, phase: 'DELETE',
script: `(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));const onDetail=location.search.includes('mode=view')||location.search.includes('mode=edit')||new RegExp('/[0-9]+$|/[0-9a-f]{8,}$').test(location.pathname);if(onDetail){const btn=Array.from(document.querySelectorAll('button,a')).find(b=>/목록|뒤로/.test(b.innerText?.trim()));if(btn){btn.click();await w(2000);}else{history.back();await w(2000);}}return JSON.stringify({url:location.pathname+location.search});})()`,
});
steps.push({ id: id++, name: `${prefix} [DELETE] 목록 안정화 대기`, action: 'wait', timeout: 2000 });
// ─── VERIFY DELETE PHASE ───
steps.push({
id: id++, name: `${prefix} [VERIFY] 삭제 확인`,
action: 'evaluate', script: page.verifyDeleteScript, timeout: 15000, phase: 'VERIFY',
});
return {
id: page.id,
name: page.name,
version: '1.0.0',
auth: { role: 'admin' },
menuNavigation: page.menuNavigation,
screenshotPolicy: { captureOnFail: true, captureOnPass: false },
steps,
};
}
// ════════════════════════════════════════════════════════════════
// MAIN
// ════════════════════════════════════════════════════════════════
function main() {
if (!fs.existsSync(SCENARIOS_DIR)) {
fs.mkdirSync(SCENARIOS_DIR, { recursive: true });
}
const generated = [];
for (const key of Object.keys(PAGES)) {
const scenario = generateScenario(key);
const filePath = path.join(SCENARIOS_DIR, `${scenario.id}.json`);
fs.writeFileSync(filePath, JSON.stringify(scenario, null, 2), 'utf-8');
generated.push({ id: scenario.id, steps: scenario.steps.length });
console.log(` ${scenario.id}.json (${scenario.steps.length} steps)`);
}
console.log(`\n Generated ${generated.length} scenarios`);
console.log(`\n Run: node e2e/runner/run-all.js --filter create-delete`);
}
main();