开源测试工具 FastMonkey Jenkins 部署及测试结果 web 展示

lemon · 2018年04月03日 · 最后由 lei 回复于 2019年09月11日 · 342 次阅读

1228 新增内容

1.自动获取真机设备名及 duid
2.iOS crashreport 解析优化及测试结果 DB 存储
3.测试失败邮件通知
4.Web 页面结果展示及支持 crash log 下载

设备列表

测试包详情

测试报告

结果展示

1.环境

Mac mini:10.12.6
xcode:9.2
python:python3.6

2.备注

a.FastMonkey 相关问题参照@zhangzhao_lenovo 大神的帖子:https://testerhome.com/topics/9524,此处不再赘述!
b.相关扫盲贴:
*https://testerhome.com/topics/9810

*http://cdn2.jianshu.io/p/2cbdb50411ae
c.ios-deploy,用于命令安装 iOS app ,https://www.npmjs.com/package/ios-deploy
d.FastMonkey 设置为非 sevrer 模式

3.简单说明下脚本流程

自动化打包机打包->定时检测最新安装包->自动安装待测 app->执行 monkey->解析 crash report->DB 存储->Web 展示

4.脚本:

https://github.com/Lemonzhulixin/iOS-monkey.git

# -*- coding: UTF8 -*-
from iOSCrashAnalysis.CrashExport import CrashExport
from iOSCrashAnalysis.getPakeage import getPakeage
from iOSCrashAnalysis import mysql_monkey
from iOSCrashAnalysis.FileOperate import *
from iOSCrashAnalysis.BaseIosPhone import get_ios_devices,get_ios_PhoneInfo
from iOSCrashAnalysis.FileOperate import FileFilt


PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

def monkey(devicename):
    cmd_monkey = "xcodebuild -project /Users/iOS_Team/.jenkins/workspace/iOS_Monkey_VivaVideo/XCTestWD/XCTestWD/XCTestWD.xcodeproj " \
                 "-scheme XCTestWDUITests " \
                 "-destination 'platform=iOS,name=" + devicename + "' " + \
                 "XCTESTWD_PORT=8001 " + \
                 "clean test"

    print(cmd_monkey)
    try:
        os.system(cmd_monkey)
    except Exception as msg:
        print('error message:', msg)
        raise

