Files
AppAutoTest/core/base_page.py
CNWei d3f9326baa feat(driver): 新增CoreDriver基础操作,更新文档
- 优化 is_visible,支持快速状态检查。
- 新增 wait_until_visible/wait_until_not_visible 支持元素状态检查。
- 新增 clear_popups 支持弹窗清理。
- 优化 implicit_wait 状态追踪,确保等待时间恢复的准确性。
- 更新 README.md
- 其他优化
[clear_popups 采用“非阻塞探测 + 阻塞确认”策略,大幅提升清理效率并减少无效等待]
2026-01-29 18:17:49 +08:00

63 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# coding=utf-8
"""
@author: CNWei,ChenWei
@Software: PyCharm
@contact: t6g888@163.com
@file: base_page
@date: 2026/1/26 17:33
@desc:
"""
import logging
import secrets
from typing import Type, TypeVar, List, Tuple
from appium import webdriver
from selenium.common import TimeoutException
from core.driver import CoreDriver
# 定义一个泛型用于类型推断IDE 依然会有补全提示)
T = TypeVar('T', bound='BasePage')
logger = logging.getLogger(__name__)
class BasePage(CoreDriver):
def __init__(self, driver: webdriver.Remote):
super().__init__(driver)
# 定义常见弹窗的关闭按钮定位
# 这里放全局通用的 Page 属性和逻辑
# 封装一些所有页面通用的元动作
def clear_permission_popups(self):
# 普适性黑名单
_black_list = [
("id", "com.android.packageinstaller:id/permission_allow_button"),
("xpath", "//*[@text='始终允许']"),
("xpath", "//*[@text='稍后提醒']"),
("xpath", "//*[@text='以后再说']"),
("id", "com.app:id/iv_close_global_ad"),
("accessibility id", "Close"), # iOS 常用
]
self.clear_popups(_black_list)
def clear_business_ads(self):
"""在这里定义一些全 App 通用的业务广告清理"""
_ads = [("id", "com.app:id/global_ad_close")]
return self.clear_popups(_ads)
def get_toast(self, text):
return self.is_visible("text", text)
def go_to(self, page_name: Type[T]) -> T:
"""
通用的页面跳转/获取方法
:param page_name: 目标页面类
:return: 目标页面的实例
"""
logger.info(f"跳转到页面: {page_name.__name__}")
return page_name(self.driver)