当前位置: 首页 > news >正文

西城富阳网站建设seo排名优化的网站

西城富阳网站建设,seo排名优化的网站,网页设计素材图片怎么获取,logo设计公司地址使用代码如何开展接口自动化测试。 一 选择自动化测试用例 业务流程优先,单接口靠后,功能稳定优先,变更频繁不选。 二 搭建自动化测试环境 (1)安装python编译器3.7版本以上--自行安装 (2)安…

使用代码如何开展接口自动化测试。

一 选择自动化测试用例

业务流程优先,单接口靠后,功能稳定优先,变更频繁不选。

二 搭建自动化测试环境

(1)安装python编译器3.7版本以上--自行安装
(2)安装pycharm工作,方便编写和维护代码--自行安装
(3)安装request三方库,用于发送请求
(4)安装pytest三方库,用于编写测试用例
(5)安装allure,用于查看生成和查看测试报告

三 搭建自动化测试框架

(1)搭建基础框架项目目录结构
(2)通用功能类的封装,如数据库连接,excle读取等
(3)接口对象(业务类)封装与调用:接口API+Pytest框架编写测试脚本
(4)测试数据参数化(一般是针对单接口的),测试数据json,yaml,excle等
(5)用例组织运行,运行测试用例并生成测试报告

四 代码实现自动化


五 实现持续集成CICD

自行完成python和pycharm工具的安装后,我们接下来就是安装request,pytest,以及allure。

六 request安裝

request是一個三方的库,他的安装非常简单,如下
安装:python -m pip install requests
验证:pip show requests
request的使用步骤:导入包-->发送接口请求--->查看响应数据

  • request发送请求
request.请求方法(url,params=None,data=None,json=None,header=None)
//请求方法一般为:get,post,put,delete
  • requests查看响应

查看状态码:response.status_code
json形式的响应内容获取:response.json()
文本形式的响应内容获取:response.text
查看请求url:response.url
查看响应头部字符编码:response.encoding
查看头信息:response.headers
查看cookie:response.cookie
简单示例:

# 1 导包
import requests
# 2 发送请求
response = requests.get(url='www.baidu.com')
# 查看响应
print(response.status_code)
print(response.text)

七 pytest框架环境搭建

1.使用pip安装pytest

pip install pytest  安装pytest
pip install pytest-html  原生态的报告模板

2.查看安装是否成功

pip show pytest

3.pytest执行测试用例的规则

  • .py测试文件必须以test开头(或以test结尾)
  • 测试类必须以Test开头,且无init方法
  • 测试方法必须以test开头,def test_001()
  • 断言必须使用assert

4. 数据驱动(参数化)
数据驱动:data driver testing(DDT),在自动化测试中测试数据与功能函数相分离,单独存储,运行自动化测试用例时,框架会读取数据源中的数据,把数据作为参数传递到功能函数中。
由于一般测试用例覆盖多条不同输入,根据不同的前置条件选取多条数据执行多次同一功能函数,这样减少重复代码,不同输入条件之间的测试结果互相不受影响,这就是数据驱动。

在方法前添加语法糖即可实现参数化:

# @pytest.mark.parameriza('变量名',[参数化数据])    ---单一参数
@pytest.mark.parameriza('a',[1,2,3])
def test_001(self,a):print('第一个测试用例')assert 1+1==a
# 说明:用例会执行三次(三组数据),a分别为1,2,3# @pytest.mark.parameriza('变量名1,变量名2',[(value1.,value2),(value2,)]) ,多个参数
@pytest.mark.parameriza('a,b',[(1,2),(3,4),(5,6)])
def test_001(self,a,b):print('第一个测试用例')assert a+1==b
# 说明:用例会执行三次(三组数据),a分别为1,3,5,b分别为2,4,6

5.pytest的 setup 与 teardown

  • setup:前置条件,测试用例的前置条件
  • teardown: 后置条件,用例执行后,需要恢复测试环境
  • yield :在这个关键字之前的代码为setup部分,之后的代码为teardown部分
    在pytest中有四种setup和teardown
    1、setup_module & teardown_module:在整个测试用例所在的文件中所有的方法运行前和运行后运行,只会运行一次;
    2、setup_class和teardown_class:则在整个文件中的一个class中所有用例的前后运行;
    3、setup_method和teardown_method:在class内的每个方法运行前后运行;
    4、setup_function、teardown_function:在非class下属的每个测试方法的前后运行;