if __name__ == '__main__':
    print('获取设备信息')
    # dev_list = []
    # devices = get_ios_devices()
    # for i in range(len(devices)):
    #     duid = get_ios_devices()[i]
    #     dev = get_ios_PhoneInfo(duid)
    #     dev_list.append(dev)
    # print(dev_list)

    deviceName = 'iPhone2140'
    deviceID = 'e80251f0e66967f51add3ad0cdc389933715c3ed'
    release = '9.3.2'

    print('远程复制ipa文件到本地')
    start_time = time.strftime('%Y%m%d%H%M%S', time.localtime())
    cmd_copy = 'sshpass -p ios scp -r iOS_Team@10.0.35.xx:/Users/iOS_Team/XiaoYing_AutoBuild/XiaoYing/XiaoYingApp/fastlane/output_ipa/ ~/Desktop'
    os.system(cmd_copy)

    print('安装ipa测试包到设备')
    path = "/Users/iOS_Team/Desktop/output_ipa/"
    file_format = ['.ipa']
    ipa_path = getPakeage().get_ipa(path, file_format)
    getPakeage().install(path, file_format, deviceID)

    print("启动monkey")
    monkey(deviceName)

    print('解析crash report')
    find_str = 'XiaoYing-'  # 待测app crashreport文件关键字
    file_format1 = [".ips"]  # 导出的crash文件后缀
    file_format2 = [".crash"]  # 解析后的crash文件后缀
    CrashExport(deviceID, find_str, file_format1, file_format2)
    end_time = time.strftime('%Y%m%d%H%M%S', time.localtime())

    print('测试结果数据解析并DB存储')
    loacl_time = time.strftime('%Y%m%d%H%M%S', time.localtime())
    iOS_tag = 'iOS_' + loacl_time

    print('插入数据到device表')
    deviceData = {
        'name': deviceName,
        'serial_number': deviceID,
        'version': release,
        'status': 1,
        'tag': 'iOS'
    }

    print('插入数据到apk信息表')
    # ipa_path = '/Users/zhulixin/Desktop/output_ipa/day_inke_release_xiaoying.ipa'
    ipainfo = getPakeage().getIpaInfo(ipa_path)
    apkData = {
        'app_name': ipainfo[0],
        'ver_name': ipainfo[2],
        'ver_code': ipainfo[3],
        'file_name': 'day_inke_release_xiaoying.ipa',
        'file_path': ipa_path,
        'build_time': start_time,
        'tag': iOS_tag
    }

    print('插入数据到task表')
    taskData = {
        'start_time': start_time,
        'end_time': end_time,
        'app_name': ipainfo[0],
        'devices': 1,
        'test_count': None,
        'pass_count': None,
        'fail_count': None,
        'passing_rate': None,
        'tag': iOS_tag,
        'info': None
    }

    print('插入数据到results表')
    # f = FileFilt()
    # f.FindFile(find_str, file_format1, './CrashInfo/')
    # crash_count = len(f.fileList)
    # result = 1
    # if crash_count:
    #     result = 0

    resultData = {
        'result_id': start_time + '-monkey-' + ipainfo[0],
        'start_time': start_time,
        'end_time': end_time,
        'device_name': deviceName,
        'apk_id': None,
        'result': None,
        'status': None,
        'CRASHs': None,
        'ANRs': None,
        'tag': iOS_tag,
        'device_log':None,
        'monkey_log': None,
        'monkey_loop': None,
        'cmd':None,
        'seed': None
    }

    # print('deviceData:', deviceData)
    # mysql_monkey.insert_record_to_phones(deviceData)

    print('apkData:', apkData)
    mysql_monkey.insert_record_to_apks(apkData)

    print('taskData:', taskData)
    mysql_monkey.insert_record_to_tasks(taskData)

    print('resultData:', resultData)
    mysql_monkey.insert_record_to_results(resultData)

    print("压缩测试结果并传")
    f = FileFilt()
    results_file = f.zip_report(loacl_time, './CrashInfo/', './Results_ZIP/')
    url = 'http://10.0.32.xx:5100/api/v1/iOS-monkey'
    files = {'file': open(results_file, 'rb')}
    response = requests.post(url, files=files)
    json = response.json()

    print("删除本次的测试结果")
    f.DelFolder('./CrashInfo/')
    print("xxxxxxxxxxxxxxxxxxxxxxxxx Finish Test xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

5.Jenkins 部署定时任务


6.待优化

a.多设备执行
b.设备系统日志获取及 web 展示
c.操作日志获取及 web 展示

最后感谢@zhangzhao_lenovo 开源的 FastMonkey 工具,赞!

共收到 14 条回复 时间 点赞

点个赞👍

帖子上代码的排版有问题 修改套用下 markdown 吧

请教下楼主,关于 fastmonkey 我也用过,关于 carsh log 你是如何做的,我用的非 server 模式,跳出 app 后会重新运行 app,你怎么发现 carsh 多少次呢

已修改,昨天写的时候没注意,谢谢分享的 FastMonkey 工具,很赞!👍

John 回复

次数我们不关心,我们只关注 log(本地和线上监控的),所以跟你一样,也不知道 crash 准确的次数,只能通过 log 大概的判断挂了多少次。

匿名 #6 · 2018年04月04日

现在遇到一个问题 就是 ipad 横屏时 通过 screenshot 接口获取的截图还是竖屏的
IOS 9.3 OS 10.13.4 IPAD WEBDRIVERAGENT 最新代码
@zhangzhao_lenovo @slideplustest 大神求解决

这个。。。。pad 我没试过,还得@zhangzhao_lenovo来解决,我 iOS 开发方面小白~😓

这个是在真机上执行还是在模拟器上执行?

meizifighting 回复

我是真机,理论上虚拟机应该也可以,我没试过。

lemon 关闭了讨论 08月16日 16:09
lemon 重新开启了讨论 08月27日 18:32

运行的时候报错,无法启动 app:Unable to update application state promptly for Application '

Test Case '-[XCTestWDUITests.XCTextWDRunner testRunner]' started.
    t =     0.00s Start Test at 2018-11-11 17:18:10.514
    t =     0.05s Set Up
    t =     0.06s     Pressing Home button
2018-11-11 17:18:12.593909+0800 XCTestWDUITests-Runner[28587:386693] springApplication:nil
    t =    62.09s Snapshot accessibility hierarchy for app with pid 25419
    t =    62.19s     Assertion Failure: XCTestWDMonkey.swift:23: Unable to update application state promptly for Application 'com.myApp.demo'.
    t =    62.20s Tear Down
    t =    62.20s     Pressing Home button
    t =    62.24s     Pressing Home button
Test Case '-[XCTestWDUITests.XCTextWDRunner testRunner]' failed (62.256 seconds).
Test Suite 'XCTextWDRunner' failed at 2018-11-11 17:19:12.770.
     Executed 1 test, with 1 failure (0 unexpected) in 62.256 (62.258) seconds
Test Suite 'XCTestWDUITests.xctest' failed at 2018-11-11 17:19:12.771.
     Executed 1 test, with 1 failure (0 unexpected) in 62.256 (62.260) seconds
Test Suite 'All tests' failed at 2018-11-11 17:19:12.771.
     Executed 1 test, with 1 failure (0 unexpected) in 62.256 (62.269) seconds
LLVM Profile Error: Failed to write file "default.profraw": Permission denied


bupo 回复

您好,xcode10.1 同报这个错,请问有解决办法了么

你好问问 monkeytest 执行的时候怎么老提示找不到设备呢?
"C:\Program Files\Python36\python.exe" F:/monkeyTest/monkeyTest.py
持久性目录 info 已存在,继续执行测试!
'adb' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
当前已连接待测手机数为:-2
'adb' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
设备不存在

Process finished with exit code 0
无限都已经连上了

仅楼主可见

请问一下通过命令下方的话,怎么动态控制执行时间呢?是根据代码里面固定的时间执行吗?

bupo 回复

请问,你说的这个问题现在解决了没?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册