- internal_code DB 저장 → 프론트에서 선택한 제품 그대로 주문 - 기존 장바구니 백업/복구로 사용자 장바구니 보존 - 수인약품 submit_order() 수정 (체크박스 제외 방식) - 테스트 파일 정리 및 문서 추가
123 lines
4.5 KiB
Python
123 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""rx-usage 페이지 Playwright 테스트"""
|
|
from playwright.sync_api import sync_playwright
|
|
import time
|
|
import json
|
|
|
|
def test_rx_usage_quick_order():
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=False) # 화면 보이게
|
|
page = browser.new_page()
|
|
|
|
# 콘솔 로그 캡처
|
|
page.on("console", lambda msg: print(f"[CONSOLE] {msg.type}: {msg.text}"))
|
|
|
|
# 네트워크 요청/응답 캡처
|
|
def log_response(response):
|
|
if 'api/order' in response.url or 'quick-submit' in response.url:
|
|
print(f"\n[RESPONSE] {response.url}")
|
|
print(f" Status: {response.status}")
|
|
try:
|
|
body = response.json()
|
|
print(f" Body: {json.dumps(body, ensure_ascii=False, indent=2)}")
|
|
except:
|
|
print(f" Body: {response.text()[:500]}")
|
|
|
|
page.on("response", log_response)
|
|
|
|
print("="*60)
|
|
print("1. rx-usage 페이지 접속")
|
|
print("="*60)
|
|
page.goto("http://localhost:7001/admin/rx-usage")
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(2)
|
|
|
|
print("\n" + "="*60)
|
|
print("2. 데이터 로드 (조회 버튼 클릭)")
|
|
print("="*60)
|
|
# 조회 버튼 클릭
|
|
search_btn = page.locator("button:has-text('조회')")
|
|
if search_btn.count() > 0:
|
|
search_btn.first.click()
|
|
time.sleep(3)
|
|
|
|
print("\n" + "="*60)
|
|
print("3. 첫 번째 품목 행 더블클릭 (도매상 모달 열기)")
|
|
print("="*60)
|
|
# 테이블 행 찾기
|
|
rows = page.locator("tr[data-idx]")
|
|
row_count = rows.count()
|
|
print(f" 품목 수: {row_count}")
|
|
|
|
if row_count > 0:
|
|
# 첫 번째 품목 더블클릭
|
|
rows.first.dblclick()
|
|
time.sleep(3)
|
|
|
|
print("\n" + "="*60)
|
|
print("4. 도매상 모달에서 지오영 품목 확인")
|
|
print("="*60)
|
|
|
|
# 지오영 테이블에서 재고 있는 품목 찾기
|
|
geo_rows = page.locator(".geo-table tbody tr:not(.no-stock)")
|
|
geo_count = geo_rows.count()
|
|
print(f" 지오영 재고 있는 품목: {geo_count}개")
|
|
|
|
if geo_count > 0:
|
|
# 첫 번째 품목 정보 출력
|
|
first_row = geo_rows.first
|
|
product_name = first_row.locator(".geo-name").text_content()
|
|
stock = first_row.locator(".geo-stock").text_content()
|
|
print(f" 선택할 품목: {product_name}, 재고: {stock}")
|
|
|
|
print("\n" + "="*60)
|
|
print("5. '담기' 버튼 클릭")
|
|
print("="*60)
|
|
add_btn = first_row.locator("button.geo-add-btn")
|
|
if add_btn.count() > 0:
|
|
add_btn.click()
|
|
time.sleep(1)
|
|
|
|
# prompt 창에 수량 입력 (기본값 사용)
|
|
page.on("dialog", lambda dialog: dialog.accept())
|
|
time.sleep(2)
|
|
|
|
print("\n" + "="*60)
|
|
print("6. 장바구니 확인")
|
|
print("="*60)
|
|
cart_items = page.locator(".cart-item")
|
|
cart_count = cart_items.count()
|
|
print(f" 장바구니 품목: {cart_count}개")
|
|
|
|
if cart_count > 0:
|
|
print("\n" + "="*60)
|
|
print("7. 퀵주문 버튼 클릭!")
|
|
print("="*60)
|
|
|
|
# 퀵주문 버튼 찾기
|
|
quick_order_btn = page.locator("button.cart-item-order").first
|
|
if quick_order_btn.count() > 0:
|
|
quick_order_btn.click()
|
|
time.sleep(1)
|
|
|
|
# confirm 대화상자 수락
|
|
page.on("dialog", lambda dialog: dialog.accept())
|
|
time.sleep(5)
|
|
|
|
print("\n" + "="*60)
|
|
print("8. 결과 확인")
|
|
print("="*60)
|
|
|
|
# 토스트 메시지 확인
|
|
toast = page.locator(".toast")
|
|
if toast.count() > 0:
|
|
toast_text = toast.text_content()
|
|
print(f" 토스트 메시지: {toast_text}")
|
|
|
|
print("\n테스트 완료. 10초 후 브라우저 닫힘...")
|
|
time.sleep(10)
|
|
browser.close()
|
|
|
|
if __name__ == "__main__":
|
|
test_rx_usage_quick_order()
|