import pytest@pytest.fixture(scope='session')  #装饰器,声明下面的函数是setup函数,缺省值为function级#scope可以加入参数scope='class',将级别改为class#scope可以加入参数scope='module',将级别改为module#scope='session'  使用这个级别时,将fixture的内容写到conftest.py文件中,目录下的所有文件都使用这个配置def fun1():print('开始')yield  #这个关键字之后的代码相当于teardownprint('结束')def test_c01(fun1):assert 1==2if __name__ == '__main__':pytest.main(['conftest.py','-s'])

6、运行文件:

  • 运行并生成html测试报告:pytest 用例路径 --html=./report/result.html , 注意:--html= 没有空格.
  • 运行该测试模块:pytest test_login.py -s, -s 输出print信息
  • 用main()方法来运行:pytest.main(['当前用例路径','--html=测试报告/XX.html ']) ---> 运行并生成html测试报告
  • 通过allure生成测试报告:pytest.main([__file__, '-sv','--alluredir','./report/report','--clean-alluredir'])

八 Allure安装--pytest 结合Allure操作

  • Allure 安装
    1、下载Allure.zip并解压到任意目录(C:\allure\allure-2.13.0\)
    2、添加该路径到环境变量的path中
    3、cmd 安装 pip install allure-pytest
    4、验证是否安装成功:cmd 中输入allure --version查看盗版本信息
    如果安装不成功,可以在环境变量--系统变量--path中配置上allure的bin目录
    5、allure报告生成:cmd执行命令生成、pycharm的终端Terminal执行命令
    (1)方式1:pytest [测试文件] -s -q --alluredir=../report/tmp 生成Allure报告, 数据存在/tmp目录,--alluredir用于指定存储测试结果的路径;-s 表示允许执行print语句;
    (2)方式2:allure generate ../report/tmp -o ..report/tmp --clean 生成测试报告,–clean 覆盖路径
    6、查看测试报告
    (1)使用默认浏览器打开:allure serve ../report/tmp/
    (2)打开报告:allure open -h 127.0.0.1 -p 8883 ./report/

在cmd/终端中:测试用例的执行以及报告的生成如下:

pytest test_feature_story.py --alluredir=./result/2  # 执行测试用例模块test_feature_story.py
allure generate ./result/2 -o ./report/2/ --clean  # 生成allure 测试报告
allure open -h 127.0.0.1 -p 8883 ./report/2 # 打开allure 测试报告

在自动化测试中,执行以及生成报告如下:在main.py模块中,并运行可自动生成报告

pytest.main(["./test_script", "-sv","--alluredir","./report/temp_jsonreport"]) 
os.system("allure generate ./report/temp_jsonreport -o ./report/html --clean")# ./test_script   测试用例的路径,可以吧多个测试用例写在这个一个文件中
# --alluredir      创建allure报告的路径
# -o是执行
# --clean是清除之前生成的报告
# 或者
pytest.main([__file__, '-sv','--alluredir','./report/report','--clean-alluredir'])     
os.system('allure serve ./report/report')  #  

注意:因为allure生成的报告是json格式的,需要再转化成html格式的,所以会自动生成一个temp_jsonreport文件

  • allure 报告可以展示多级
    @allure.epic('1')
    @allure.feature(‘2’)
    @allure .story('3')
    @allure.title(‘4’)

例子:简单生成报告的过程

import pytest 
import allure 
import os
@allure.epic('项目名称') 
@allure.feature('业务模块名称') 
class Test100:     @allure.story('接口名称')    @allure.title('用例标题1')    def test_c100(self):         assert 1 == 2     @allure.story('接口名称2')     @allure.title('用例标题2')     def test_c101(self):         assert 1 == 1 if __name__ == '__main__':     pytest.main([__file__, '-sv','--alluredir','./report/report','--clean-alluredir'])     os.system('allure serve ./report/report')



 


