forked from Lemonzhulixin/python-appium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseStatistics.py
More file actions
151 lines (122 loc) · 4.85 KB
/
Copy pathBaseStatistics.py
File metadata and controls
151 lines (122 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import xlsxwriter
from Base.BaseAndroidPhone import getPhoneInfo
from Base.BaseElements import Element
from Base.BaseExcel import OperateReport
from Base.BaseInit import destroy
from Base.BasePickle import *
from datetime import datetime
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
'''
统计数据相关
'''
'''
result bool
logTest 记录日志类 class
driver
testinfo
'''
def countInfo(**kwargs):
_info = {}
step = "" # 操作步骤信息
check_step = "" # 检查点步骤信息
for case in kwargs["testCase"]:
step = step + case["info"] + "\n"
if type(kwargs["testCheck"]) == list: # 检查点为列表
for check in kwargs["testCheck"]:
check_step = check_step + check["info"] + "\n"
elif type(kwargs["testCheck"]) == dict:
check_step = kwargs["testCheck"]["info"]
else:
print("获取检查点步骤数据错误,请检查")
print(kwargs["testCheck"])
_info["step"] = step # 用例操作步骤
_info["checkStep"] = check_step # 用例检查点
if kwargs["result"]:
_info["result"] = "通过"
kwargs["logTest"].checkPointOK(driver=kwargs["driver"], caseName=kwargs["testInfo"][0]["title"],
checkPoint=kwargs["caseName"] + "_" + kwargs["testInfo"][0].get(
"msg", " "))
else:
_info["result"] = "失败" # 用例接开关
_info["img"] = kwargs["logTest"].checkPointNG(driver=kwargs["driver"], caseName=kwargs["testInfo"][0]["title"],
checkPoint=kwargs["caseName"] + "_" + kwargs["testInfo"][0].get(
"msg", " "))
_info["id"] = kwargs["testInfo"][0]["id"] # 用例id
_info["title"] = kwargs["testInfo"][0]["title"] # 用例名称
_info["caseName"] = kwargs["caseName"] # 测试函数
_info["phoneName"] = kwargs["phoneName"] # 手机名
_info["msg"] = kwargs["testInfo"][0].get("msg", "") # 备注
_info["info"] = kwargs["testInfo"][0]["info"] # 前置条件
writeInfo(data=_info, path=PATH("../Log/" + Element.INFO_FILE))
# print(read(PATH("../Log/info.pickle")))
# 本地没有设备用例的记录统计
def countSumNoDevices(devices, result, _read, phone_name):
if _read is None:
_read = []
# get_phone = getPhoneInfo(devices)
# phone_name = get_phone["brand"] + "_" + get_phone["model"] + "_" + "android" + "_" + get_phone["release"]
app = {"phone_name": phone_name, "pass": 0, "fail": 0, "device": devices}
if result:
app["pass"] = 1
else:
app["fail"] = 1
_read.append(app)
write(data=_read, path=PATH("../Log/" + Element.DEVICES_FILE))
# print(read(PATH("../Log/" + Element.DEVICES_FILE)))
return
# 统计各个设备成功失败的用例数
def countSumDevices(devices, result, phone_name):
_read = readInfo(PATH("../Log/" + Element.DEVICES_FILE))
if _read:
for item in _read:
if item["device"] == devices: # 本地已经存在该设备记录
if result:
item["pass"] = item["pass"] + 1
else:
item["fail"] = item["fail"] + 1
write(data=_read, path=PATH("../Log/" + Element.DEVICES_FILE))
return
countSumNoDevices(devices, result, _read, phone_name=phone_name)
# print(read(PATH("../Log/" + Element.DEVICES_FILE)))
# 统计所有用例数
def countSum(result):
# print("----countSum----")
data = {"sum": 0, "pass": 0, "fail": 0}
_read = read(PATH("../Log/sum.pickle"))
if _read:
data = _read
data["sum"] = data["sum"] + 1
if result:
data["pass"] = data["pass"] + 1
else:
data["fail"] = data["fail"] + 1
write(data=data, path=PATH("../Log/" + Element.SUM_FILE))
# print(read(PATH("../Log/sum.pickle")))
def countDate(testDate, testSumDate):
print("--------- countDate------")
data = read(PATH("../Log/" + Element.SUM_FILE))
print(data)
if data:
data["testDate"] = testDate
data["testSumDate"] = testSumDate
write(data=data, path=PATH("../Log/" + Element.SUM_FILE))
else:
print("统计数据失败")
'''
测试报告
'''
def writeExcel():
workbook = xlsxwriter.Workbook(PATH('../Report/' + Element.REPORT_FILE))
worksheet = workbook.add_worksheet("测试总况")
worksheet2 = workbook.add_worksheet("测试详情")
operateReport = OperateReport(workbook)
operateReport.init(worksheet, read(PATH("../Log/" + Element.SUM_FILE)),
read(PATH("../Log/" + Element.DEVICES_FILE)))
operateReport.detail(worksheet2, readInfo(PATH("../Log/" + Element.INFO_FILE)))
operateReport.close()
# destroy() # 删除文件
if __name__ == '__main__':
pass
# writeExcel()