ai 开始测试

This commit is contained in:
2025-09-01 21:51:36 +08:00
parent e20d81144d
commit 8317470fb5
7 changed files with 416 additions and 322 deletions

View File

@@ -1,4 +1,3 @@
import os
import re
import cv2
@@ -9,6 +8,7 @@ import xml.etree.ElementTree as ET
from lxml import etree
from wda import Client
# 工具类
class AiUtils(object):
@@ -17,7 +17,7 @@ class AiUtils(object):
def findImageInScreen(cls, target, udid):
try:
# 加载原始图像和模板图像
image_path = AiUtils.imagePathWithName(udid,"bgv") # 替换为你的图像路径
image_path = AiUtils.imagePathWithName(udid, "bgv") # 替换为你的图像路径
template_path = AiUtils.imagePathWithName("", target) # 替换为你的模板路径
# 读取图像和模板,确保它们都是单通道灰度图
@@ -64,7 +64,6 @@ class AiUtils(object):
return int(match.group()) # 将匹配到的数字转换为整数
return None # 如果没有找到数字,返回 None
# 选择截图
@classmethod
def screenshot(cls):
@@ -125,6 +124,7 @@ class AiUtils(object):
height, width, channels = heart_icon.shape
roi = np.zeros((height, width, channels), dtype=np.uint8)
# 将爱心图标粘贴到透明背景上
for c in range(channels):
roi[:, :, c] = np.where(mask_inv == 255, heart_icon[:, :, c], roi[:, :, c])
@@ -142,7 +142,6 @@ class AiUtils(object):
else:
print("未选择有效区域。")
# 根据名称获取图片完整地址
@classmethod
def imagePathWithName(cls, udid, name):
@@ -166,7 +165,6 @@ class AiUtils(object):
# 返回根目录
return project_root
# 创建一个以udid命名的目录
@classmethod
def makeUdidDir(cls, udid):
@@ -189,6 +187,8 @@ class AiUtils(object):
LogManager.info(f"目录 {udid_dir} 已存在,跳过创建", udid)
print(f"目录 {udid_dir} 已存在,跳过创建")
# 查找首页按钮
# uuid 设备id
# click 是否点击该按钮
@@ -209,10 +209,9 @@ class AiUtils(object):
print(e)
return None
# 查找关闭按钮
@classmethod
def findLiveCloseButton(cls,udid="eca000fcb6f55d7ed9b4c524055214c26a7de7aa"):
def findLiveCloseButton(cls, udid="eca000fcb6f55d7ed9b4c524055214c26a7de7aa"):
client = wda.USBClient(udid)
session = client.session()
session.appium_settings({"snapshotMaxDepth": 10})
@@ -277,7 +276,6 @@ class AiUtils(object):
client = wda.USBClient("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")
print(client.source())
# 查找app主页上的收件箱按钮
@classmethod
def getMsgBoxButton(cls, session: Client):
@@ -317,6 +315,7 @@ class AiUtils(object):
# 屏幕宽度
app = root.xpath('/XCUIElementTypeApplication')
screen_w = cls.parse_float(app[0], 'width', 414.0) if app else 414.0
# 找 Table 的可见范围