Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangjingdong
/
bihe_interface_test
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
df4a893e
authored
Jan 11, 2019
by
zhangjingdong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加报告整合邮件
parent
4b70f2f5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
14 deletions
+91
-14
.DS_Store
+0
-0
.idea/workspace.xml
+0
-0
碧合app/.DS_Store
+0
-0
碧合app/execute_automation_scripts.py
+91
-14
No files found.
.DS_Store
View file @
df4a893e
No preview for this file type
.idea/workspace.xml
View file @
df4a893e
This diff is collapsed.
Click to expand it.
碧合app/.DS_Store
View file @
df4a893e
No preview for this file type
碧合app/execute_automation_scripts.py
View file @
df4a893e
# cod
ing = utf-8
# cod
ing = utf-8
# coding = utf-8
from
bs4
import
BeautifulSoup
import
time
import
os
import
re
import
smtplib
from
email.mime.text
import
MIMEText
from
email.header
import
Header
class
PostmanApi
():
def
endWith
(
self
,
s
,
*
endstring
):
"""
:param s:
:param endstring:
:return:
筛选文件
"""
array
=
map
(
s
.
endswith
,
endstring
)
if
True
in
array
:
return
True
else
:
return
False
def
full_path
(
self
,
BASE_DIR
,
file_path
,
delay_request
,
timeout_request
,
now_time
):
path
=
"newman run "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
\
".postman_collection.json -e "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
\
+
file_path
+
"_manage.postman_environment.json --delay-request "
\
+
delay_request
+
" --timeout-request "
+
timeout_request
\
+
" --reporters html --reporter-html-export "
+
now_time
return
path
class
PostmanApi
:
def
report_mail
(
self
,
years
,
report_text
,
report_text1
,
at_the
,
report_file
):
mail_host
=
"smtp.exmail.qq.com"
# 设置服务器
mail_user
=
"zhangjingdong@maxrocky.com"
# 用户名
mail_pass
=
"Xqw123123"
# 口令
sender
=
'zhangjingdong@maxrocky.com'
# 接收邮件
receivers
=
[
'zhangjingdong@maxrocky.com'
]
message
=
MIMEText
(
'各位领导同事:
\n
以下是本次接口自动化测试的执行结果
\n
'
+
report_text
+
"
\n
"
+
report_text1
+
"
\n
报告执行具体情况可通过下面链接查看
\n
"
" 报告地址:"
+
"http://reptorfile.bgycc.com/"
+
" "
+
years
+
"/"
+
at_the
,
'plain'
,
'utf-8'
)
message
[
'From'
]
=
Header
(
"测试环境接口自动化测试"
)
message
[
'Subject'
]
=
Header
(
years
+
at_the
+
"自动化测试结果"
,
'utf-8'
)
try
:
smtpObj
=
smtplib
.
SMTP
()
smtpObj
.
connect
(
mail_host
,
25
)
# 25 为 SMTP 端口号
smtpObj
.
login
(
mail_user
,
mail_pass
)
smtpObj
.
sendmail
(
sender
,
receivers
,
message
.
as_string
())
print
(
"邮件发送成功"
)
except
smtplib
.
SMTPException
:
print
(
"Error: 无法发送邮件"
)
return
True
def
post
(
self
):
file
=
[]
report_text
=
""
report_text1
=
""
report_file
=
"/phantom/file/testreport/"
# report_file = "/Users/lucas/Documents/reporter/"
BASE_DIR
=
os
.
path
.
realpath
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
path
=
os
.
listdir
(
BASE_DIR
)
at_the
=
time
.
strftime
(
"
%
H-
%
M"
,
time
.
localtime
(
time
.
time
()))
at_the
=
time
.
strftime
(
"
%
H:
%
M"
,
time
.
localtime
(
time
.
time
()))
years
=
time
.
strftime
(
"
%
Y-
%
m-
%
d"
,
time
.
localtime
(
time
.
time
()))
extract_data
=
report_file
+
years
+
"/"
+
at_the
extract_data
=
"/Users/lucas/Documents/reporter/2019-01-08/14-55"
delay_request
=
str
(
50
)
timeout_request
=
str
(
5000
)
timeout_request
=
str
(
5000
)
successful
=
0
failure
=
0
for
p
in
path
:
if
os
.
path
.
isdir
(
p
):
file
.
append
(
p
)
for
file_path
in
file
:
# 当天日期
now_date
=
report_file
+
years
print
(
now_date
)
# 目前时分
now_module
=
now_date
+
"/"
+
at_the
print
(
now_module
)
now_time
=
now_module
+
"/"
+
file_path
+
'.html'
print
(
now_time
)
# 文件完整路径
now_time
=
now_module
+
"/"
+
file_path
+
'.html'
execute
=
PostmanApi
()
.
full_path
(
BASE_DIR
,
file_path
,
delay_request
,
timeout_request
,
now_time
)
if
(
os
.
path
.
exists
(
now_date
)):
if
(
os
.
path
.
exists
(
now_module
)):
execute
=
"newman run "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
".postman_collection.json -e "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
"_manage.postman_environment.json --delay-request "
+
delay_request
+
" --timeout-request "
+
timeout_request
+
" --reporters html --reporter-html-export "
+
now_time
os
.
system
(
execute
)
else
:
os
.
system
(
"mkdir "
+
now_module
)
execute
=
"newman run "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
".postman_collection.json -e "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
"_manage.postman_environment.json --delay-request "
+
delay_request
+
" --timeout-request "
+
timeout_request
+
" --reporters html --reporter-html-export "
+
now_time
os
.
system
(
execute
)
else
:
os
.
system
(
"mkdir "
+
now_date
)
if
(
os
.
path
.
exists
(
now_module
)):
execute
=
"newman run "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
".postman_collection.json -e "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
"_manage.postman_environment.json --delay-request "
+
delay_request
+
" --timeout-request "
+
timeout_request
+
" --reporters html --reporter-html-export "
+
now_time
os
.
system
(
execute
)
else
:
os
.
system
(
"mkdir "
+
now_module
)
execute
=
"newman run "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
".postman_collection.json -e "
+
BASE_DIR
+
"/"
+
file_path
+
"/"
+
file_path
+
"_manage.postman_environment.json --delay-request "
+
delay_request
+
" --timeout-request "
+
timeout_request
+
" --reporters html --reporter-html-export "
+
now_time
os
.
system
(
execute
)
for
item
in
os
.
listdir
(
extract_data
):
if
PostmanApi
()
.
endWith
(
item
,
'.html'
):
# print(item)
with
open
(
extract_data
+
"/"
+
item
,
'rU'
)
as
strf
:
str1
=
strf
.
read
()
res_2
=
r'Test Scripts</div><div class="col-md-4">(.+?)</div><div class="col-md-4">(.+?)</div>'
pile1
=
re
.
compile
(
res_2
)
li
=
re
.
findall
(
pile1
,
str1
)
li1
=
str
(
li
[
0
][
0
])
li2
=
str
(
li
[
0
][
1
])
successful
+=
int
(
li
[
0
][
0
])
failure
+=
int
(
li
[
0
][
1
])
report
=
""
report_text
+=
report
.
join
(
" 模块:"
+
item
[:
-
5
]
+
" 数量:"
+
li1
+
" 失败:"
+
li2
+
"
\n
"
)
report_text1
=
" 接口数量:"
+
str
(
successful
)
+
" 失败数量:"
+
str
(
failure
)
PostmanApi
()
.
report_mail
(
years
,
report_text1
,
report_text
,
at_the
,
report_file
)
return
self
if
__name__
==
'__main__'
:
PostmanApi
()
.
post
()
\ No newline at end of file
PostmanApi
()
.
post
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment