"""App 登录功能测试用例。 覆盖: - (skip_login: true) 验证预登录态有效,用例直接复用已登录状态 - (skip_login: false) 完整 UI 登录流程 前置条件: 1. Appium Server 已启动: appium --log-level info 2. (推荐) 已在设备上手动登录一次,后续用例自动跳过登录 3. app.skip_login: true(默认)→ 用例通过 ensure_logged_in 检查登录态 4. app.skip_login: false → 每次执行完整 UI 登录(有验证码会失败) 标记: pytest -m app # 仅执行 App 用例 pytest -m p0 # 仅执行 P0 冒烟 pytest -m smoke # 仅执行冒烟 """ import pytest from appium.webdriver.common.appiumby import AppiumBy pytestmark = [pytest.mark.app] # ═══════════════════════════════════════════════════════════════════ # P0 — 冒烟测试(依赖手动登录后的持久化登录态) # ═══════════════════════════════════════════════════════════════════ class TestAppSmoke: """验证 App 登录态有效,核心页面可正常访问。""" @pytest.mark.p0 @pytest.mark.smoke def test_already_logged_in(self, driver, platform, ensure_logged_in): """验证 APP 已处于登录状态(手动登录后 noReset 持久化)。""" ensure_logged_in() # 主页面 tab 应可见 home_tab = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "tab_home") assert home_tab.is_displayed(), "登录后应展示首页 tab" @pytest.mark.p0 @pytest.mark.smoke def test_navigate_to_order_list(self, driver, platform, ensure_logged_in): """验证登录后可导航到运单列表。""" from tests.app.pages.driver_home_page import DriverHomePage ensure_logged_in() home = DriverHomePage(driver, platform=platform) home.go_to_order_list() # 验证运单列表可见 # ⚠️ 定位需根据实际 APP UI 调整 order_list = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "order_list") assert order_list.is_displayed(), "运单列表应可见" @pytest.mark.p0 @pytest.mark.smoke def test_tab_switching(self, driver, platform, ensure_logged_in): """验证底部 tab 可正常切换。""" from tests.app.pages.driver_home_page import DriverHomePage ensure_logged_in() home = DriverHomePage(driver, platform=platform) # 点击"我的" home.go_to_mine() # ⚠️ mine_page 的 accessibility_id 需根据实际 APP UI 确认 mine_view = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "mine_page") assert mine_view.is_displayed(), "应展示「我的」页面" # 切回首页 home.tap_by_id("tab_home") assert home.is_displayed(), "应切回首页" # ═══════════════════════════════════════════════════════════════════ # P1 — 登录页验证(仅在 skip_login: false 时有意义) # ═══════════════════════════════════════════════════════════════════ class TestAppLoginPage: """登录页基础验证。""" @pytest.mark.p1 def test_login_page_elements(self, driver, platform, app_config): """验证登录页元素存在(不执行登录)。""" # ⚠️ 前提: app 当前在登录页(未登录状态) # 如果已登录,此用例可能找不到登录页元素 from tests.app.conftest import is_logged_in # 如果已登录,跳过此用例 try: if is_logged_in: pytest.skip("APP 已登录,无法验证登录页元素") except Exception: pass # 验证登录页核心元素 try: phone_input = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login_phone_input") assert phone_input.is_displayed(), "手机号输入框应可见" password_input = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login_password_input") assert password_input.is_displayed(), "密码输入框应可见" login_btn = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login_submit_btn") assert login_btn.is_displayed(), "登录按钮应可见" except Exception: pytest.skip("登录页元素未找到,APP 可能已登录或 UI 已变更")