114 lines
3.2 KiB
Python
114 lines
3.2 KiB
Python
import tidevice
|
|
from wda import Client
|
|
|
|
from Entity.Variables import tikTokApp
|
|
from Utils.AiUtils import AiUtils
|
|
from Utils.LogManager import LogManager
|
|
|
|
# 页面控制工具类
|
|
class ControlUtils(object):
|
|
|
|
# 获取设备上的app列表
|
|
@classmethod
|
|
def getDeviceAppList(self, udid):
|
|
device = tidevice.Device(udid)
|
|
# 获取已安装的应用列表
|
|
apps = []
|
|
for app in device.installation.iter_installed():
|
|
apps.append({
|
|
"name": app.get("CFBundleDisplayName", "Unknown"),
|
|
"bundleId": app.get("CFBundleIdentifier", "Unknown"),
|
|
"version": app.get("CFBundleShortVersionString", "Unknown"),
|
|
"path": app.get("Path", "Unknown")
|
|
})
|
|
|
|
# 筛选非系统级应用(过滤掉以 com.apple 开头的系统应用)
|
|
noSystemApps = [app for app in apps if not app["bundleId"].startswith("com.apple")]
|
|
return noSystemApps
|
|
|
|
# 打开Tik Tok
|
|
@classmethod
|
|
def openTikTok(cls, session: Client, udid):
|
|
apps = cls.getDeviceAppList(udid)
|
|
tk = ""
|
|
for app in apps:
|
|
if app.get("name", "") == "TikTok":
|
|
tk = app.get("bundleId", "")
|
|
|
|
currentApp = session.app_current()
|
|
if currentApp != tk:
|
|
session.app_start(tikTokApp)
|
|
|
|
# 关闭Tik Tok
|
|
@classmethod
|
|
def closeTikTok(cls, session: Client, udid):
|
|
apps = cls.getDeviceAppList(udid)
|
|
tk = ""
|
|
for app in apps:
|
|
if app.get("name", "") == "TikTok":
|
|
tk = app.get("bundleId", "")
|
|
session.app_stop(tk)
|
|
|
|
# 返回
|
|
@classmethod
|
|
def clickBack(cls, session: Client):
|
|
x, y = AiUtils.findImageInScreen("back")
|
|
if x > 0:
|
|
r = session.swipe_right()
|
|
if r.status == 0:
|
|
return True
|
|
else:
|
|
return False
|
|
else:
|
|
print("本页面无法返回")
|
|
return False
|
|
|
|
# 点赞
|
|
@classmethod
|
|
def clickLike(cls, session: Client, udid):
|
|
scale = session.scale
|
|
x, y = AiUtils.findImageInScreen(udid,"add")
|
|
print(x,y)
|
|
if x > -1:
|
|
print("找到目标了")
|
|
r = session.click(x // scale, y // scale + 50)
|
|
if r.status == 0:
|
|
return True
|
|
else:
|
|
return False
|
|
else:
|
|
print("没有找到目标")
|
|
return False
|
|
|
|
# 点击评论
|
|
# @classmethod
|
|
# def clickComment(cls, session: Client):
|
|
# scale = session.scale
|
|
# x, y = AiUtils.findImageInScreen("add")
|
|
# print(x,y)
|
|
# if x > -1:
|
|
# print("找到目标了")
|
|
# r = session.click(x // scale, y // scale + 120)
|
|
# if r.status == 0:
|
|
# return True
|
|
# else:
|
|
# return False
|
|
# else:
|
|
# print("没有找到目标")
|
|
# return False
|
|
|
|
|
|
# 点击搜索
|
|
@classmethod
|
|
def clickSearch(cls, session: Client):
|
|
obj = session.xpath("//*[@name='搜索']")
|
|
try:
|
|
if obj.label == "搜索":
|
|
return obj
|
|
else:
|
|
return None
|
|
except Exception as e:
|
|
print(e)
|
|
return None
|
|
|