环境准备:
Android sdk下载及环境变量的配置
python下载及环境变量的配置
monkeymaxim开源工具
遇到的问题:
1、在自己mac上手机连接adb非常好使,放在公司win7机器上死活连不上,因为不同的手机需要不同版本的adb interface驱动,所以需要驱动精灵把缺的adb interface都装上,这样就能解决连接不上的问题。
2、注意windows跟mac的终端命令的差异化。
大体思路:
先通过adb devices 查到所有的已连接设备,然后把所有的设备进行遍历,每个设备进行测试工具必要文件的推送及app的安装。
跑mankye也是通过遍历每台手机,对每台手机执行monkey命令,程序进行一个delay,执行完所有的手机mokey后,把每台手机里的logcat日志进行一个过滤提取,指定到以设备名为名称的文本中。
在log文件所在的文件目录中起一个python的http服务,记得关闭电脑的防火墙,这个服务在局域网内是可以通过局域网ip访问到的,端口为8000。
最后就是把兼容性测试的机器及log访问的地址通过webhook推送到钉钉。
'''
# @author_='zhimeng';
# @time: 2020-12-15 14:50
# @File: adb_monkey.py
# @Email: '1099182107@qq.com'
'''
import json
import os
import time
import requests
import socket
IP = socket.gethostbyname_ex(socket.gethostname())[-1][0]
ip = 'http://' + IP + ':8000'
PHONE = {"5539ca7d":"小米-8-9","3XU9X17308G11839":"华为-畅享6s-6.0","ffec9021":"vivo-x20-8.1","8BNDU17526007313":"华为-荣耀9-8","f0329939":"oppo","bbd7bf6e":"小米-6-9"}
file_name = os.path.dirname(os.path.realpath(__file__))
log_path = file_name+'/log'
devices = os.popen('adb devices').readlines()
apk_path = r'{0}\app-bitz-produce-release_340_jiagu_zip_sign_normal.apk'.format(file_name)
def installApp():
# os.chdir('D:\monkeymaxim')
for i in devices[1:-1]: #推送必要monkeymaxim文件到手机及安装apk
device = i.split('\t')[0]
os.popen('adb -s {0} push framework.jar monkey.jar max.xpath.selector max.config /sdcard'.format(device))
os.popen('adb -s {0} install {1}'.format(device,apk_path))
def run_monkey(how_long):
device_list = []
phoneModle = []
for i in devices[1:-1]:
device = i.split('\t')[0]
device_list.append(device)
os.popen('adb -s {0} shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p com.xinlian.bitz --uiautomatortroy --running-minutes {1} -v -v'.format(device,how_long))
delay_time = (how_long+1)*60
time.sleep(delay_time)
for i in devices[1:-1]:
device = i.split('\t')[0]
if device in PHONE:
os.popen('adb -s {0} logcat -b crash -d|find "xinlian" > {1}/{2}.log'.format(device,log_path,PHONE[device]))
phoneModle.append(PHONE[device])
else:
os.popen('adb -s {0} logcat -b crash -d|find "xinlian > {1}/{2}.log'.format(device,log_path,device))
phoneModle.append(device)
phoneNum = len(device_list)
os.chdir(file_name)
msg = '### android兼容性测试,本次兼容到{0}部手机,涉及机型有{1},请前往[{2}]({3})查看本次的崩溃日志'.format(phoneNum,phoneModle,ip,ip)
dingding(msg)
os.system('python -m http.server')
def dingding(msg):
headers = {'Content-Type': 'application/json;charset=utf-8'}
data = {
"msgtype": "markdown",
"at":
{
"atMobiles": [
],
"isAtAll": False,
},
"markdown":
{
"text": msg,
"title": "android兼容性测试",
}
}
url = 'https://oapi.dingtalk.com/robot/send?access_token=XXXXXXX'
r = requests.post(url, data=json.dumps(data), headers=headers)
run_monkey(1)
# installApp()
网友评论