Files
2026-05-13 18:07:36 +08:00

63 lines
2.3 KiB
Python

from pathlib import Path
import re
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("App下载")
@allure.story("下载页内容")
@allure.title("校验 App 下载页核心内容和下载入口可见")
def test_app_page_key_content_and_download_links_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 Download the App 页面")
page.goto("/app", wait_until="domcontentloaded")
logger.info("校验 App 下载页地址和页面已加载")
expect(page).to_have_url(re.compile(r".*/app/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
logger.info("动态校验下载入口展示,不绑定具体版本文案")
download_links = page.locator('section main a[href]')
expect(download_links.first).to_be_visible(timeout=settings.default_timeout)
download_link_count = download_links.count()
logger.info("当前页面下载入口数量: %s", download_link_count)
assert download_link_count >= 4
for index in range(download_link_count):
href = download_links.nth(index).get_attribute("href")
logger.info("当前下载入口 href: %s", href)
assert href is not None
@allure.feature("App下载")
@allure.story("下载说明")
@allure.title("校验 App 下载页 How to Download APK 按钮可见")
def test_app_page_how_to_download_apk_button_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 Download the App 页面")
page.goto("/app", wait_until="domcontentloaded")
logger.info("动态校验下载说明按钮可见,不绑定按钮文案")
how_to_download_button = page.locator("section main button").first
expect(how_to_download_button).to_be_visible(timeout=settings.default_timeout)
expect(how_to_download_button).to_be_enabled(timeout=settings.default_timeout)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))