Phase 1: R.ok=true 무조건 반환 → 조건부 검증으로 교체 (36개 시나리오 영향) - gen-edge-cases.js: R.ok=R.validationTriggered, R.ok=R.allConsistent 등 - gen-pagination-sort.js: R.ok=R.sortWorked!==false - gen-search-function.js: R.ok=R.searchWorked!==false - gen-form-validation.js: R.ok=R.validationTriggered||R.hasValidation - gen-batch-create.js: R.ok=R.created!==false - gen-reload-persist.js: R.ok=R.persisted!==false - gen-detail-roundtrip.js: R.ok=R.matched!==false - gen-business-workflow.js: R.ok=!R.error&&R.phaseCompleted!==false Phase 2: rows[0] 맹목적 접근 → E2E_TEST_ 스마트 타겟팅 추가 - gen-detail-roundtrip.js, gen-business-workflow.js에 testRow 탐색 패턴 적용 결과: 184 시나리오 중 9개 정당한 FAIL 노출 (실제 버그 5건 발견) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
304 lines
18 KiB
JavaScript
304 lines
18 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 페이지 새로고침 후 데이터 유지 검증 시나리오 생성기
|
|
*
|
|
* 고객 시나리오: 데이터 등록 후 브라우저 새로고침(F5) → 데이터가 사라지면 심각한 버그.
|
|
* 서버 저장 무결성, 캐시 의존 여부, 세션 관리 검증.
|
|
*
|
|
* 흐름: CREATE → Reload Page → VERIFY → DELETE
|
|
*
|
|
* Usage: node e2e/runner/gen-reload-persist.js
|
|
*
|
|
* Output:
|
|
* e2e/scenarios/reload-persist-board.json
|
|
* e2e/scenarios/reload-persist-acc-bills.json
|
|
* e2e/scenarios/reload-persist-acc-deposit.json
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const SCENARIOS_DIR = path.resolve(__dirname, '..', 'scenarios');
|
|
|
|
const H = [
|
|
`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;try{localStorage.setItem('__E2E_TS__',ts);}catch(e){}`,
|
|
].join('');
|
|
|
|
const BACK_TO_LIST = `(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));const onForm=location.search.includes('mode=new')||location.search.includes('mode=edit')||location.search.includes('mode=view')||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});})()`;
|
|
|
|
const VERIFY_IN_LIST = [
|
|
`(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));`,
|
|
`const ts=window.__E2E_TS__||(()=>{try{return localStorage.getItem('__E2E_TS__')}catch(e){return null}})()||'E2E_TEST_';`,
|
|
`const R={phase:'VERIFY'};await w(500);`,
|
|
`const rows=document.querySelectorAll('table tbody tr');R.rowCount=rows.length;`,
|
|
`const found=Array.from(rows).find(r=>r.innerText?.includes(ts))||Array.from(rows).find(r=>r.innerText?.includes('E2E_TEST_'));`,
|
|
`R.found=!!found;R.ok=R.found;R.ts=ts;`,
|
|
`if(found)R.foundText=found.innerText?.substring(0,80);`,
|
|
`if(!found){R.error='E2E_TEST_ 데이터 없음';R.firstRow=rows[0]?.innerText?.substring(0,80)||'(empty)';}`,
|
|
`return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join('');
|
|
|
|
// ════════════════════════════════════════════════════════════════
|
|
const PAGES = {
|
|
board: {
|
|
id: 'reload-persist-board',
|
|
name: '새로고침 데이터 유지 검증: 자유게시판',
|
|
menuNavigation: { level1: '게시판', level2: '자유게시판' },
|
|
|
|
createScript: [
|
|
`(async()=>{`, H,
|
|
`const R={phase:'CREATE',ts};`,
|
|
`const testTitle='E2E_TEST_리로드_'+ts;R.testTitle=testTitle;`,
|
|
`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);`,
|
|
`const ti=document.querySelector('input[placeholder*="제목"]')||document.querySelector('input[type="text"]');`,
|
|
`if(!ti){R.error='제목 입력란 없음';return JSON.stringify(R);}`,
|
|
`sv(ti,testTitle);await w(200);`,
|
|
`const ta=document.querySelector('textarea');if(ta){sv(ta,'새로고침 후 유지되어야 하는 테스트 데이터');await w(200);}`,
|
|
`const sub=Array.from(document.querySelectorAll('button')).find(b=>b.innerText?.trim()==='등록');`,
|
|
`if(!sub){R.error='등록 버튼 없음';return JSON.stringify(R);}`,
|
|
`sub.click();await w(5000);`,
|
|
`R.urlAfter=location.pathname+location.search;`,
|
|
`R.ok=!R.urlAfter.includes('mode=new')&&!location.pathname.endsWith('/new');if(!R.ok)R.error='등록 제출 후 여전히 폼 페이지 (url='+R.urlAfter+')';`,
|
|
`return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join(''),
|
|
|
|
deleteScript: [
|
|
`(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));`,
|
|
`const ts=window.__E2E_TS__||(()=>{try{return localStorage.getItem('__E2E_TS__')}catch(e){return null}})()||'E2E_TEST_';`,
|
|
`const R={phase:'DELETE'};`,
|
|
`const rows=Array.from(document.querySelectorAll('table tbody tr'));`,
|
|
`const row=rows.find(r=>r.innerText?.includes(ts))||rows.find(r=>r.innerText?.includes('E2E_TEST_'));`,
|
|
`if(!row){R.error='E2E_TEST_ 행 없음 (ts='+ts+')';R.ok=false;return JSON.stringify(R);}`,
|
|
`R.targetText=row.innerText?.substring(0,60);`,
|
|
`row.click();await w(2500);`,
|
|
`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 cfm=Array.from(document.querySelectorAll('[role="alertdialog"] button,[role="dialog"] button,button')).find(b=>/확인|삭제|예|Yes/.test(b.innerText?.trim())&&b!==delBtn&&b.offsetParent!==null);`,
|
|
`if(cfm){cfm.click();await w(3000);}`,
|
|
`R.ok=true;return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join(''),
|
|
},
|
|
|
|
bills: {
|
|
id: 'reload-persist-acc-bills',
|
|
name: '새로고침 데이터 유지 검증: 어음관리',
|
|
menuNavigation: { level1: '회계관리', level2: '어음관리' },
|
|
|
|
createScript: [
|
|
`(async()=>{`, H,
|
|
`const R={phase:'CREATE',ts};`,
|
|
`const testId='E2E'+ts.replace(/_/g,'').substring(4,10);R.testId=testId;`,
|
|
`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 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);}`,
|
|
// 거래처 combobox (label match or index 1) — proven pattern from gen-create-delete
|
|
`const combos=Array.from(document.querySelectorAll('button[role="combobox"]')).filter(b=>b.offsetParent!==null);`,
|
|
`R.comboCount=combos.length;`,
|
|
`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);}}`,
|
|
` 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);}`,
|
|
// 날짜 선택
|
|
`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);}`,
|
|
// 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=R.navigatedBack;`,
|
|
`if(!R.ok)R.error='등록 후 여전히 폼 페이지 (url='+R.urlAfter+')';`,
|
|
`return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join(''),
|
|
|
|
deleteScript: [
|
|
`(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));`,
|
|
`const ts=window.__E2E_TS__||(()=>{try{return localStorage.getItem('__E2E_TS__')}catch(e){return null}})()||'E2E_TEST_';`,
|
|
`const R={phase:'DELETE'};`,
|
|
`const rows=Array.from(document.querySelectorAll('table tbody tr'));`,
|
|
`const row=rows.find(r=>r.innerText?.includes(ts))||rows.find(r=>r.innerText?.includes('E2E_TEST_'));`,
|
|
`if(!row){R.error='E2E_TEST_ 행 없음 (ts='+ts+')';R.ok=false;return JSON.stringify(R);}`,
|
|
`R.targetText=row.innerText?.substring(0,60);`,
|
|
`row.click();await w(2500);`,
|
|
`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 cfm=Array.from(document.querySelectorAll('[role="alertdialog"] button,[role="dialog"] button,button')).find(b=>/확인|삭제|예|Yes/.test(b.innerText?.trim())&&b!==delBtn&&b.offsetParent!==null);`,
|
|
`if(cfm){cfm.click();await w(3000);}`,
|
|
`R.ok=true;return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join(''),
|
|
},
|
|
|
|
deposit: {
|
|
id: 'reload-persist-acc-deposit',
|
|
name: '새로고침 데이터 유지 검증: 입금관리',
|
|
menuNavigation: { level1: '회계관리', level2: '입금관리' },
|
|
|
|
createScript: [
|
|
`(async()=>{`, H,
|
|
`const R={phase:'CREATE',ts};`,
|
|
`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);}`,
|
|
// 거래처 combobox (label match) — proven pattern from gen-create-delete
|
|
`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;`,
|
|
` }`,
|
|
`}`,
|
|
// 입금 유형 combobox (label match)
|
|
`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;`,
|
|
` }`,
|
|
`}`,
|
|
// 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=R.navigatedBack;`,
|
|
`if(!R.ok)R.error='등록 후 여전히 폼 페이지 (url='+R.urlAfter+')';`,
|
|
`return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join(''),
|
|
|
|
deleteScript: [
|
|
`(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));`,
|
|
`const ts=window.__E2E_TS__||(()=>{try{return localStorage.getItem('__E2E_TS__')}catch(e){return null}})()||'E2E_TEST_';`,
|
|
`const R={phase:'DELETE'};`,
|
|
`const rows=Array.from(document.querySelectorAll('table tbody tr'));`,
|
|
`const row=rows.find(r=>r.innerText?.includes(ts))||rows.find(r=>r.innerText?.includes('E2E_TEST_'));`,
|
|
`if(!row){R.error='E2E_TEST_ 행 없음 (ts='+ts+')';R.ok=false;return JSON.stringify(R);}`,
|
|
`R.targetText=row.innerText?.substring(0,60);`,
|
|
`row.click();await w(2500);`,
|
|
`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 cfm=Array.from(document.querySelectorAll('[role="alertdialog"] button,[role="dialog"] button,button')).find(b=>/확인|삭제|예|Yes/.test(b.innerText?.trim())&&b!==delBtn&&b.offsetParent!==null);`,
|
|
`if(cfm){cfm.click();await w(3000);}`,
|
|
`R.ok=true;return JSON.stringify(R);`,
|
|
`})()`,
|
|
].join(''),
|
|
},
|
|
};
|
|
|
|
// ════════════════════════════════════════════════════════════════
|
|
function generateScenario(pageKey) {
|
|
const pg = PAGES[pageKey];
|
|
const steps = [];
|
|
let id = 1;
|
|
const nav = pg.menuNavigation;
|
|
const pfx = `[${nav.level1} > ${nav.level2}]`;
|
|
|
|
// SETUP
|
|
steps.push({ id: id++, name: `${pfx} 페이지 로드 대기`, action: 'wait', timeout: 3000 });
|
|
steps.push({ id: id++, name: `${pfx} 테이블 로드 대기`, action: 'wait_for_table', timeout: 5000 });
|
|
|
|
// CREATE
|
|
steps.push({ id: id++, name: `${pfx} [CREATE] 데이터 생성`, action: 'evaluate', script: pg.createScript, timeout: 30000, phase: 'CREATE' });
|
|
steps.push({ id: id++, name: `${pfx} [CREATE] 생성 후 대기`, action: 'wait', timeout: 3000 });
|
|
steps.push({ id: id++, name: `${pfx} [CREATE] 목록 복귀`, action: 'evaluate', script: BACK_TO_LIST, timeout: 10000, phase: 'CREATE' });
|
|
steps.push({ id: id++, name: `${pfx} [CREATE] 목록 안정화`, action: 'wait', timeout: 2000 });
|
|
|
|
// VERIFY BEFORE RELOAD
|
|
steps.push({ id: id++, name: `${pfx} [VERIFY] 새로고침 전 데이터 확인`, action: 'evaluate', script: VERIFY_IN_LIST, timeout: 10000, phase: 'VERIFY' });
|
|
|
|
// ★ RELOAD PAGE — 핵심 테스트 ★
|
|
steps.push({ id: id++, name: `${pfx} [RELOAD] 페이지 새로고침`, action: 'reload', timeout: 10000 });
|
|
steps.push({ id: id++, name: `${pfx} [RELOAD] 새로고침 후 대기`, action: 'wait', timeout: 5000 });
|
|
steps.push({ id: id++, name: `${pfx} [RELOAD] SPA 안정화 대기`, action: 'wait', timeout: 5000 });
|
|
|
|
// VERIFY AFTER RELOAD — 데이터가 여전히 존재해야 함
|
|
steps.push({ id: id++, name: `${pfx} [VERIFY] 새로고침 후 데이터 유지 확인`, action: 'evaluate', script: VERIFY_IN_LIST, timeout: 10000, phase: 'VERIFY' });
|
|
|
|
// CLEANUP: DELETE
|
|
steps.push({ id: id++, name: `${pfx} [DELETE] 테스트 데이터 삭제`, action: 'evaluate', script: pg.deleteScript, timeout: 30000, phase: 'DELETE', critical: true });
|
|
steps.push({ id: id++, name: `${pfx} [DELETE] 삭제 후 대기`, action: 'wait', timeout: 3000 });
|
|
steps.push({ id: id++, name: `${pfx} [DELETE] 목록 복귀`, action: 'evaluate', script: BACK_TO_LIST, timeout: 10000, phase: 'DELETE' });
|
|
steps.push({ id: id++, name: `${pfx} [DELETE] 목록 안정화`, action: 'wait', timeout: 2000 });
|
|
|
|
// VERIFY DELETE
|
|
const VERIFY_DELETE = `(async()=>{const w=ms=>new Promise(r=>setTimeout(r,ms));const ts=window.__E2E_TS__||(()=>{try{return localStorage.getItem('__E2E_TS__')}catch(e){return null}})();const R={phase:'VERIFY_DELETE'};await w(500);const rows=document.querySelectorAll('table tbody tr');R.rowCount=rows.length;R.ts=ts||'(no ts)';if(!ts){R.ok=true;R.skipped='no ts available';return JSON.stringify(R);}const found=Array.from(rows).find(r=>r.innerText?.includes(ts));R.stillExists=!!found;R.ok=!found;if(found)R.error='삭제된 데이터(ts='+ts+')가 여전히 존재';return JSON.stringify(R);})()`;
|
|
steps.push({ id: id++, name: `${pfx} [VERIFY] 삭제 확인`, action: 'evaluate', script: VERIFY_DELETE, timeout: 10000, phase: 'VERIFY' });
|
|
|
|
return {
|
|
id: pg.id,
|
|
name: pg.name,
|
|
version: '1.0.0',
|
|
auth: { role: 'admin' },
|
|
menuNavigation: pg.menuNavigation,
|
|
screenshotPolicy: { captureOnFail: true, captureOnPass: false },
|
|
steps,
|
|
};
|
|
}
|
|
|
|
function main() {
|
|
if (!fs.existsSync(SCENARIOS_DIR)) fs.mkdirSync(SCENARIOS_DIR, { recursive: true });
|
|
for (const key of Object.keys(PAGES)) {
|
|
const scenario = generateScenario(key);
|
|
const fp = path.join(SCENARIOS_DIR, `${scenario.id}.json`);
|
|
fs.writeFileSync(fp, JSON.stringify(scenario, null, 2), 'utf-8');
|
|
console.log(` ${scenario.id}.json (${scenario.steps.length} steps)`);
|
|
}
|
|
console.log(`\n Generated ${Object.keys(PAGES).length} scenarios\n Run: node e2e/runner/run-all.js --filter reload-persist`);
|
|
}
|
|
|
|
main();
|