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

网站logo源码sem优化推广

网站logo源码,sem优化推广,产品管理系统软件,查看网站建站时间前言 在编写自动化测试用例的时候经常会遇到需要编写流程性测试用例的场景,一般流程性的测试用例的测试步骤比较多,我们在测试用例中添加详细的步骤会提高测试用例的可阅读性。 allure提供的装饰器allure.step()是allure测试报告框架非常有用的功能&am…

前言

在编写自动化测试用例的时候经常会遇到需要编写流程性测试用例的场景,一般流程性的测试用例的测试步骤比较多,我们在测试用例中添加详细的步骤会提高测试用例的可阅读性。

allure提供的装饰器@allure.step()是allure测试报告框架非常有用的功能,它能帮助我们在测试用例中对测试步骤进行详细的描述。

@allure.step的使用例子:

实现一个购物的场景:1.登录;2.浏览商品;3.将商品加入到购物车中;4.下单;5.支付订单;

# file_name: test_allure_step.pyimport pytest
import allure@allure.step
def login():"""执行登录逻辑:return:"""print("执行登录逻辑")@allure.step
def scan_good():"""执行浏览商品逻辑:return:"""print("执行浏览商品逻辑")@allure.step
def add_good_to_shopping_car():"""将商品添加到购物车:return:"""print("将商品添加到购物车")@allure.step
def generator_order():"""生成订单:return:"""print("生成订单")@allure.step
def pay():"""支付订单:return:"""print("支付订单")def test_buy_good():"""测试购买商品:步骤1:登录步骤2:浏览商品步骤3:将商品加入到购物车中步骤4:下单步骤5:支付:return:"""login()scan_good()add_good_to_shopping_car()generator_order()pay()with allure.step("断言"):assert 1if __name__ == '__main__':pytest.main(['-s', 'test_allure_step.py'])

执行命令:

> pytest test_allure_step.py --alluredir=./report/result_data> allure serve ./report/result_data

查看测试报告展示效果:

image

从报告中可以看到,我们事先通过@allure.step()定义好的步骤都展示在测试用例test_buy_good()下了。

@allure.step支持嵌套,step中调用step

# file_name: steps.pyimport allure@allure.step
def passing_step_02():print("执行步骤02")pass

测试用例:

# file_name: test_allure_step_nested.pyimport pytest
import allurefrom .steps import passing_step_02  # 从外部模块中导入@allure.step
def passing_step_01():print("执行步骤01")pass@allure.step
def step_with_nested_steps():"""这个步骤中调用nested_step():return:"""nested_step()@allure.step
def nested_step_with_arguments(arg1, arg2):pass@allure.step
def nested_step():"""这个步骤中调用nested_step_with_arguments(),并且传递参数:return:"""nested_step_with_arguments(1, 'abc')def test_with_imported_step():"""测试@allure.step()支持调用从外部模块导入的step:return:"""passing_step_01()passing_step_02()def test_with_nested_steps():"""测试@allure.step()支持嵌套调用step:return:"""passing_step_01()step_with_nested_steps()passing_step_02()if __name__ == '__main__':pytest.main(['-s', 'test_allure_step_nested.py'])

执行命令:

pytest test_allure_step_nested.py --alluredir=./report/result_dataallure serve ./report/result_data

查看测试报告展示效果:

image

从上面的结果中可以看到:

  • @step可以先保存到其他模块中,在测试用例中需要用到的时候导入就可以了;
  • @step也支持在一个step中嵌套调用其他的step;嵌套的形式在测试报告中以树形展示出来了;

@allure.step支持添加描述且通过占位符传递参数

# file_name: test_allure_step_with_placeholder.pyimport pytest
import allure@allure.step('这是一个带描述语的step,并且通过占位符传递参数:positional = "{0}",keyword = "{key}"')
def step_title_with_placeholder(arg1, key=None):passdef test_step_with_placeholder():step_title_with_placeholder(1, key="something")step_title_with_placeholder(2)step_title_with_placeholder(3, key="anything")if __name__ == '__main__':pytest.main(['-s', 'test_allure_step_with_placeholder.py'])

执行命令:

pytest test_allure_step_with_placeholder.py --alluredir=./report/result_dataallure serve ./report/result_data

查看测试报告展示效果:

image

从上面的执行结果中可以看到,@allure.step()是支持输入描述的,并且支持通过占位符向描述中传递参数。

在conftest.py文件中定义@allure.step

conftest.py文件:

# file_name: conftest.pyimport pytest
import allure@pytest.fixture()
def fixture_with_conftest_step():conftest_step()@allure.step("这是一个在conftest.py文件中的step")
def conftest_step():pass

测试用例:

# file_name: test_allure_step_in_fixture_from_conftest.pyimport pytest
import allure@allure.step
def passed_step():passdef test_with_step_in_fixture_from_conftest(fixture_with_conftest_step):passed_step()if __name__ == '__main__':pytest.main(['-s', 'test_allure_step_in_fixture_from_conftest.py'])

执行命令:

pytest test_allure_step_in_fixture_from_conftest.py --alluredir=./report/result_dataallure serve ./report/result_data

查看测试报告展示效果:

从运行结果中可以看到,在fixture中定义的step会在setup和teardown单独以树形结构展示出来。

这可能是B站最详细的pytest自动化测试框架教程,整整100小时,全程实战!!!

http://www.hengruixuexiao.com/news/43133.html

相关文章:

  • 营销网站的问题与优势产品推广策划书
  • 网站制作如何做滚动字幕颜色百度推广竞价排名技巧
  • 哈尔滨营销型网站建设公司网销怎么做才能做好
  • 单位网站建设管理情况seo网站推广建站服务商
  • 做的比较好的法律实务培训网站网络营销流程
  • 网站优化有哪些优化大师免费下载安装
  • 在哪里学做网站代写平台在哪找
  • 正规绍兴网站建设公司竞价网络推广外包
  • 能用二级域名做网站吗seo营销推广平台
  • wordpress写文章教程seo网络推广员招聘
  • 天津创思佳网络网站制作公司北京网站优化体验
  • 免费php外贸网站模板手机关键词seo排名优化
  • 可以做羞羞的游戏视频网站百度2022第三季度财报
  • 网站开发虚拟主机是什么武汉最新今天的消息
  • 网站建设加盟代理视频号下载器手机版
  • 河南网站建设网络推广工作内容
  • 套模板的网站为什么排名做不上去市场营销策划方案案例
  • 优设网专利seo研究中心倒闭
  • flash网站的制作网络营销的方法包括哪些
  • 橱柜手机网站模板谷歌海外广告投放
  • wordpress图片在哪东莞关键词优化推广
  • 海南高端网站建设搜索引擎付费推广
  • 网站对应不同域名官方进一步优化
  • 电子商务网页设计与制作课后作业黑帽seo技术有哪些
  • 网络游戏那个网站做的最好关键词优化怎么优化
  • 网站建设衤金手指花总十五免费宣传平台有哪些
  • 建设公司网站价格免费seo在线优化
  • 防制网站怎么做网址创建
  • 中山网站建设文化友情链接交换
  • 东莞万江最新疫情seo模拟点击工具