-
Notifications
You must be signed in to change notification settings - Fork 6
/
reports.py
313 lines (310 loc) · 27.6 KB
/
reports.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import os
import json
import glob
import datetime
from shovel import task
from gmail import GMail
from gmail import Message
@task
def email(to_email="nareshnavinash@gmail.com", jenkins_url="Not set from cli", git_branch="Not set from cli", git_commit="Not set from cli", git_commiter_email="Not set from cli"):
"""Emails the consolidated report to the recipients"""
failed = 0
passed = 0
broken = 0
failed_cases = []
broken_cases = []
attachments = []
for file in glob.glob("reports/allure/*result.json"):
f = open(os.getcwd() + "/" + file, 'r')
file_data_as_string = f.readlines()
json_values = json.loads(file_data_as_string[0])
try:
if json_values['status'] == "passed":
passed = passed + 1
elif json_values['status'] == "failed":
failed = failed + 1
failed_cases.append(json_values['name'])
else:
broken = broken + 1
broken_cases.append(json_values['name'])
except Exception as e:
broken = broken + 1
broken_cases.append(json_values['name'])
print(e)
print("Passed - " + str(passed))
print("Failed - " + str(failed))
print("Broken - " + str(broken))
# Email parameters
email = "nareshapitest@gmail.com" # to send the email from this account
password = "Test@123"
gmail = GMail(email, password)
current_time = str(datetime.datetime.now())
if failed == 0 and broken == 0:
email_subject = "Automation - Report " + current_time
else:
email_subject = "Automation - Report " + current_time + " - Alert failure(s) found !!!"
if len(failed_cases) != 0:
final_string = ""
for cases in failed_cases:
final_string = final_string + "<li>" + cases + "</li>"
failed_testcases_string = "Failed Test Cases, \n<ul>\n" + final_string + "\n</ul>"
else:
failed_testcases_string = ""
if len(broken_cases) != 0:
final_string = ""
for cases in broken_cases:
final_string = final_string + "<li>" + cases + "</li>"
broken_testcases_string = "Broken Test Cases, \n<ul>\n" + final_string + "\n</ul>"
else:
broken_testcases_string = ""
for file in glob.glob("reports/*.html"):
attachments.append(file)
html_body = "" \
"<body style=\"margin: 0; padding: 0;\">" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"background: #f3f3f3; min-width: 350px; font-size: 1px; line-height: normal;\">" \
"<tr>" \
"<td align=\"center\" valign=\"top\">" \
"<!--[if (gte mso 9)|(IE)]>" \
"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" \
"<tr><td align=\"center\" valign=\"top\" width=\"750\"><![endif]-->" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"750\" class=\"table750\" style=\"width: 100%; max-width: 750px; min-width: 350px; background: #f3f3f3;\">" \
"<tr>" \
"<td class=\"mob_pad\" width=\"25\" style=\"width: 25px; max-width: 25px; min-width: 25px;\"> </td>" \
"<td align=\"center\" valign=\"top\" style=\"background: #ffffff;\">" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;\">" \
"<tr>" \
"<td align=\"right\" valign=\"top\">" \
"<div class=\"top_pad\" style=\"height: 25px; line-height: 25px; font-size: 23px;\"> </div>" \
"</td>" \
"</tr>" \
"</table>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;\">" \
"<tr>" \
"<td align=\"right\" valign=\"top\">" \
"<div class=\"top_pad\" style=\"height: 25px; line-height: 25px; font-size: 23px;\"> </div>" \
"</td>" \
"</tr>" \
"</table>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"88%\" style=\"width: 88% !important; min-width: 88%; max-width: 88%;\">" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<div style=\"height: 10px; line-height: 33px; font-size: 31px;\"> </div>" \
"<div class=\"header\" align=\"center\">" \
"<h2 style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #3375AA; font-size: 32px; line-height: 32px;\">Automation Report</h2>" \
"</div>" \
"<div style=\"height: 10px; line-height: 33px; font-size: 31px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#1a1a1a\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 20px; line-height: 32px;\">Hi Team,</span>" \
"</font>" \
"<div style=\"height: 33px; line-height: 33px; font-size: 31px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 20px; line-height: 32px;\">Automation Regression Status,</span>" \
"</font>" \
"<div style=\"height: 20px; line-height: 20px; font-size: 20px;\"> </div>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"88%\" style=\"width: 88% !important; min-width: 88%; max-width: 88%;\">" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 18px; line-height: 32px;\">Passed Test Case count :</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #0E9C4A; font-size: 18px; line-height: 32px;\">" + str(passed) + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 18px; line-height: 32px;\">Failed Test Case count :</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #B2230F; font-size: 18px; line-height: 32px;\">" + str(failed) + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 18px; line-height: 32px;\">Broken Test Case count :</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #E6C404; font-size: 18px; line-height: 32px;\">" + str(broken) + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 18px; line-height: 32px;\">Run Completed at :</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #130145; font-size: 18px; line-height: 32px;\">" + str(current_time) + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"</table>" \
"<div style=\"height: 33px; line-height: 33px; font-size: 31px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 18px; line-height: 32px;\">HTML Reports are attached for reference. Below are the few parameters that are responsible for this job trigger. If any failures or broken cases found in the result kindly trace back from the last commit ID with the last commited user.</span>" \
"</font>" \
"<div style=\"height: 20px; line-height: 20px; font-size: 31px;\"> </div>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"88%\" style=\"width: 88% !important; min-width: 88%; max-width: 88%;\">" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 17px; line-height: 32px;\">Jenkins URL:</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<a href=\"" + jenkins_url +"\" style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #130145; font-size: 17px; line-height: 32px;\">navigate_to_jenkins</a>" \
"</font>" \
"</td>" \
"</tr>" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 17px; line-height: 32px;\">Git Branch:</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #130145; font-size: 17px; line-height: 32px;\">" + git_branch + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 17px; line-height: 32px;\">Last Commit ID:</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #130145; font-size: 17px; line-height: 32px;\">" + git_commit + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 17px; line-height: 32px;\">Last Commit by:</span>" \
"</font>" \
"</td>" \
"<td align=\"left\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #130145; font-size: 17px; line-height: 32px;\">" + git_commiter_email + "</span>" \
"</font>" \
"</td>" \
"</tr>" \
"</table>" \
"<div style=\"height: 33px; line-height: 33px; font-size: 31px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 18px; line-height: 32px;\">Follow the following Link for detailed analysis in allure,</span>" \
"</font>" \
"<div style=\"height: 10px; line-height: 10px; font-size: 10px;\"> </div>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"88%\" style=\"width: 88% !important; min-width: 88%; max-width: 88%;\">" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<table class=\"mob_btn\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background: #27cbcc; border-radius: 4px;\">" \
"<tr>" \
"<td align=\"center\" valign=\"top\">" \
"<a href=\"" + jenkins_url + "/allure/\" target=\"_blank\" style=\"display: block; border: 1px solid #27cbcc; border-radius: 4px; padding: 4px 8px; font-family: 'Source Sans Pro', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#ffffff\" style=\"font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Verdana, Tahoma, Geneva, sans-serif; color: #ffffff; font-size: 20px; line-height: 30px; text-decoration: none; white-space: nowrap; font-weight: 600;\">Allure Report</span>" \
"</font>" \
"</a>" \
"</td>" \
"</tr>" \
"</table>" \
"</td>" \
"</tr>" \
"</table>" \
"<div style=\"height: 45px; line-height: 10px; font-size: 10px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 16px; line-height: 32px;\">This email is auto-triggered from Jenkins Automation Job, for any queries please contact </span>" \
"<a href=\"mailto:nareshnavinash@gmail.com\" style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 16px; line-height: 32px;\"> nareshnavinash@gmail.com</a>" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 16px; line-height: 32px;\"> or </span>" \
"<a href=\"mailto:nareshsekar@zoho.com\" style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 16px; line-height: 32px;\">nareshsekar@zoho.com.</a>" \
"</font>" \
"<div style=\"height: 33px; line-height: 33px; font-size: 31px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 16px; line-height: 32px;\">" + failed_testcases_string +"</span>" \
"</font>" \
"<div style=\"height: 1px; line-height: 1px; font-size: 31px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#585858\" style=\"font-size: 24px; line-height: 32px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #585858; font-size: 16px; line-height: 32px;\">" + broken_testcases_string + "</span>" \
"</font>" \
"<div style=\"height: 33px; line-height: 33px; font-size: 31px;\"> </div>" \
"</td>" \
"</tr>" \
"</table>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"90%\" style=\"width: 90% !important; min-width: 90%; max-width: 90%; border-width: 1px; border-style: solid; border-color: #e8e8e8; border-bottom: none; border-left: none; border-right: none;\">" \
"<tr>" \
"<td align=\"left\" valign=\"top\">" \
"<div style=\"height: 15px; line-height: 15px; font-size: 13px;\"> </div>" \
"</td>" \
"</tr>" \
"</table>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"88%\" style=\"width: 88% !important; min-width: 88%; max-width: 88%;\">" \
"<tr>" \
"<td class=\"mob_center\" align=\"left\" valign=\"top\">" \
"<div style=\"height: 10px; line-height: 10px; font-size: 11px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#000000\" style=\"font-size: 19px; line-height: 23px; font-weight: 600;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #7f7f7f; font-size: 19px; line-height: 23px;\">Thanks,</span>" \
"</font>" \
"<div style=\"height: 1px; line-height: 1px; font-size: 1px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#7f7f7f\" style=\"font-size: 19px; line-height: 23px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #000000; font-size: 19px; line-height: 23px; font-weight: 600;\">SDET Team.</span>" \
"</font>" \
"<div style=\"height: 25px; line-height: 20px; font-size: 15px;\"> </div>" \
"</td>" \
"</tr>" \
"</table>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"width: 100% !important; min-width: 100%; max-width: 100%; background: #f3f3f3;\">" \
"<tr>" \
"<td align=\"center\" valign=\"top\">" \
"<div style=\"height: 34px; line-height: 34px; font-size: 32px;\"> </div>" \
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"88%\" style=\"width: 88% !important; min-width: 88%; max-width: 88%;\">" \
"<tr>" \
"<td align=\"center\" valign=\"top\">" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#868686\" style=\"font-size: 17px; line-height: 20px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #868686; font-size: 17px; line-height: 20px;\">Copyright © 2020 Naresh Sekar. All Rights Reserved. Confidential attachments!</span>" \
"</font>" \
"<div style=\"height: 2px; line-height: 2px; font-size: 32px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#868686\" style=\"font-size: 17px; line-height: 20px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #868686; font-size: 17px; line-height: 20px;\">Beware Before Forwarding this e-mail!</span>" \
"</font>" \
"<div style=\"height: 3px; line-height: 3px; font-size: 1px;\"> </div>" \
"<font face=\"'Source Sans Pro', sans-serif\" color=\"#1a1a1a\" style=\"font-size: 17px; line-height: 20px;\">" \
"<span style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px;\"><a href=\"mailto:nareshnavinash@gmail.com\" target=\"_blank\" style=\"font-family: 'Source Sans Pro', Arial, Tahoma, Geneva, sans-serif; color: #1a1a1a; font-size: 17px; line-height: 20px; text-decoration: none;\">nareshnavinash@gmail.com</a>" \
"</font>" \
"<div style=\"height: 35px; line-height: 35px; font-size: 33px;\"> </div>" \
"</td>" \
"</tr>" \
"</table>" \
"</td>" \
"</tr>" \
"</table>" \
"</td>" \
"<td class=\"mob_pad\" width=\"25\" style=\"width: 25px; max-width: 25px; min-width: 25px;\"> </td>" \
"</tr>" \
"</table>" \
"<!--[if (gte mso 9)|(IE)]>" \
"</td></tr>" \
"</table><![endif]-->" \
"</td>" \
"</tr>" \
"</table>" \
"</body>" \
""
message = Message(email_subject, to=to_email, html=html_body, attachments=attachments)
gmail.send(message)