03e152baab
目录结构: tests/web/admin/ 管理端 (Playwright) tests/web/mini_program/ 司机端小程序 (Playwright/微信 WebView) tests/app/driver_android/ 司机安卓 (Appium) tests/app/shipper_android/ 货主安卓 (Appium) tests/app/driver_ios/ 司机苹果 (Appium) tests/app/shipper_ios/ 货主苹果 (Appium) 公共模块: tests/app/_shared.py driver+ensure_logged_in 工厂 tests/app/_base_page.py App Page Object 基类 配置: test_config.yaml 拆分为 6 个独立 section + 货主账号
32 lines
1000 B
Python
32 lines
1000 B
Python
"""小程序 Page Object 基类。"""
|
|
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
from playwright.sync_api import Page, Locator, expect
|
|
|
|
SCREENSHOTS_DIR = Path("output/screenshots")
|
|
|
|
|
|
class MiniProgramBasePage:
|
|
"""小程序 Page Object 基类。"""
|
|
|
|
def __init__(self, page: Page, timeout_ms: int = 30_000):
|
|
self.page = page
|
|
self.timeout = timeout_ms
|
|
|
|
def wait_visible(self, locator: Locator, timeout_ms: int | None = None) -> None:
|
|
expect(locator).to_be_visible(timeout=timeout_ms or self.timeout)
|
|
|
|
def click_when_ready(self, locator: Locator) -> None:
|
|
self.wait_visible(locator)
|
|
locator.click()
|
|
|
|
def screenshot(self, name: str) -> str:
|
|
scenario_dir = SCREENSHOTS_DIR / self.__class__.__name__
|
|
scenario_dir.mkdir(parents=True, exist_ok=True)
|
|
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
path = str(scenario_dir / f"{name}_{ts}.png")
|
|
self.page.screenshot(path=path)
|
|
return path
|