栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

多测师肖sir

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

多测师肖sir

接口自动化框架设计

一、第一包config包

二、第二个包组建接口api


三、第三个包 testcase

四、第四个包report 报告包

五、utils 包存放工具类

六、第六个包run 包就是运行

七、结果:
报告:

邮件:

接口自动化连框架设计实战:

第一步:新建一个新的项目

第二步:在项目下建6个包

命名:
第一个包:新建config包
存放所有接口的参数,新建config包(命名config)
(1)新建config包,

(2)新建config文件(.py)

配置所有的接口基本信息
#登录接口
dl_post_url = “http://cms.duoceshi.cn/cms/manage/loginJump.do”
data = {‘userAccount’: ‘admin’, ‘loginPwd’: 123456}
headers = {“Content-Type”: “application/x-www-form-urlencoded”}
#查询用户接口
lmcx_url= “http://cms.duoceshi.cn/cms/manage/findCategoryByPage.do”
lmcx_data = {‘parentId’: ‘’, ‘categoryName’: “”, ‘page’: 1}
lmcx_headers = {“Content-Type”: “application/x-www-form-urlencoded”}

第二个包:api包

源代码:
import requests
s=requests.Session()
from cms_config.config import *
class Cms(object):
def init(self):
pass
def Dl(self):
r=s.post(url=dl_post_url,data=dl_data,json=dl_headers)
return r.text
def lmcx(self):
r=s.post(url=lmcx_url,data=lmcx_data,json=lmcx_headers)
return r.text
if name == ‘main’:
c=Cms()
print(c.Dl())
print(c.lmcx())

第三个包:testcase 存放所有的用例

#存放所有的用例
import unittest
from cms_api.api import *
class Test_case(unittest.TestCase):
def setUp(self) -> None:
pass
def tearDown(self) -> None:
pass
def test001(self):
x=Cms().Dl()
def test(self):
y=Cms().lmcx()
if name == ‘main’:
unittest.main()

第四个包:report 包 存放所有报告

第五个包:工具类包

第六包:run包 运行所有的用例

import unittest,os,time
from cms_utils.HTMLTestRunner3_New import HTMLTestRunner
from cms_utils.mail3 import SendMail
p=os.path.join(os.path.abspath(os.path.dirname(os.getcwd())))

print§ #print 项目路径

testcase_path=os.path.join(os.path.abspath(os.path.dirname(os.getcwd())),“cms_testcase”)

print(testcase_path)

bg_path=os.path.join(os.path.abspath(os.path.dirname(os.getcwd())),“cms_report”)

print(bg_path)

new=time.strftime("%y-%m-%d %H-%M-%S")
file=bg_path+"/"+str(new)+"_repot.html"
def bg(x):
d=unittest.defaultTestLoader.discover(start_dir=testcase_path,pattern=x)
f=open(file,“wb”)
r=HTMLTestRunner(stream=f,description=“执行用例情况如下”,title=“cms接口自动化框架”,tester=“hz12”)
r.run(d)
def yj():
fs=SendMail(send_msg=file,attachment=file)
fs.send_mail()
if name == ‘main’:
bg(‘cms*.py’)
yj()

备注:
邮件模板:



点击设置,选择pop3




转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/603702.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号