kdrug-inventory-system/dev_scripts/test_herb_info_ui.py
시골약사 ad9ac396e2 chore: 개발 파일 정리 및 구조화
- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동
- 스크린샷을 screenshots/ 폴더로 이동
- 백업 파일 보존 (.backup)
- 처방 관련 추가 스크립트 포함

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-18 04:44:48 +00:00

162 lines
7.4 KiB
Python

#!/usr/bin/env python3
"""Playwright를 사용한 약재 정보 페이지 UI 테스트"""
import asyncio
from playwright.async_api import async_playwright
import time
async def test_herb_info_page():
async with async_playwright() as p:
# 브라우저 시작
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
# 콘솔 메시지 캡처
console_messages = []
page.on("console", lambda msg: console_messages.append(f"{msg.type}: {msg.text}"))
# 페이지 에러 캡처
page_errors = []
page.on("pageerror", lambda err: page_errors.append(str(err)))
try:
print("=== Playwright 약재 정보 페이지 테스트 ===\n")
# 1. 메인 페이지 접속
print("1. 메인 페이지 접속...")
await page.goto("http://localhost:5001")
await page.wait_for_load_state("networkidle")
# 2. 약재 정보 메뉴 클릭
print("2. 약재 정보 메뉴 클릭...")
herb_info_link = page.locator('a[data-page="herb-info"]')
is_visible = await herb_info_link.is_visible()
print(f" - 약재 정보 메뉴 표시 여부: {is_visible}")
if is_visible:
await herb_info_link.click()
await page.wait_for_timeout(2000) # 2초 대기
# 3. herb-info 페이지 표시 확인
print("\n3. 약재 정보 페이지 요소 확인...")
herb_info_div = page.locator('#herb-info')
is_herb_info_visible = await herb_info_div.is_visible()
print(f" - herb-info div 표시: {is_herb_info_visible}")
if is_herb_info_visible:
# 검색 섹션 확인
search_section = page.locator('#herb-search-section')
is_search_visible = await search_section.is_visible()
print(f" - 검색 섹션 표시: {is_search_visible}")
# 약재 카드 그리드 확인
herb_grid = page.locator('#herbInfoGrid')
is_grid_visible = await herb_grid.is_visible()
print(f" - 약재 그리드 표시: {is_grid_visible}")
# 약재 카드 개수 확인
await page.wait_for_selector('.herb-info-card', timeout=5000)
herb_cards = await page.locator('.herb-info-card').count()
print(f" - 표시된 약재 카드 수: {herb_cards}")
if herb_cards > 0:
# 첫 번째 약재 카드 정보 확인
first_card = page.locator('.herb-info-card').first
card_title = await first_card.locator('.card-title').text_content()
print(f" - 첫 번째 약재: {card_title}")
# 카드 클릭으로 상세 보기 (카드 전체가 클릭 가능)
print("\n4. 약재 상세 정보 확인...")
# herb-info-card는 클릭 가능한 카드이므로 직접 클릭
if True:
await first_card.click()
await page.wait_for_timeout(1000)
# 상세 모달 확인
modal = page.locator('#herbDetailModal')
is_modal_visible = await modal.is_visible()
print(f" - 상세 모달 표시: {is_modal_visible}")
if is_modal_visible:
modal_title = await modal.locator('.modal-title').text_content()
print(f" - 모달 제목: {modal_title}")
# 모달 닫기
close_btn = modal.locator('button.btn-close')
if await close_btn.is_visible():
await close_btn.click()
await page.wait_for_timeout(500)
# 5. 검색 기능 테스트
print("\n5. 검색 기능 테스트...")
search_input = page.locator('#herbSearchInput')
if await search_input.is_visible():
await search_input.fill("감초")
await page.locator('#herbSearchBtn').click()
await page.wait_for_timeout(1000)
search_result_count = await page.locator('.herb-info-card').count()
print(f" - '감초' 검색 결과: {search_result_count}")
# 6. 효능별 보기 테스트
print("\n6. 효능별 보기 전환...")
efficacy_btn = page.locator('button[data-view="efficacy"]')
if await efficacy_btn.is_visible():
await efficacy_btn.click()
await page.wait_for_timeout(1000)
efficacy_section = page.locator('#herb-efficacy-section')
is_efficacy_visible = await efficacy_section.is_visible()
print(f" - 효능별 섹션 표시: {is_efficacy_visible}")
if is_efficacy_visible:
tag_buttons = await page.locator('.efficacy-tag-btn').count()
print(f" - 효능 태그 버튼 수: {tag_buttons}")
else:
print(" ⚠️ herb-info div가 표시되지 않음!")
# 디버깅: 현재 활성 페이지 확인
active_pages = await page.locator('.main-content.active').count()
print(f" - 활성 페이지 수: {active_pages}")
# 디버깅: herb-info의 display 스타일 확인
herb_info_style = await herb_info_div.get_attribute('style')
print(f" - herb-info style: {herb_info_style}")
# 디버깅: herb-info의 클래스 확인
herb_info_classes = await herb_info_div.get_attribute('class')
print(f" - herb-info classes: {herb_info_classes}")
# 7. 콘솔 에러 확인
print("\n7. 콘솔 메시지 확인...")
if console_messages:
print(" 콘솔 메시지:")
for msg in console_messages[:10]: # 처음 10개만 출력
print(f" - {msg}")
else:
print(" ✓ 콘솔 메시지 없음")
if page_errors:
print(" ⚠️ 페이지 에러:")
for err in page_errors:
print(f" - {err}")
else:
print(" ✓ 페이지 에러 없음")
# 스크린샷 저장
await page.screenshot(path="/root/kdrug/herb_info_page.png")
print("\n스크린샷 저장: /root/kdrug/herb_info_page.png")
except Exception as e:
print(f"\n❌ 테스트 실패: {e}")
# 에러 시 스크린샷
await page.screenshot(path="/root/kdrug/herb_info_error.png")
print("에러 스크린샷 저장: /root/kdrug/herb_info_error.png")
finally:
await browser.close()
if __name__ == "__main__":
print("Playwright 테스트 시작...\n")
asyncio.run(test_herb_info_page())
print("\n테스트 완료!")