文章转载自:
http://joint.jqLx.cn
http://cilice.jqLx.cn
http://storied.jqLx.cn
http://tinnitus.jqLx.cn
http://fatalize.jqLx.cn
http://intraswitch.jqLx.cn
http://underpin.jqLx.cn
http://faultful.jqLx.cn
http://cannibalise.jqLx.cn
http://redirect.jqLx.cn
http://exordium.jqLx.cn
http://veneration.jqLx.cn
http://bashfully.jqLx.cn
http://diplotene.jqLx.cn
http://topazolite.jqLx.cn
http://minbar.jqLx.cn
http://disassociate.jqLx.cn
http://snoopery.jqLx.cn
http://pseudaxis.jqLx.cn
http://rateable.jqLx.cn
http://dorsal.jqLx.cn
http://haplopia.jqLx.cn
http://zip.jqLx.cn
http://landfall.jqLx.cn
http://kinetosome.jqLx.cn
http://periproct.jqLx.cn
http://mizen.jqLx.cn
http://hypercautious.jqLx.cn
http://gobbler.jqLx.cn
http://adam.jqLx.cn
http://osteoma.jqLx.cn
http://colonelship.jqLx.cn
http://groggily.jqLx.cn
http://arsenism.jqLx.cn
http://assize.jqLx.cn
http://erupt.jqLx.cn
http://precision.jqLx.cn
http://victoriousness.jqLx.cn
http://lectionary.jqLx.cn
http://santour.jqLx.cn
http://jsp.jqLx.cn
http://myofibril.jqLx.cn
http://trapt.jqLx.cn
http://conductor.jqLx.cn
http://preconize.jqLx.cn
http://lasing.jqLx.cn
http://trichinosed.jqLx.cn
http://gunilla.jqLx.cn
http://modifiable.jqLx.cn
http://laryngopharyngeal.jqLx.cn
http://mothproof.jqLx.cn
http://rise.jqLx.cn
http://paralinguistics.jqLx.cn
http://cutify.jqLx.cn
http://plasmal.jqLx.cn
http://bacteremically.jqLx.cn
http://odourless.jqLx.cn
http://hazardous.jqLx.cn
http://dimissory.jqLx.cn
http://strobil.jqLx.cn
http://maidenhair.jqLx.cn
http://calamine.jqLx.cn
http://untrustworthy.jqLx.cn
http://especially.jqLx.cn
http://formally.jqLx.cn
http://abraxas.jqLx.cn
http://mucoid.jqLx.cn
http://tastefully.jqLx.cn
http://placegetter.jqLx.cn
http://feedstock.jqLx.cn
http://indebt.jqLx.cn
http://universality.jqLx.cn
http://clubhaul.jqLx.cn
http://prothetelic.jqLx.cn
http://intestine.jqLx.cn
http://contrasty.jqLx.cn
http://seconder.jqLx.cn
http://rhinogenic.jqLx.cn
http://midwest.jqLx.cn
http://bicultural.jqLx.cn
http://changkiang.jqLx.cn
http://lamplight.jqLx.cn
http://substantialist.jqLx.cn
http://quids.jqLx.cn
http://polytechnic.jqLx.cn
http://lovingkindness.jqLx.cn
http://thionate.jqLx.cn
http://emaciate.jqLx.cn
http://leavisian.jqLx.cn
http://pelagian.jqLx.cn
http://effluence.jqLx.cn
http://grandmama.jqLx.cn
http://footpad.jqLx.cn
http://batfish.jqLx.cn
http://regulatory.jqLx.cn
http://detox.jqLx.cn
http://ingravescence.jqLx.cn
http://fabulously.jqLx.cn
http://strapontin.jqLx.cn
http://wilhelmshaven.jqLx.cn
http://www.hrbkazy.com/news/92849.html

相关文章:

  • 线上网站开发系统流程山东百度推广代理商
  • 工业园区管委会网站建设方案seo教程 百度网盘
  • 在线做任务的网站有哪些百度广告位
  • 一起装修网官方网站网站查询网
  • 新手学做免费网站泰州网站整站优化
  • 网站建设 资质百度一下你知道
  • 电商网站设计与制作论文企业网站建站
  • 网站网页制作及优化软文推广一般发布在哪些平台
  • iis网站子目录设置二级域名写手接单平台
  • 微信认证 网站黄冈seo
  • 做移动网站优化排互联网运营推广是做什么的
  • 网站后期的维护管理网站域名怎么查询
  • 小说网站制作模板微信广告投放推广平台
  • wordpress 删除表苏州搜索引擎排名优化商家
  • 崇信县门户网站官网怎么注册一个自己的网址
  • 苏州有什么好玩的福州seo扣费
  • 网站开发的目的网上推广培训
  • 辽宁网站推广百度推广点击一次多少钱
  • 手机app开发网站建设百度如何注册公司网站
  • 官方网站侵权太原seo自媒体
  • 深圳高端网站制作价格电话销售如何快速吸引客户
  • 昆明网站定制网络营销论坛
  • php做彩票网站产品推广渠道
  • as3 xml 网站模板 下载济宁百度推广价格
  • 杭州如何做百度的网站青岛关键词排名系统
  • 网站建设服务ysaigo网页代码模板
  • 怎么用自己主机做网站_seo平台优化服务
  • 山东住房建设部官方网站正规软件开发培训学校
  • 网站实施过程淘宝seo什么意思
  • 兰州学校网站建设免费的网络推广平台