技术方案:基于Airtest 获取某信指定人员的聊天记录文本信息
基于
Airtest IDE 连接 夜游神模拟器 自动化UI测试_javaDB_EAD的专栏-CSDN博客
编写案例核心代码如下:
# -*- encoding=utf8 -*-
__author__ = "Administrator"
from airtest.core.api import *
auto_setup(__file__)
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
import win32con
import time
# 唤醒手机
#poco.device.wake()
keyevent("HOME")
#打开某信
poco("某信").click()
#搜过指定聊天人员
poco(text="javaDB").click()
#获取聊天内容
w,h =poco.get_screen_size()
print(poco.get_screen_size())
#double_click((120,280))
category=[]
#获取聊天内容
for answer in poco('com.tencent.mm:id/auk'):
#answer.long_click()
x, y = answer.get_position()
pos = answer.get_position()
cx = int(x * w)
cy = int(y * h)
#print('=============get_position========'+ str(pos)+'---cx:'+str(cx)+'---cy:'+str(cy))
#double_click((120,280))
double_click((cx,cy))
dao = poco("com.tencent.mm:id/dc3")
sleep(1)
if dao.exists() :
category.append(str(dao.get_text()))
print('=======get_text===================坐标cx:'+str(cx)+'---cy:'+str(cy)+'--聊天文本信息:'+str(dao.get_text()))
#os.system('pause')
answer.click()
#打印聊天文本信息
print(category)
#点击输入框
poco("com.tencent.mm:id/iki").click()
#输入发送内容
text("myPowerAI你好呀!")
try :
#发送
#poco("com.tencent.mm:id/ay5").click()
poco(text="发送").click()
except Exception:
print('exception---')
# 回到小程序首页
keyevent("BACK")
keyevent("BACK")
keyevent("BACK")
#sleep(2)
# 断言:进入的页面是否存在“个人中心”文本
#assert(poco(text="个人中心").exists())
# 关闭
stop_app("com.tencent.mm")