代码拉取完成,页面将自动刷新
同步操作将从 冰貉/appMonkey 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。