ai 开始测试
This commit is contained in:
106
.idea/workspace.xml
generated
106
.idea/workspace.xml
generated
@@ -5,8 +5,17 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="ai 开始测试">
|
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="ai 开始测试">
|
||||||
|
<change afterPath="$PROJECT_DIR$/resources/bb5886c82b356593c2b3d917d578862cf0abf9c0/bgv.png" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/script/ScriptManager(20250829).py" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Module/DeviceInfo.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/DeviceInfo.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Utils/AiUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/AiUtils.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Utils/ControlUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ControlUtils.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Utils/ThreadManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/ThreadManager.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/resources/833c034d29ee6b79e1dfd88dc1d454f3da1e8a3d/bgv.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/833c034d29ee6b79e1dfd88dc1d454f3da1e8a3d/bgv.png" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/resources/eca000fcb6f55d7ed9b4c524055214c26a7de7aa/bgv.png" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/resources/fc18bc21951daf7be012a8a687b00a4de8b24c18/bgv.png" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/script/ScriptManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/script/ScriptManager.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -46,26 +55,29 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||||
"Python.123.executor": "Run",
|
"Python.123.executor": "Run",
|
||||||
"Python.Main.executor": "Run",
|
"Python.Main.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"Python.ScriptManager.executor": "Run",
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"Python.test.executor": "Run",
|
||||||
"git-widget-placeholder": "main",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"javascript.nodejs.core.library.configured.version": "22.18.0",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"javascript.nodejs.core.library.typings.version": "22.18.0",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "F:/company code/AI item/20250820/iOSAI",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"javascript.nodejs.core.library.configured.version": "20.17.0",
|
||||||
"node.js.detected.package.tslint": "true",
|
"javascript.nodejs.core.library.typings.version": "20.17.58",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"last_opened_file_path": "F:/company code/AI item/20250820/iOSAI",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.detected.package.eslint": "true",
|
||||||
"nodejs_package_manager_path": "npm",
|
"node.js.detected.package.tslint": "true",
|
||||||
"settings.editor.selected.configurable": "com.gitee.ui.GiteeSettingsConfigurable",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"settings.editor.selected.configurable": "com.gitee.ui.GiteeSettingsConfigurable",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="MoveFile.RECENT_KEYS">
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
<recent name="E:\Code\python\iOSAI\resources" />
|
<recent name="E:\Code\python\iOSAI\resources" />
|
||||||
@@ -119,8 +131,56 @@
|
|||||||
<option name="INPUT_FILE" value="" />
|
<option name="INPUT_FILE" value="" />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="ScriptManager" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="iOSAI" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/script" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/script/ScriptManager.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<option name="EMULATE_TERMINAL" value="false" />
|
||||||
|
<option name="MODULE_MODE" value="false" />
|
||||||
|
<option name="REDIRECT_INPUT" value="false" />
|
||||||
|
<option name="INPUT_FILE" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="iOSAI" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<option name="EMULATE_TERMINAL" value="false" />
|
||||||
|
<option name="MODULE_MODE" value="false" />
|
||||||
|
<option name="REDIRECT_INPUT" value="false" />
|
||||||
|
<option name="INPUT_FILE" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Python.test" />
|
||||||
|
<item itemvalue="Python.ScriptManager" />
|
||||||
<item itemvalue="Python.123" />
|
<item itemvalue="Python.123" />
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
@@ -168,6 +228,8 @@
|
|||||||
<workItem from="1756361418986" duration="7579000" />
|
<workItem from="1756361418986" duration="7579000" />
|
||||||
<workItem from="1756370074173" duration="5000" />
|
<workItem from="1756370074173" duration="5000" />
|
||||||
<workItem from="1756370506697" duration="4402000" />
|
<workItem from="1756370506697" duration="4402000" />
|
||||||
|
<workItem from="1756443992872" duration="16905000" />
|
||||||
|
<workItem from="1756465346773" duration="5806000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="ai 开始测试">
|
<task id="LOCAL-00001" summary="ai 开始测试">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -192,7 +254,9 @@
|
|||||||
<option name="LAST_COMMIT_MESSAGE" value="ai 开始测试" />
|
<option name="LAST_COMMIT_MESSAGE" value="ai 开始测试" />
|
||||||
</component>
|
</component>
|
||||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||||
<SUITE FILE_PATH="coverage/iOSAI$Main.coverage" NAME="Main Coverage Results" MODIFIED="1756378956708" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
<SUITE FILE_PATH="coverage/iOSAI$test.coverage" NAME="test 覆盖结果" MODIFIED="1756467664420" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||||
|
<SUITE FILE_PATH="coverage/iOSAI$ScriptManager.coverage" NAME="ScriptManager 覆盖结果" MODIFIED="1756455946870" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/script" />
|
||||||
|
<SUITE FILE_PATH="coverage/iOSAI$Main.coverage" NAME="Main 覆盖结果" MODIFIED="1756467704997" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||||
<SUITE FILE_PATH="coverage/iOSAI$123.coverage" NAME="123 覆盖结果" MODIFIED="1756300694280" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
<SUITE FILE_PATH="coverage/iOSAI$123.coverage" NAME="123 覆盖结果" MODIFIED="1756300694280" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -203,7 +203,7 @@ class AiUtils(object):
|
|||||||
print("1.找到了")
|
print("1.找到了")
|
||||||
return homeButton
|
return homeButton
|
||||||
else:
|
else:
|
||||||
print("没找到")
|
print("1.没找到")
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
@@ -241,23 +241,34 @@ class AiUtils(object):
|
|||||||
# 获取关注按钮
|
# 获取关注按钮
|
||||||
@classmethod
|
@classmethod
|
||||||
def getFollowButton(cls, session: Client):
|
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:
|
if followButton.exists:
|
||||||
print("2.找到了")
|
print("2.关注找到了")
|
||||||
|
LogManager.info("2.关注找到了")
|
||||||
return followButton
|
return followButton
|
||||||
else:
|
else:
|
||||||
print("没找到")
|
print("2.关注没找到")
|
||||||
|
print("2.关注没找到")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 查找发消息按钮
|
# 查找发消息按钮
|
||||||
@classmethod
|
@classmethod
|
||||||
def getSendMesageButton(cls, session: Client):
|
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:
|
if msgButton.exists:
|
||||||
print("3.找到了")
|
print("3.发消息按钮找到了")
|
||||||
|
LogManager.info("3.发消息按钮找到了")
|
||||||
return msgButton
|
return msgButton
|
||||||
else:
|
else:
|
||||||
print("没找到")
|
print("3.发消息按钮没找到")
|
||||||
|
LogManager.info("3.发消息按钮没找到")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 获取当前屏幕上的节点
|
# 获取当前屏幕上的节点
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import tidevice
|
import tidevice
|
||||||
|
import wda
|
||||||
from wda import Client
|
from wda import Client
|
||||||
from Utils.AiUtils import AiUtils
|
from Utils.AiUtils import AiUtils
|
||||||
from Utils.LogManager import LogManager
|
from Utils.LogManager import LogManager
|
||||||
@@ -81,11 +82,11 @@ class ControlUtils(object):
|
|||||||
x, y = AiUtils.findImageInScreen("add", udid)
|
x, y = AiUtils.findImageInScreen("add", udid)
|
||||||
print(x, y)
|
print(x, y)
|
||||||
if x > -1:
|
if x > -1:
|
||||||
LogManager.info("点赞了",udid)
|
LogManager.info("点赞了", udid)
|
||||||
session.click(x // scale, y // scale + 50)
|
session.click(x // scale, y // scale + 50)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
LogManager.info("没有找到目标",udid)
|
LogManager.info("没有找到目标", udid)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 点击搜索
|
# 点击搜索
|
||||||
@@ -139,3 +140,31 @@ class ControlUtils(object):
|
|||||||
else:
|
else:
|
||||||
print("没有找到主页的第一个视频")
|
print("没有找到主页的第一个视频")
|
||||||
return False, num
|
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)
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ class ThreadManager():
|
|||||||
try:
|
try:
|
||||||
info = cls.threads[udid]
|
info = cls.threads[udid]
|
||||||
if info:
|
if info:
|
||||||
info["stopEvent"].set() # 停止线程
|
info["stopEvent"].set() # 停止线程
|
||||||
info["thread"].join(timeout=3) # 等待线程退出
|
info["thread"].join(timeout=3) # 等待线程退出
|
||||||
del cls.threads[udid]
|
del cls.threads[udid]
|
||||||
LogManager.info("停止线程成功", udid)
|
LogManager.info("停止线程成功", udid)
|
||||||
return 200, "停止线程成功 " + udid
|
return 200, "停止线程成功 " + udid
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 MiB |
@@ -49,7 +49,7 @@ class ScriptManager():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ControlUtils.openTikTok(session, udid)
|
ControlUtils.openTikTok(session, udid)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
LogManager.info("养号重启tiktok")
|
LogManager.info("养号重启tiktok", udid)
|
||||||
AiUtils.makeUdidDir(udid)
|
AiUtils.makeUdidDir(udid)
|
||||||
|
|
||||||
# ========= 主循环 =========
|
# ========= 主循环 =========
|
||||||
@@ -183,7 +183,6 @@ class ScriptManager():
|
|||||||
if live_button.exists:
|
if live_button.exists:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# 下滑一下
|
# 下滑一下
|
||||||
client.swipe_up()
|
client.swipe_up()
|
||||||
|
|
||||||
@@ -479,6 +478,7 @@ class ScriptManager():
|
|||||||
|
|
||||||
# 关注打招呼以及回复主播消息
|
# 关注打招呼以及回复主播消息
|
||||||
def greetNewFollowers(self, udid, needReply, event):
|
def greetNewFollowers(self, udid, needReply, event):
|
||||||
|
|
||||||
client = wda.USBClient(udid)
|
client = wda.USBClient(udid)
|
||||||
session = client.session()
|
session = client.session()
|
||||||
print(f"是否要自动回复消息:{needReply}")
|
print(f"是否要自动回复消息:{needReply}")
|
||||||
@@ -536,24 +536,8 @@ class ScriptManager():
|
|||||||
session.appium_settings({"snapshotMaxDepth": 23})
|
session.appium_settings({"snapshotMaxDepth": 23})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# 点击关注按钮
|
||||||
# 查找“关注”按钮
|
ControlUtils.clickFollow(session, aid)
|
||||||
follow_btn = session.xpath(
|
|
||||||
'//XCUIElementTypeButton[@name="关注" or @name="Follow" or @name="已关注" or @name="Following"]').get(
|
|
||||||
timeout=5)
|
|
||||||
|
|
||||||
# 获取按钮位置和大小
|
|
||||||
rect = follow_btn.bounds
|
|
||||||
left_x = max(1, rect.x - 20) # 向左偏移 20px,确保不会点到屏幕外
|
|
||||||
center_y = rect.y + rect.height // 2
|
|
||||||
|
|
||||||
# 打印调试信息
|
|
||||||
print(f"关注按钮位置 x={rect.x}, y={rect.y}, width={rect.width}, height={rect.height}")
|
|
||||||
print(f"即将点击的位置 x={left_x}, y={center_y}")
|
|
||||||
|
|
||||||
# 点击关注按钮左侧区域(通常是头像)
|
|
||||||
session.tap(left_x, center_y)
|
|
||||||
|
|
||||||
except wda.WDAElementNotFoundError:
|
except wda.WDAElementNotFoundError:
|
||||||
# 如果没有“关注”按钮,则不点击
|
# 如果没有“关注”按钮,则不点击
|
||||||
print("未找到‘关注’按钮,跳过点击。")
|
print("未找到‘关注’按钮,跳过点击。")
|
||||||
@@ -596,6 +580,7 @@ class ScriptManager():
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
# 查找add图标
|
# 查找add图标
|
||||||
r = ControlUtils.clickLike(session, udid)
|
r = ControlUtils.clickLike(session, udid)
|
||||||
|
|
||||||
# 点赞成功。
|
# 点赞成功。
|
||||||
# if r == True:
|
# if r == True:
|
||||||
|
|
||||||
@@ -628,8 +613,8 @@ class ScriptManager():
|
|||||||
followButton.click()
|
followButton.click()
|
||||||
else:
|
else:
|
||||||
LogManager.info("没找到关注按钮", udid)
|
LogManager.info("没找到关注按钮", udid)
|
||||||
removeModelFromAnchorList(anchor)
|
|
||||||
goBack(3)
|
goBack(3)
|
||||||
|
session.appium_settings({"snapshotMaxDepth": 15})
|
||||||
continue
|
continue
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@@ -641,8 +626,8 @@ class ScriptManager():
|
|||||||
msgButton.click()
|
msgButton.click()
|
||||||
else:
|
else:
|
||||||
print("没有识别出发消息按钮")
|
print("没有识别出发消息按钮")
|
||||||
removeModelFromAnchorList(anchor)
|
|
||||||
goBack(3)
|
goBack(3)
|
||||||
|
session.appium_settings({"snapshotMaxDepth": 15})
|
||||||
continue
|
continue
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -666,6 +651,8 @@ class ScriptManager():
|
|||||||
|
|
||||||
# 接着下一个主播
|
# 接着下一个主播
|
||||||
# removeModelFromAnchorList(anchor)
|
# removeModelFromAnchorList(anchor)
|
||||||
|
session.appium_settings({"snapshotMaxDepth": 15})
|
||||||
|
|
||||||
goBack(4)
|
goBack(4)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -697,6 +684,7 @@ class ScriptManager():
|
|||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
print("重新创建wda会话 防止wda会话失效")
|
print("重新创建wda会话 防止wda会话失效")
|
||||||
|
|
||||||
client = wda.USBClient(udid)
|
client = wda.USBClient(udid)
|
||||||
session = client.session()
|
session = client.session()
|
||||||
|
|
||||||
@@ -738,9 +726,8 @@ class ScriptManager():
|
|||||||
|
|
||||||
# 调整节点的深度为 7
|
# 调整节点的深度为 7
|
||||||
session.appium_settings({"snapshotMaxDepth": 7})
|
session.appium_settings({"snapshotMaxDepth": 7})
|
||||||
el = session(xpath='//XCUIElementTypeButton[@name="a11y_vo_inbox"]')
|
|
||||||
|
|
||||||
print(111111111111111111111111)
|
el = session(xpath='//XCUIElementTypeButton[@name="a11y_vo_inbox"]')
|
||||||
|
|
||||||
# 如果收件箱有消息 则进行点击
|
# 如果收件箱有消息 则进行点击
|
||||||
if el.exists:
|
if el.exists:
|
||||||
@@ -751,7 +738,6 @@ class ScriptManager():
|
|||||||
session.appium_settings({"snapshotMaxDepth": 25})
|
session.appium_settings({"snapshotMaxDepth": 25})
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
info_count = 0
|
info_count = 0
|
||||||
|
|
||||||
# 创建新的会话
|
# 创建新的会话
|
||||||
@@ -776,7 +762,6 @@ class ScriptManager():
|
|||||||
LogManager.error(f"当前页面不再收件箱页面,重启", udid)
|
LogManager.error(f"当前页面不再收件箱页面,重启", udid)
|
||||||
raise Exception("当前页面不再收件箱页面,重启")
|
raise Exception("当前页面不再收件箱页面,重启")
|
||||||
|
|
||||||
print(3333333333333333333333333333333)
|
|
||||||
m = re.search(r'(\d+)', el.label) # 抓到的第一个数字串
|
m = re.search(r'(\d+)', el.label) # 抓到的第一个数字串
|
||||||
count = int(m.group(1)) if m else 0
|
count = int(m.group(1)) if m else 0
|
||||||
|
|
||||||
@@ -818,7 +803,70 @@ class ScriptManager():
|
|||||||
']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
|
']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
|
||||||
)
|
)
|
||||||
|
|
||||||
print(44444444444444444444444444444444)
|
try:
|
||||||
|
# 如果 2 秒内找不到,会抛异常
|
||||||
|
user_text = session.xpath(xp_badge_numeric).get(timeout=2.0)
|
||||||
|
val = (user_text.info.get("value") or
|
||||||
|
user_text.info.get("label") or
|
||||||
|
user_text.info.get("name"))
|
||||||
|
LogManager.info(f"用户未读数量:{val}", udid)
|
||||||
|
except Exception:
|
||||||
|
LogManager.warning("当前屏幕没有找到 用户 未读徽标数字", udid)
|
||||||
|
print("当前屏幕没有找到 用户消息 未读徽标数字", udid)
|
||||||
|
user_text = None
|
||||||
|
info_count += 1
|
||||||
|
|
||||||
|
if user_text:
|
||||||
|
user_text.tap()
|
||||||
|
time.sleep(3)
|
||||||
|
xml = session.source()
|
||||||
|
msgs = AiUtils.extract_messages_from_xml(xml)
|
||||||
|
# 检测出对方发的最后一条信息
|
||||||
|
last_msg_text = next(item['text'] for item in reversed(msgs) if item['type'] == 'msg')
|
||||||
|
# 向ai发送信息
|
||||||
|
|
||||||
|
# 获取主播的名称
|
||||||
|
anchor_name = AiUtils.get_navbar_anchor_name(session)
|
||||||
|
|
||||||
|
# 找到输入框
|
||||||
|
|
||||||
|
sel = session.xpath("//TextView")
|
||||||
|
|
||||||
|
if anchor_name not in anchorWithSession:
|
||||||
|
# 如果是第一次发消息(没有sessionId的情况)
|
||||||
|
response = Requester.chatToAi({"msg": last_msg_text})
|
||||||
|
aiResult = response['result']
|
||||||
|
sessionId = response['session_id']
|
||||||
|
|
||||||
|
anchorWithSession[anchor_name] = sessionId
|
||||||
|
# 找到输入框,输入ai返回出来的消息
|
||||||
|
if sel.exists:
|
||||||
|
sel.click() # 聚焦
|
||||||
|
time.sleep(1)
|
||||||
|
sel.clear_text()
|
||||||
|
sel.set_text(aiResult + "\n")
|
||||||
|
else:
|
||||||
|
LogManager.error("找不到输入框,重启", udid)
|
||||||
|
raise Exception("找不到输入框,重启")
|
||||||
|
else:
|
||||||
|
# 如果不是第一次发消息(证明存储的有sessionId)
|
||||||
|
sessionId = anchorWithSession[anchor_name]
|
||||||
|
response = Requester.chatToAi({"msg": last_msg_text, "sid": sessionId})
|
||||||
|
aiResult = response['result']
|
||||||
|
if sel.exists:
|
||||||
|
sel.click() # 聚焦
|
||||||
|
time.sleep(1)
|
||||||
|
sel.clear_text()
|
||||||
|
sel.set_text(aiResult + "\n")
|
||||||
|
|
||||||
|
LogManager.info(f"存储的sessionId:{anchorWithSession}", udid)
|
||||||
|
time.sleep(1)
|
||||||
|
# 返回
|
||||||
|
ControlUtils.clickBack(session)
|
||||||
|
|
||||||
|
# 重新回到收件箱页面后,强制刷新节点
|
||||||
|
session.appium_settings({"snapshotMaxDepth": 25})
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 如果 2 秒内找不到,会抛异常
|
# 如果 2 秒内找不到,会抛异常
|
||||||
@@ -894,71 +942,6 @@ class ScriptManager():
|
|||||||
badge_text = None
|
badge_text = None
|
||||||
info_count += 1
|
info_count += 1
|
||||||
|
|
||||||
try:
|
|
||||||
# 如果 2 秒内找不到,会抛异常
|
|
||||||
user_text = session.xpath(xp_badge_numeric).get(timeout=2.0)
|
|
||||||
val = (user_text.info.get("value") or
|
|
||||||
user_text.info.get("label") or
|
|
||||||
user_text.info.get("name"))
|
|
||||||
LogManager.info(f"用户未读数量:{val}", udid)
|
|
||||||
except Exception:
|
|
||||||
LogManager.warning("当前屏幕没有找到 用户 未读徽标数字", udid)
|
|
||||||
print("当前屏幕没有找到 用户消息 未读徽标数字", udid)
|
|
||||||
user_text = None
|
|
||||||
info_count += 1
|
|
||||||
|
|
||||||
if user_text:
|
|
||||||
user_text.tap()
|
|
||||||
time.sleep(3)
|
|
||||||
xml = session.source()
|
|
||||||
msgs = AiUtils.extract_messages_from_xml(xml)
|
|
||||||
# 检测出对方发的最后一条信息
|
|
||||||
last_msg_text = next(item['text'] for item in reversed(msgs) if item['type'] == 'msg')
|
|
||||||
# 向ai发送信息
|
|
||||||
|
|
||||||
# 获取主播的名称
|
|
||||||
anchor_name = AiUtils.get_navbar_anchor_name(session)
|
|
||||||
|
|
||||||
# 找到输入框
|
|
||||||
|
|
||||||
sel = session.xpath("//TextView")
|
|
||||||
|
|
||||||
if anchor_name not in anchorWithSession:
|
|
||||||
# 如果是第一次发消息(没有sessionId的情况)
|
|
||||||
response = Requester.chatToAi({"msg": last_msg_text})
|
|
||||||
aiResult = response['result']
|
|
||||||
sessionId = response['session_id']
|
|
||||||
|
|
||||||
anchorWithSession[anchor_name] = sessionId
|
|
||||||
# 找到输入框,输入ai返回出来的消息
|
|
||||||
if sel.exists:
|
|
||||||
sel.click() # 聚焦
|
|
||||||
time.sleep(1)
|
|
||||||
sel.clear_text()
|
|
||||||
sel.set_text(aiResult + "\n")
|
|
||||||
else:
|
|
||||||
LogManager.error("找不到输入框,重启", udid)
|
|
||||||
raise Exception("找不到输入框,重启")
|
|
||||||
else:
|
|
||||||
# 如果不是第一次发消息(证明存储的有sessionId)
|
|
||||||
sessionId = anchorWithSession[anchor_name]
|
|
||||||
response = Requester.chatToAi({"msg": last_msg_text, "sid": sessionId})
|
|
||||||
aiResult = response['result']
|
|
||||||
if sel.exists:
|
|
||||||
sel.click() # 聚焦
|
|
||||||
time.sleep(1)
|
|
||||||
sel.clear_text()
|
|
||||||
sel.set_text(aiResult + "\n")
|
|
||||||
|
|
||||||
LogManager.info(f"存储的sessionId:{anchorWithSession}", udid)
|
|
||||||
time.sleep(1)
|
|
||||||
# 返回
|
|
||||||
ControlUtils.clickBack(session)
|
|
||||||
|
|
||||||
# 重新回到收件箱页面后,强制刷新节点
|
|
||||||
session.appium_settings({"snapshotMaxDepth": 25})
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
# 双击收件箱 定位到消息的位置
|
# 双击收件箱 定位到消息的位置
|
||||||
if info_count == 5:
|
if info_count == 5:
|
||||||
r = el.bounds # 可能是命名属性,也可能是 tuple
|
r = el.bounds # 可能是命名属性,也可能是 tuple
|
||||||
@@ -966,9 +949,9 @@ class ScriptManager():
|
|||||||
cy = int((r.y + r.height / 2) if hasattr(r, "y") else (r[1] + r[3] / 2))
|
cy = int((r.y + r.height / 2) if hasattr(r, "y") else (r[1] + r[3] / 2))
|
||||||
session.double_tap(cx, cy) # 可能抛异常:方法不存在
|
session.double_tap(cx, cy) # 可能抛异常:方法不存在
|
||||||
LogManager.info(f"双击收件箱 定位到信息", udid)
|
LogManager.info(f"双击收件箱 定位到信息", udid)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
LogManager.error(f"检测不到收件箱", udid)
|
LogManager.error(f"检测不到收件箱", udid)
|
||||||
raise Exception("当前页面找不到收件箱,重启")
|
raise Exception("当前页面找不到收件箱,重启")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user