Files
AppAutoTest/page_objects/wan_android_home.py
CNWei a8d0b75dd9 feat(driver): 增加元素高亮截图功能并重构截图矩阵
- 新增 `_get_highlighted_image` 核心逻辑,支持自动缩放 (Scale) 适配。
- 新增 `get_highlight_screenshot_as_file/bytes` 接口,支持诊断级高亮截图。
- 重构 `get_screenshot_as_file/bytes` 统一命名规范。
- 引入 `ImagePath` 与 `ImageBytes` 类型别名,增强代码语义化。
- 优化内存管理,使用 `io.BytesIO` 与 `img.load()` 确保在高频截图下的稳定性。
2026-03-03 17:46:03 +08:00

67 lines
2.2 KiB
Python

#!/usr/bin/env python
# coding=utf-8
"""
@author: CNWei,ChenWei
@Software: PyCharm
@contact: t6g888@163.com
@file: wan_android_home
@date: 2026/1/30 17:18
@desc:
"""
import logging
import allure
from appium import webdriver
from core.base_page import BasePage
logger = logging.getLogger(__name__)
class HomePage(BasePage):
# 定位参数
menu = ("accessibility id", "开启")
home = ("id", 'com.manu.wanandroid:id/largeLabel')
project = ("-android uiautomator", 'new UiSelector().text("项目")')
system = ("-android uiautomator", 'new UiSelector().text("体系")')
tv_name = ("id", "com.manu.wanandroid:id/tvName")
account = ("-android uiautomator", 'new UiSelector().text("账号")')
pass_word = ("-android uiautomator", 'new UiSelector().text("密码")')
login_button = ("accessibility id", '登录')
def __init__(self, driver: webdriver.Remote):
super().__init__(driver)
@allure.step("点击 “侧边栏”")
def click_open(self):
if self.wait_until_visible(*self.menu, timeout=1):
self.click(*self.menu)
self.attach_screenshot_bytes("侧边栏截图")
with allure.step("准备登录"):
self.click(*self.tv_name)
@allure.step("登录账号:{1}")
def login(self, username, password):
"""执行登录业务逻辑"""
account_element_id = self.find_element(*self.account).id
account_input = {"elementId": account_element_id, "text": username}
pwd_element_id = self.find_element(*self.pass_word).id
pass_word_input = {"elementId": pwd_element_id, "text": password}
if self.wait_until_visible(*self.login_button):
self.click(*self.account).driver.execute_script('mobile: type', account_input)
self.click(*self.pass_word).driver.execute_script('mobile: type', pass_word_input)
self.click(*self.login_button)
if self.wait_until_visible(*self.tv_name):
self.get_screenshot_as_file("登陆成功")
self.get_highlight_screenshot_as_file(*self.tv_name, "登陆成功-高亮")
self.get_element_screenshot_as_file(*self.tv_name)
self.long_press(x=636, y=117, duration=300)