Commit 0c277885 authored by xiao-hesheng's avatar xiao-hesheng
Browse files

Signed-off-by: xiao-hesheng <xhs89@sina.com>

parent 26c6f206
Pipeline #3481 failed with stages
in 25 seconds
# -*- encoding=utf-8 -*-
import os
import sys
import common.run_case_conditions as run
import common.case_tag_get as case_tag_get
import random
import time
import requests
import json
import platform
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
def dingding_send(content):
"""
报错的用例发钉钉群
:param content:
:return:
"""
url = 'https://oapi.dingtalk.com/robot/send?access_token=d9e673ded1ab61ee6a631333a3d80b4291684e3adf61169ab6c1bb83d375e26d'
pagrem = {
"msgtype": "text",
"text": {
"content": content
},
"at": {
"atMobiles": [
],
"isAtAll": True # 是否@所有人,默认否
}
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url, data=json.dumps(pagrem), headers=headers)
print(response.text)
return response.text
def check_phone_locked():
for device_id in devices_list:
is_ok = os.system('adb -s ' + device_id + ' get-state')
print("is_ok: " + str(is_ok))
if is_ok != 0:
if '5555' in device_id:
os.system('adb connect ' + device_id)
is_ok = os.system('adb -s ' + device_id + ' get-state')
if is_ok != 0:
devices_list.remove(device_id)
else:
if device_id != 'bb294ac8':
devices_list.remove(device_id)
if "AutoTest_" in curPath:
dingding_send("设备检查:" + device_id + "离线啦, 快去看看")
else:
try:
for i in range(3):
r = os.popen('adb -s ' + device_id + ' shell dumpsys window policy')
stdout = r.read()
r.close()
if 'mShowingLockscreen=true' in stdout or 'mScreenOnEarly=false' in stdout:
if 'mScreenOnEarly=false' in stdout:
os.system('adb -s ' + device_id + ' shell input keyevent 26')
os.system('adb -s ' + device_id + ' shell input keyevent 224')
if device_id in ['0815f81aab021502', 'WTKDU16C07003266']:
os.system('adb -s ' + device_id + ' shell input swipe 300 1500 300 300')
else:
os.system('adb -s ' + device_id + ' shell input swipe 300 1000 300 500')
os.system('adb -s ' + device_id + ' shell input keyevent 3')
check_battery(device_id)
except:
pass
print("device_list:")
print(devices_list)
def check_battery(device_id):
"""
检查电池信息
:return:
"""
reset_cmd = 'adb -s ' + device_id + ' shell dumpsys battery reset'
os.system(reset_cmd)
time.sleep(1)
check_cmd = 'adb -s ' + device_id + ' shell dumpsys battery'
r = os.popen(check_cmd)
stdout = r.read()
r.close()
level = stdout.split('level')[1].split('scale')[0]
level = level.replace('\n', '').replace('\r', '').replace(': ', '')
if int(level) >= 90:
print(level)
print('adb -s ' + device_id + ' shell dumpsys battery set status 1')
os.system('adb -s ' + device_id + ' shell dumpsys battery set status 1')
else:
if int(level) < 6:
devices_list.remove(device_id)
if "AutoTest_" in curPath:
dingding_send("设备检查:" + device_id + "电量不足6%啦,快去看看")
print(level)
print('adb -s ' + device_id + ' shell dumpsys battery set status 2')
os.system('adb -s ' + device_id + ' shell dumpsys battery set status 2')
def get_file(path):
"""
获取解压出来得文件名
:return:
"""
list = []
for dirpath, dirnames, filenames in os.walk(path):
for f in filenames:
if f.endswith('.apk'):
list.append(filenames)
return list
def download(url=""):
"""
拉取主干最新的包
:return:
"""
del_cmd = 'del temp\*.* /s /q >nul'
os.system(del_cmd)
if url != "":
dump_cmd = 'curl -u admin:YKNTJKLW9Y -O ' + url
print(dump_cmd)
p = os.popen(dump_cmd)
print(p.read())
time.sleep(1)
os.popen('move *apk temp')
time.sleep(1)
else:
dump_cmd = 'curl -u admin:YKNTJKLW9Y http://pack.babytree-inc.com/view/%E5%AD%95%E8%82%B2%E5%AE%89%E5%8D%93/job/android_pregnancy_master/lastSuccessfulBuild/artifact/temp/*zip*/temp.zip -o apk.zip'
print("dump_cmd: ", dump_cmd)
unzip_cmd = 'unzip -o apk.zip'
p = os.popen(dump_cmd)
print(p.read())
os.popen(unzip_cmd)
time.sleep(2)
if __name__ == '__main__':
# 第一个参数设备ID
devices = sys.argv[1]
devices_list = devices.split(',')
# 第二个参数 选择单机或多机或多机分布式跑
runType = sys.argv[2]
# 第三个参数 case 执行类型,'all', 'choose', 'tag'
caseType = sys.argv[3]
# 第四个参数要执行的caseName, 多个文件逗号分割
caseName = sys.argv[4]
# 第五个参数,设置日志等级
log_level = sys.argv[5]
# 复制hosts文件
if platform.system() == 'Windows':
cmd = "xcopy /s /y data\hosts C:\Windows\System32\drivers\etc\ "
else:
cmd = 'mv data/hosts /etc/'
os.system(cmd)
workspace = os.path.abspath(".")
# 检查锁屏
check_phone_locked()
if len(sys.argv) >= 7 and sys.argv[6] == 'download':
if len(sys.argv) > 7:
url = sys.argv[7]
download(url)
else:
download()
case_path = os.path.join(workspace, 'air_case')
log_path = os.path.join(workspace, 'log')
runtime_log = os.path.join(log_path, 'runtime.txt')
print("workspace: " + workspace)
print("air_case_path: " + case_path)
print("air_log_path: " + log_path)
print("runType:" + runType)
print("caseType:" + caseType)
test = run.CustomAirTestCase(workspace, case_path, log_path, runtime_log, log_level)
case_list = caseName.split(',')
if caseType == 'tag':
tag = sys.argv[4]
tagList = tag.split(',')
case_list = case_tag_get.get_case_tag_list(case_path, tagList)
if caseType == 'user':
tag = sys.argv[4]
case_list = case_tag_get.get_case_by_author(case_path, tag)
random.shuffle(case_list)
"""
if '个人主页_会客厅_首次进入' in case_list:
index = case_list.index('个人主页_会客厅_首次进入')
case_list[0], case_list[index] = case_list[index], case_list[0]
print("first case is : %s " % case_list[0])
"""
if runType == 's':
test.run_case(devices_list[0], case_list)
print("执行程序里的exit(0)")
sys.exit(0)
print("执行后exit(0)")
elif runType == 'd':
if caseName == 'firstpage':
devices_list = devices_list[:3]
test.run_case_by_distri(devices_list, case_list, log_level)
print("执行程序里的exit(0)")
sys.exit(0)
print("执行后exit(0)")
else:
test.run_case_by_Multi(devices_list, case_list, log_level)
print("执行程序里的exit(0)")
sys.exit(0)
print("执行后exit(0)")
# -*- encoding=utf8 -*-
import os
import sys
import common.run_case_conditions as run
import common.case_tag_get as case_tag_get
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
if __name__ == '__main__':
# 第一个参数设备ID
devices = sys.argv[1]
devices_list = devices.split(',')
# 第二个参数 选择单机或多机或多机分布式跑
runType = sys.argv[2]
# 第三个参数 case 执行类型,'all', 'choose', 'tag'
caseType = sys.argv[3]
# 第四个参数要执行的caseName, 多个文件逗号分割
caseName = sys.argv[4]
# 第五个参数,设置日志等级
log_level = sys.argv[5]
log_level = log_level.lower()
workspace = os.path.abspath(".")
case_path = os.path.join(workspace, 'air_case')
log_path = os.path.join(workspace, 'log')
runtime_log = os.path.join(log_path, 'runtime.txt')
print("workspace: " + workspace)
print("air_case_path: " + case_path)
print("air_log_path: " + log_path)
print("runType:" + runType)
print("caseType:" + caseType)
test = run.CustomAirTestCase(workspace, case_path, log_path, runtime_log, log_level)
case_list = caseName.split(',')
if caseType == 'tag':
tag = sys.argv[4]
case_list = case_tag_get.get_case_tag_list_2(case_path, tag)
if runType == 's':
test.run_case_single(devices_list[0], case_list)
os._exit(0)
elif runType == 'd':
test.run_case_by_distri(devices_list, case_list)
os._exit(0)
else:
test.run_case_by_Multi(devices_list, case_list)
os._exit(0)
<!DOCTYPE html>
<html>
<head>
<title>测试结果汇总</title>
<style>
table,table tr th,table tr td {
border:1px solid #ccc;
border-collapse: collapse;
color: #669;
padding: 6px 8px;
font-size: 14px;
}
table caption {
font-size: 14px;
color: #039;
text-align: left;
margin-top: 10px;
margin-bottom: -10px;
margin-left: -10px;
}
.fail {
color: red;
width: 7em;
text-align: center;
}
.success {
color: green;
width: 7em;
text-align: center;
}
.details-col-elapsed {
width: 7em;
text-align: center;
}
.details-col-msg {
width: 7em;
text-align: center;
background-color:#ccc;
}
</style>
</head>
<body>
<div>
<!--<div><h2>Test Statistics</h2></div>-->
<table width="1000">
<caption><ul><li>测试概要</li></ul></caption>
<tr width="800">
<th width="400" class='details-col-msg'>用例总数</th>
<th class='details-col-msg'>成功数</th>
<th class='details-col-msg'>运行用时</th>
<th class='details-col-msg'>成功率</th>
</tr>
<tr width="800">
<td class='details-col-elapsed'>{{summary_message.caseNum}}</td>
<td class='details-col-elapsed'>{{summary_message.passNum}}</td>
<td class='details-col-elapsed'>{{summary_message.time}}</td>
<td class="details-col-elapsed">{{summary_message.passRate}}%</td>
</tr>
</table>
<!--<div><h2>Test detail</h2></div>-->
<table width="1000">
<caption><ul><li>测试列表</li></ul></caption>
<tr width="800">
<th width="400" class='details-col-msg'>用例名称</th>
<th class='details-col-msg'>执行结果</th>
<th class='details-col-msg'>执行时间(秒)</th>
<th class='details-col-msg'>用例作者</th>
<th class='details-col-msg'>执行设备</th>
</tr>
{% for r in case_results %}
<tr width="800">
<td class="details-col-elapsed"><a href='{{log_path}}/{{r.name}}/log.html' target='_blank'>{{r.name}}</a></td>
<td class="{{'success' if r.result else 'fail'}}">{{"成功" if r.result else "失败"}}</td>
<td class="details-col-elapsed">{{r.time}}</td>
<td class="details-col-elapsed">{{r.author}}</td>
<td class="details-col-elapsed">{{r.device}}</td>
</tr>
{% endfor %}
</table>
<div><h2></h2></div>
</div>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment