系部网站开发计划书,wordpress的多站点网站无法访问,网址缩短在线生成app,为什么做网站更新Allure测试报告框架帮助你轻松实现”高大上”报告展示。本文通过示例演示如何从0到1集成Allure测试框架。重点展示了如何将Allure集成到已有的自动化测试工程中、以及如何实现报表的优化展示。Allure非常强大#xff0c;支持多种语言多种测试框架#xff0c;无论是Java/Pytho…Allure测试报告框架帮助你轻松实现”高大上”报告展示。本文通过示例演示如何从0到1集成Allure测试框架。重点展示了如何将Allure集成到已有的自动化测试工程中、以及如何实现报表的优化展示。Allure非常强大支持多种语言多种测试框架无论是Java/Python还是Junit/TestNG其他语言或者框架实现的流程和本文一致具体配置参照各语言框架规范 
安装 
安装allure 
Windows用户 
scoop install allure    需要先下载并安装Scoop该方法无需配置环境变量 
MAC用户 
通过Homebrew进行自动安装brew install allure   如果Homebrew版本比较旧需要先升级Homebrew否则安装的allure版本也很老可能会与Python插件不兼容 
手动安装 
可以从官网 Central Repository: io/qameta/allure/allure-commandline 手动下载目前最新版本为2.13.6    下载后解压并配置环境变量 
安装allure-pytest插件 
pip install allure-pytest 
allure常用特性 
希望在报告中看到测试功能子功能或场景测试步骤包括测试附加信息可以使用feature,story,step,attach 
步骤 
import allure功能上加allure.feature(功能名称)子功能上加allure.story(子功能名称)步骤上加allure.step(步骤细节)allure.attach(具体文本信息)需要附加的信息可以是数据文本图片视频网页如果只测试部分功能运行的时候可以加限制过滤 pytest 文件名 --allure-features 需要运行的功能名称 
allure特性—feature/story 
allure.feature与allure.store的关系 
feature相当于一个功能一个大的模块将case分类到某个feature中报告中在behaviore中显示相当于testsuitestory相当于对应这个功能或者模块下的不同场景分支功能属于feature之下的结构报告在features中显示相当于testcasefeature与story类似于父与子关系 
step特性 
测试过程中每个步骤一般放在具体逻辑方法中可以放在关键步骤中在报告中显示在app,web自动化测试中建议每切换到一个新的页面当做一个step用法 allure.step() 只能以装饰器的形式放在类或方法上面with allure.step():  可以放在测试用例方法里面但测试步骤的代码需要被该语句包含 
运行 在测试执行期间收集结果 pytest [测试文件] -s -q --alluredir./result --clean-alluredir 
--alluredir这个选项用于指定存储测试结果的路径--clean-alluredir 这个选项用来清除之前生成的结果 
查看测试报告 方法一测试完成后查看实际报告在线看报告会直接打开默认浏览器展示当前报告 allure serve ./result 方法二从结果生成报告这是一个启动tomcat的服务需要两个步骤 生成报告 allure generate ./result -o ./report --clean   (注意--clean用来清除之前已生成的报告) 打开报告 allure open -h 127.0.0.1 -p 8883 ./report   该方法直接生成一个tomcat服务可远程访问 
举个例子 
有如下代码文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60  #!/usr/bin/python # -*- coding: UTF-8 -*-  author:chenshifeng file:test_allure.py time:2020/10/10  import allure import pytest   allure.feature(登录模块) class TestLogin():     allure.story(登录成功)     allure.title(登录成功标题)     def test_login_sucess(self):         with allure.step(步骤1打开应用):             print(应用已打开)         with allure.step(步骤2进入登录页面):             print(登录页面已打开)         with allure.step(步骤3输入用户名和密码):             print(用户名和密码输入成功)         print(登录测试用例登录成功)      allure.story(登录成功)     def test_login_sucess2(self):         assert 1  1         print(登录测试用例登录成功)      allure.story(登录失败)     def test_login_failure_a(self):         print(登录测试用例登录失败用户名缺失)      allure.story(登录失败)     def test_login_failure_b(self):         print(登录测试用例登录失败密码缺失)      allure.story(登录失败)     def test_login_failure_c(self):         with allure.step(输入用户名):             print(已输入用户名)         with allure.step(输入密码):             print(已输入密码)         with allure.step(点击登录):             print(已点击登录)         print(登录测试用例登录失败密码错误)   allure.feature(搜索模块) class TestSearch():     def test_search1(self):         print(搜索用例1)      TEST_CASE_LINK  https://mirrors.huaweicloud.com/     allure.testcase(TEST_CASE_LINK,测试用例连接)     def test_search2(self):         print(搜索用例2)     allure.step(搜索步骤)     def test_search3(self):         print(搜索用例3)  
依次执行命令  pytest test_allure.py --alluredir./result --clean-alluredir allure serve ./result 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_allure.py --alluredir./result --clean-alluredir  test session starts  platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.ini plugins: allure-pytest-2.8.18 collected 8 items                                                                                                                                                              test_allure.py .F......                                                                                                                                                 [100%]   FAILURES  ________________________________________________________________________ TestLogin.test_login_sucess2 _________________________________________________________________________  self  test_allure.TestLogin object at 0x7fef3d5cba90      allure.story(登录成功)     def test_login_sucess2(self):        assert 1  1 E       AssertionError: assert 1  1  test_allure.py:27: AssertionError  short test summary info  FAILED test_allure.py::TestLogin::test_login_sucess2 - AssertionError: assert 1  1  1 failed, 7 passed in 0.07s  chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result Generating report to temp directory... Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/7024790777193223986/allure-report Starting web server... 2020-10-13 21:39:56.174:INFO::main: Logging initialized 6818ms to org.eclipse.jetty.util.log.StdErrLog Server started at http://192.168.12.100:58977/. Press CtrlC to exit  
生成的报告 allure特性-testcase 
关联测试用例可以直接给测试用例的地址链接 
例子 1 2 3 4  TEST_CASE_LINK  https://mirrors.huaweicloud.com/ allure.testcase(TEST_CASE_LINK,测试用例连接) def test_search(self):     print(搜索用例)  按重要性级别进行一定范围测试 
通常测试有P0、冒烟测试、验证上线测试。按重要性级别来执行的比如上线要把主流程和重要模块都跑一遍可通过以下方法解决 
通过附加pytest.mark标记 
通过allure.feature,allure.story 
也可以通过allure.severity来附加标记 
级别trivial:不重要轻微缺陷必输项无提示或者提示不规范minor 不太重要次要缺陷界面错误与UI需求不符normal:正常问题普通缺陷数值计算错误critical:严重临界缺陷功能点缺失blocker:阻塞中断缺陷客户端程序无响应无法执行下一步操作 
使用方法 在方法、函数和类上面加 allure.severity(allure.severity_level.TRIVIAL) 
执行: pytest -s -v 文件名 --allure-severities normal,critical 
举例说明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57  #!/usr/bin/python # -*- coding: UTF-8 -*-  author:chenshifeng file:test_severity.py time:2020/10/11  import allure import pytest   # 不加任何标记,默认normal def test_with_no_severity():     pass   # trivial:不重要轻微缺陷必输项无提示或者提示不规范 allure.severity(allure.severity_level.TRIVIAL) def test_with_trivial_severity():     pass   # minor 级别 不太重要次要缺陷界面错误与UI需求不符 allure.severity(allure.severity_level.MINOR) def test_with_minor_severity():     pass   # normal:正常问题普通缺陷数值计算错误 allure.severity(allure.severity_level.NORMAL) def test_with_normal_severity():     pass   # critical:严重临界缺陷功能点缺失 allure.severity(allure.severity_level.CRITICAL) def test_with_ritical_severity():     pass   # blocker:阻塞中断缺陷客户端程序无响应无法执行下一步操作 allure.severity(allure.severity_level.BLOCKER) def test_with_blocker_severity():     pass   allure.severity(allure.severity_level.NORMAL) class TestClassWithNormalSeverity(object):      # 不加任何标记默认为同class级别     def test_inside_with_normal_severity(self):         pass      # 重新设置了critical级别     allure.severity(allure.severity_level.CRITICAL)     def test_inside_with_critical_severity(self):         pass  
执行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_severity.py --alluredir./result --clean-alluredir -vs  test session starts  platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python3.9 cachedir: .pytest_cache rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.ini plugins: allure-pytest-2.8.18 collected 8 items                                                                                                                                                              test_severity.py::test_with_no_severity PASSED test_severity.py::test_with_trivial_severity PASSED test_severity.py::test_with_minor_severity PASSED test_severity.py::test_with_normal_severity PASSED test_severity.py::test_with_ritical_severity PASSED test_severity.py::test_with_blocker_severity PASSED test_severity.py::TestClassWithNormalSeverity::test_inside_with_normal_severity PASSED test_severity.py::TestClassWithNormalSeverity::test_inside_with_critical_severity PASSED   8 passed in 0.03s  chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result Generating report to temp directory... Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/17788207943997663035/allure-report Starting web server... 2020-10-13 22:27:49.842:INFO::main: Logging initialized 6620ms to org.eclipse.jetty.util.log.StdErrLog Server started at http://192.168.12.100:59696/. Press CtrlC to exit  终极用例 
百度搜索 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30  #!/usr/bin/python # -*- coding: UTF-8 -*-  author:chenshifeng file:test_baidudemo.py time:2020/10/13  import pytest import allure from selenium import webdriver import time  allure.testcase(https://www.github.com) allure.feature(百度搜索) pytest.mark.parametrize(test_data1,[allure,pytest,unittest]) def test_steps_demo(test_data1):     with allure.step(打开百度网页):         driverwebdriver.Chrome()         driver.get(http://www.baidu.com)         driver.maximize_window()     with allure.step(f输入搜索词{test_data1}):         driver.find_element_by_id(kw).send_keys(test_data1)         time.sleep(2)         driver.find_element_by_id(su).click()         time.sleep(2)     with allure.step(保存图片):         driver.save_screenshot(./screenshot/baidu.png)         allure.attach.file(./screenshot/baidu.png,attachment_typeallure.attachment_type.PNG)     with allure.step(关闭浏览器):         driver.quit()  
执行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  chenshifengdeMacBook-Pro:testcode chenshifeng$ pytest test_baidudemo.py --alluredir./result --clean-alluredir -vs  test session starts  platform darwin -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python3.9 cachedir: .pytest_cache rootdir: /Users/chenshifeng/MyCode/PythonCode/SFDSZL/test_pytest, configfile: pytest.ini plugins: allure-pytest-2.8.18 collected 3 items                                                                                                                                                              test_baidudemo.py::test_steps_demo[allure] PASSED test_baidudemo.py::test_steps_demo[pytest] PASSED test_baidudemo.py::test_steps_demo[unittest] PASSED   3 passed in 24.65s  chenshifengdeMacBook-Pro:testcode chenshifeng$ allure serve ./result Generating report to temp directory... Report successfully generated to /var/folders/p0/3_7fwrvx6n3ftpfd4wjb01300000gn/T/18005664130273264423/allure-report Starting web server... 2020-10-13 23:03:39.221:INFO::main: Logging initialized 7360ms to org.eclipse.jetty.util.log.StdErrLog Server started at http://192.168.12.100:60775/. Press CtrlC to exit  
报告 总结 
感谢每一个认真阅读我文章的人 
作为一位过来人也是希望大家少走一些弯路如果你不想再体验一次学习时找不到资料没人解答问题坚持几天便放弃的感受的话在这里我给大家分享一些自动化测试的学习资源希望能给你前进的路上带来帮助。 软件测试面试文档 
我们学习必然是为了找到高薪的工作下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料并且有字节大佬给出了权威的解答刷完这一套面试资料相信大家都能找到满意的工作。 视频文档获取方式 这份文档和视频资料对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴我走过了最艰难的路程希望也能帮助到你以上均可以分享点下方小卡片即可自行领取。