-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# 使用Python Selenium 进行自动化测试 | ||
|
||
- 支持在PC、H5上运行,代理获取接口数据,无头模式,生成报告(含截图),发送邮件等 | ||
|
||
## 快速开始 | ||
|
||
- 复制并修改全局配置,`cp config.example.yaml config.yaml`,此文件为全局配置,config目录下文件可覆盖此配置 | ||
|
@@ -52,10 +54,13 @@ | |
> 8. 根据 action 执行动作 | ||
* 配置文件内容分为五类,格式说明如下: | ||
1. DEBUG: 布尔,`True/False`,是否开启调试模式,True-不生成生成报告,方便调试 | ||
* 配置文件分为以下内容,格式说明如下: | ||
1. DEBUG: 布尔,`True/False`,是否开启调试模式,True-不生成生成报告,方便调试 | ||
IMAGE: 布尔,`True/False`,是否截图,DEBUG为False且IMAGE设置为True时截图 | ||
|
||
2. MAIL: 邮箱配置,配置正确会发送测试用例执行报告 | ||
|
||
2. BROWSER,对浏览器层的设置 | ||
3. BROWSER,对浏览器层的设置 | ||
|
||
> type: 字符串,使用浏览器类型,目前支持 `Chrome/Firefox` | ||
|
@@ -69,11 +74,11 @@ | |
> headless: 布尔,`True/False`,是否开启无头模式,无界面测试,方便集成到服务器自动化部署 | ||
3. WEBSITE,启动页面的设置 | ||
4. WEBSITE,启动页面的设置 | ||
|
||
> url: 字符串,启动页地址,目前只有这一个配置可用 | ||
4. MENU,测试用例详情 | ||
5. MENU,测试用例详情 | ||
|
||
> key: 字符串,菜单路径 | ||
|
@@ -127,6 +132,19 @@ | |
DEBUG: True/False #是否开启调试模式,True-不生成生成报告,方便调试 | ||
IMAGE: True/False #是否截图,DEBUG为False且IMAGE设置为True时截图 | ||
|
||
MAIL: | ||
SEND: True/False | ||
# 邮箱服务端配置 | ||
SMTP: | ||
username: [email protected] | ||
password: xxxxxxxxxx | ||
host: smtp.163.com | ||
port: 25 | ||
# 收件人列表 | ||
receiver: | ||
- [email protected] | ||
- [email protected] | ||
|
||
BROWSER: | ||
#浏览器类型 | ||
type: Chrome/Firefox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
DEBUG: True/False #是否开启调试模式,True-不生成生成报告,方便调试 | ||
IMAGE: True/False #是否截图,DEBUG为False且IMAGE设置为True时截图 | ||
|
||
MAIL: | ||
SEND: True/False #是否开启发送邮箱配置,前提是,在DEBUG为false情况下生效 | ||
# 邮箱服务端配置 | ||
SMTP: | ||
username: [email protected] | ||
password: xxxxxxxxxx | ||
host: smtp.163.com | ||
port: 25 | ||
# 收件人列表 | ||
receiver: | ||
- [email protected] | ||
- [email protected] | ||
|
||
BROWSER: | ||
#浏览器类型 | ||
type: Chrome/Firefox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# coding = utf-8 | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.application import MIMEApplication | ||
from email.mime.text import MIMEText | ||
from email.mime.image import MIMEImage | ||
from email.mime.audio import MIMEAudio | ||
import smtplib | ||
import os | ||
|
||
|
||
class Mail(object): | ||
def __init__(self, config, email_attachment_path): | ||
""" | ||
init config | ||
""" | ||
self.attachment_path = email_attachment_path | ||
self.smtp = smtplib.SMTP() | ||
self.username = config.get('SMTP').get('username') | ||
self.password = config.get('SMTP').get('password') | ||
self.sender = config.get('SMTP').get('username') | ||
self.host = config.get('SMTP').get('host') | ||
self.port = config.get('SMTP').get('port') | ||
self.receiver = config.get('receiver') | ||
|
||
def connect(self): | ||
""" | ||
connect server | ||
""" | ||
self.smtp.connect(self.host, self.port) | ||
|
||
def login(self): | ||
""" | ||
login email | ||
""" | ||
try: | ||
self.smtp.login(self.username, self.password) | ||
except: | ||
raise AttributeError('Can not login smtp!!!') | ||
|
||
def send(self, email_title, email_content, email_attachment=""): | ||
""" | ||
send email | ||
""" | ||
msg = MIMEMultipart() # create MIMEMultipart | ||
msg['From'] = self.sender # sender | ||
msg['To'] = ', '.join(self.receiver) | ||
msg['Subject'] = email_title # email Subject | ||
content = MIMEText(email_content, _charset='gbk') # add email content, coding is gbk, because chinese exist | ||
msg.attach(content) | ||
|
||
# 是否指定附件,否,则发送目录下所有文件 | ||
for attachment_name in os.listdir(self.attachment_path): | ||
if email_attachment and attachment_name != email_attachment: | ||
continue | ||
else: | ||
attachment_file = os.path.join(self.attachment_path, attachment_name) | ||
|
||
with open(attachment_file, 'rb') as attachment: | ||
if 'application' == 'text': | ||
attachment = MIMEText(attachment.read(), _subtype='octet-stream', _charset='GB2312') | ||
elif 'application' == 'image': | ||
attachment = MIMEImage(attachment.read(), _subtype='octet-stream') | ||
elif 'application' == 'audio': | ||
attachment = MIMEAudio(attachment.read(), _subtype='octet-stream') | ||
else: | ||
attachment = MIMEApplication(attachment.read(), _subtype='octet-stream') | ||
|
||
attachment.add_header('Content-Disposition', 'attachment', filename=('gbk', '', attachment_name)) | ||
# make sure "attachment_name is chinese" right | ||
msg.attach(attachment) | ||
|
||
self.smtp.sendmail(self.sender, self.receiver, msg.as_string()) # format msg.as_string() | ||
|
||
def quit(self): | ||
self.smtp.quit() |