1 Star 0 Fork 2

codeceo/appMonkey

forked from 冰貉/appMonkey 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
uploadresult.py 3.11 KB
一键复制 编辑 原始数据 按行查看 历史
冰貉 提交于 2021-03-12 09:31 . 上传修改兼容android10
import requests
import json
import datetime
from testresult import TestResult
'''测试结果上传'''
class UploadResult():
def __init__(self, deviceid, result, modulename, productname, version, apkversion, tester, starttime, endtime, reportname):
self.result = result
self.data = {}
self.data['test_deviceid'] = deviceid
self.data['test_projectname'] = productname
if apkversion != None and apkversion != '':
self.data['test_version'] = apkversion
else:
self.data['test_version'] = version
self.data['tester'] = tester
self.data['test_start_time'] = starttime.strftime('%Y-%m-%d %H:%M:%S')
self.data['test_end_time'] = endtime.strftime('%Y-%m-%d %H:%M:%S')
self.data['test_type'] = 'Monkey测试'
self.data['test_module'] = modulename
self.data['test_testcase'] = ''
self.data['test_reportname'] = reportname
timespan = (endtime - starttime)
if timespan.seconds<90:
self.data['test_use_minutes'] = '1'
else:
self.data['test_use_minutes'] = str(round(timespan.seconds/60))
self.postdata_url = 'http://tdc.vivo.xyz/tdc/post_jenkins_json'
self.upload_file_url = 'http://tdc.vivo.xyz/tdc/upload_file'
pass
def postdata(self):
'''开始上传数据'''
failnumber = 0
passnumber = 0
for rt in self.result.result:
rtlist = list(rt)
if str(rtlist[0]).find('0')>=0:
passnumber = passnumber + 1
else:
failnumber = failnumber + 1
testcasename = str(rtlist[1]).replace('<','').replace('>','')
if self.data['test_testcase'] == '':
self.data['test_testcase'] = testcasename
else:
self.data['test_testcase'] = self.data['test_testcase'] + ',' + testcasename
if failnumber>0:
self.data['test_result'] = '失败'
else:
self.data['test_result'] = '成功'
self.data['test_fail_number'] = str(failnumber)
self.data['test_pass_number'] = str(passnumber)
self.data['test_bug_number'] = str(failnumber)
print('执行结果:'+self.data['test_result'])
headers = {'Content-Type':'application/json'}
value = json.dumps(self.data).encode('utf-8')
#print(value)
response = requests.post(self.postdata_url, data = value, headers = headers)
if response.text == 'OK':
print('==============数据上传成功===============')
else:
print('==============数据上传失败===============' + response.text)
def upload_file(self, filepath):
'''上传测试报告文件'''
file = {'myfile': open(filepath,'rb')}
response = requests.post(self.upload_file_url, files=file)
if response.text == 'OK':
print('==============数据文件成功================')
else:
print('==============数据文件失败================' + response.text)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/abaiweb/app-monkey.git
git@gitee.com:abaiweb/app-monkey.git
abaiweb
app-monkey
appMonkey
master

搜索帮助