ai 开始测试

This commit is contained in:
2025-08-29 20:48:33 +08:00
parent 3fcd72bfd5
commit b75c517488
8 changed files with 213 additions and 126 deletions

View File

@@ -203,7 +203,7 @@ class AiUtils(object):
print("1.找到了")
return homeButton
else:
print("没找到")
print("1.没找到")
return None
except Exception as e:
print(e)
@@ -241,23 +241,34 @@ class AiUtils(object):
# 获取关注按钮
@classmethod
def getFollowButton(cls, session: Client):
followButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]/Button[1]")
# followButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]/Button[1]")
followButton = session.xpath(
'//XCUIElementTypeOther[@name="cta_social_interaction"]//XCUIElementTypeButton[@name="关注"]')
if followButton.exists:
print("2.找到了")
print("2.关注找到了")
LogManager.info("2.关注找到了")
return followButton
else:
print("没找到")
print("2.关注没找到")
print("2.关注没找到")
return None
# 查找发消息按钮
@classmethod
def getSendMesageButton(cls, session: Client):
msgButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]")
# msgButton = session.xpath("//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[2]/Other[2]/Other[1]/Other[1]/Other[3]/Other[1]/Other[1]")
msgButton = session.xpath(
'//XCUIElementTypeOther[@name="cta_social_interaction"]//XCUIElementTypeButton[@name="发消息"]')
if msgButton.exists:
print("3.找到了")
print("3.发消息按钮找到了")
LogManager.info("3.发消息按钮找到了")
return msgButton
else:
print("没找到")
print("3.发消息按钮没找到")
LogManager.info("3.发消息按钮没找到")
return None
# 获取当前屏幕上的节点

View File

@@ -1,6 +1,7 @@
import re
import tidevice
import wda
from wda import Client
from Utils.AiUtils import AiUtils
from Utils.LogManager import LogManager
@@ -81,11 +82,11 @@ class ControlUtils(object):
x, y = AiUtils.findImageInScreen("add", udid)
print(x, y)
if x > -1:
LogManager.info("点赞了",udid)
LogManager.info("点赞了", udid)
session.click(x // scale, y // scale + 50)
return True
else:
LogManager.info("没有找到目标",udid)
LogManager.info("没有找到目标", udid)
return False
# 点击搜索
@@ -139,3 +140,31 @@ class ControlUtils(object):
else:
print("没有找到主页的第一个视频")
return False, num
@classmethod
def clickFollow(cls, session, aid):
# 1) 含“关注/已关注/Follow/Following”的首个 cell
cell_xpath = (
'(//XCUIElementTypeCollectionView[@name="TTKSearchCollectionComponent"]'
'//XCUIElementTypeCell[.//XCUIElementTypeButton[@name="关注" or @name="Follow" or @name="已关注" or @name="Following"]])[1]'
)
cell = session.xpath(cell_xpath).get(timeout=5)
# 2) 先试“用户信息 Button”label/name 里包含 aid
profile_btn_xpath = (
f'{cell_xpath}//XCUIElementTypeButton[contains(@label, "{aid}") or contains(@name, "{aid}")]'
)
try:
profile_btn = session.xpath(profile_btn_xpath).get(timeout=3)
profile_btn.click()
except wda.WDAElementNotFoundError:
# 3) 兜底:用“关注”按钮做锚点,向左偏移点击头像/用户名区域
follow_btn_xpath = (
f'{cell_xpath}//XCUIElementTypeButton[@name="关注" or @name="Follow" or @name="已关注" or @name="Following"]'
)
follow_btn = session.xpath(follow_btn_xpath).get(timeout=5)
rect = follow_btn.bounds
left_x = max(1, rect.x - 20)
center_y = rect.y + rect.height // 2
session.tap(left_x, center_y)

View File

@@ -20,8 +20,8 @@ class ThreadManager():
try:
info = cls.threads[udid]
if info:
info["stopEvent"].set() # 停止线程
info["thread"].join(timeout=3) # 等待线程退出
info["stopEvent"].set() # 停止线程
info["thread"].join(timeout=3) # 等待线程退出
del cls.threads[udid]
LogManager.info("停止线程成功", udid)
return 200, "停止线程成功 " + udid
@@ -30,4 +30,4 @@ class ThreadManager():
return 1001, "无此线程,无需关闭 " + udid
except KeyError as e:
LogManager.info("无此线程,无需关闭", udid)
return 1001, "停止脚本失败 " + udid
return 1001, "停止脚本失败 " + udid