python nose测试框架中使用allure_report框架
在使用nose自带的xunit生成xml文件生成测试报告后,领导说报告不够炫,没有百分比效果,且在web自动化时的截图不美观,html很多情况下没有显示图片(nose框架截图方法这里),正好,allure_report报告框架满足所有要求。
一、介绍
这里可以查看官方信息,http://allure.qatools.ru/,报告还支持中文
还有前辈写的实践之路:https://testerhome.com/topics/5738
二、基于nose框架
从官网介绍中,我们可以得知,allure支持python nose框架
1) 安装:
nose下allure的插件官网:https://pypi.python.org/pypi/nose-allure-plugin
这里我们使用pip安装,安装过程中会自动安装pytest、lxml、six、eunum34等插件
C:\Users\Administrator>pip install nose-allure-plugin
目前只支持python2的版本,python3的同学请绕行
如果在安装过程中出现以下问题:
Building lxml version 3.8..
Building without Cython.
ERROR: 'xslt-config' 不是内部或外部命令,也不是可运行的程序
或批处理文件。 ...... Could not find function xmlCheckVersion in library libxml2. Is libxml2 insta
lled?
****************************************************************************
*****
error: command 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Common\\
Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status
可以指定lxml版本安装:
pip install lxml==3.6.
然后再次安装
pip install nose-allure-plugin
安装完成后,可以输入nosetests -h,可能看到以下几个参数,表示安装成功
--logdir=LOGDIR
--not-clear-logdir
--feature=FEATURE
--story=STORY
--issue=ISSUE
--severity=SEVERITY
2)使用
根据官网的例子熟悉下
import nose class TestBar(object): @nose.allure.severity(nose.allure.severity_level.CRITICAL)
def test_bar(self):
pass # custom severity
@nose.allure.severity("hard")
def test_bar(self):
pass
运行:
nosetests -v -s allure_learn.py --with-allure --logdir=tmp --severity="critical, hard"
这里的--logdir是产生xml文件的路径,如果是在windows下请更改格式,运行完成后,在--logdir下会产生对应的xml文件
3)在web自动化下生成截图的方法
这点是allure report最方便的地方,不用指定文件名自动生成截图
看以下脚本
import nose,sys
from selenium import webdriver
from allure.constants import AttachmentType class TestBar(): @classmethod
def setUpClass(cls):
cls.driver = webdriver.Firefox()
cls.driver.get("http://www.baidu.com") @nose.allure.severity(nose.allure.severity_level.CRITICAL)
def test_bar(self):
assert 1==2
nose.allure.attach('screenshot',self.driver.get_screenshot_as_png(), type= AttachmentType.PNG) # custom severity
@nose.allure.severity("hard")
def test_bar_xx(self):
assert 4==4
#nose.allure.attach('screenshot', self.driver.get_screenshot_as_png(), type='png') -----该方法错误
nose.allure.attach('screenshot', self.driver.get_screenshot_as_png(), type=AttachmentType.PNG)
运行后,我们可以看到在对应的目录下生成了报xml报告且还有截图文件
但这个代码不实用,我们在实际项目中,肯定是运行测试失败后才截图,成功就不截图
这里,使用tearDown方法,并判断用例成功与否,失败则截图,
def tearDown(self):
if sys.exc_info()[0]:
nose.allure.attach('screenshot',self.driver.get_screenshot_as_png(), type= AttachmentType.PNG)
4)集成进jenkins生成report
jenkins怎么安装,网管上也有说明,http://wiki.qatools.ru/display/AL/Allure+Jenkins+Plugin,这里不介绍
博主在linux下安装时,发现From Maven Central一项是空是,没有版本可以选择,查看后发现,是安装插件时,在jenkins updates文件夹下没有生成对应的文件,手工添加解决
在$jenkins_home/updates查看是否存在文件ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstaller,如果不存在,手工创建,并输入以下内容
{"list":[{"id":"2.2.1","name":"2.2.1","url":"https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.2.1/allure-2.2.1.zip"},{"id":"2.2.0","name":"2.2.0","url":"https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.2.0/allure-2.2.0.zip"},{"id":"2.1.1","name":"2.1.1","url":"https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.1.1/allure-2.1.1.zip"},{"id":"2.1.0","name":"2.1.0","url":"https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.1.0/allure-2.1.0.zip"},{"id":"2.0.1","name":"2.0.1","url":"https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.0.1/allure-2.0.1.zip"},{"id":"2.0.0","name":"2.0.0","url":"https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.0.0/allure-2.0.0.zip"},{"id":"1.5.4","name":"1.5.4","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.5.4/allure-commandline-1.5.4-standalone.zip"},{"id":"1.5.3","name":"1.5.3","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.5.3/allure-commandline-1.5.3-standalone.zip"},{"id":"1.5.2","name":"1.5.2","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.5.2/allure-commandline-1.5.2-standalone.zip"},{"id":"1.5.1","name":"1.5.1","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.5.1/allure-commandline-1.5.1-standalone.zip"},{"id":"1.5.0","name":"1.5.0","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.5.0/allure-commandline-1.5.0-standalone.zip"},{"id":"1.4.23.HOTFIX1","name":"1.4.23.HOTFIX1","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.23.HOTFIX1/allure-commandline-1.4.23.HOTFIX1-standalone.zip"},{"id":"1.4.23","name":"1.4.23","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.23/allure-commandline-1.4.23-standalone.zip"},{"id":"1.4.22","name":"1.4.22","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.22/allure-commandline-1.4.22-standalone.zip"},{"id":"1.4.21","name":"1.4.21","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.21/allure-commandline-1.4.21-standalone.zip"},{"id":"1.4.20","name":"1.4.20","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.20/allure-commandline-1.4.20-standalone.zip"},{"id":"1.4.19","name":"1.4.19","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.19/allure-commandline-1.4.19-standalone.zip"},{"id":"1.4.18","name":"1.4.18","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.18/allure-commandline-1.4.18-standalone.zip"},{"id":"1.4.17","name":"1.4.17","url":"https://oss.sonatype.org/content/repositories/releases/ru/yandex/qatools/allure/allure-commandline/1.4.17/allure-commandline-1.4.17.zip"}]}
再次查看,From Maven Central中有版本选择了
构建后说明:
这里的path是之前使用nosetests 生成xml时对应的文件夹,但文件夹又是基于job的工作空间的相对目录,写绝对目录是不行的
5)查看结果
生成完成后,可以产生这样的效果图:
点击查看:
在对应失败的用例下,有截图显示,
更新一下:
有同学在使用时,不想每次用jenkins来生成数据来查看报告,可以自行下载allure commandline工具,用以下方式来生成报告:
allure generate directory-with-results/ -o directory-with-report
生成完成后,点击index.html文件,发现数据未显示出来
原来少最做一步,要开启服务才可以查看,命令如下:
allure report open
如果还觉得麻烦的,还要在运行完测试用例后直接输入以下命令:
allure serve directory-results
其中dirceotry-results是你生成xml的路径
---------------------11.16更新------------------------
在实际使用时,allure在执行时会将report生成的截图和xml删除,有时候分步骤使用时,会是一个麻烦事,
所以在nose使用时,可以使用参数:
--not-clear-logdir
来避免清空文件夹,如下:
nosetests --with-allure --logdir=results --not-clear-logdir
然后在windows下时,运行完几个测试后,还需手工清除截图及xml,这里记录下bat使用:
del /s /Q allure-results
----表示:只删除文件而不能删除子文件夹
---------------------2018.1.9更新------------------------
又来更新了,allure在首页界面有个环境信息,本来我觉得用处不大,但是TMD运营又提需求,多环境同时跑时,最后出的报告要看出是什么环境跑的,正好allure正好有该功能,很简单,只要在代码中加入下面一行:
nose.allure.environment(URL='http://192.168.1.1', Username=u'huzhq',project=u'afdffd')
生成的报告就有该信息
python nose测试框架中使用allure_report框架的更多相关文章
- python nose测试框架全面介绍十---用例的跳过
又来写nose了,这次主要介绍nose中的用例跳过应用,之前也有介绍,见python nose测试框架全面介绍四,但介绍的不详细.下面详细解析下 nose自带的SkipTest 先看看nose自带的S ...
- python nose测试框架全面介绍七--日志相关
引: 之前使用nose框架时,一直使用--logging-config的log文件来生成日志,具体的log配置可见之前python nose测试框架全面介绍四. 但使用一段时间后,发出一个问题,生成的 ...
- python nose测试框架全面介绍六--框架函数别名
之前python nose测试框架全面介绍二中介绍了nose框架的基本构成,但在实际应该中我们也会到setup_function等一系列的名字,查看管网后,我们罗列下nose框架中函数的别名 1.pa ...
- Jenkins自动化构建python nose测试
[本文出自天外归云的博客园] 简介 通过Jenkins自动化构建python nose测试分两步: 1. 创建节点(节点就是执行自动化测试的机器): 2. 创建任务并绑定节点(用指定的机器来跑我们创建 ...
- php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中
php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中 1.phalcon框架的安装: phalcon框架在windows本地安装可以利用wamp软件,安装之后可以查看对应 ...
- 框架中的导航框架 & position定位
框架中,通过链接将一个页面显示在另一个框架中: 总框架: <frameset cols="15%,*"> <frame src="xx.html ...
- python nose测试框架全面介绍五--attr介绍
之前写了一系列nose框架的,这篇介绍下attr tag 在nose框架中attr用来标识用例,使得在运行时可以通过标识来执行用例,之前在nose测试框架全面介绍四中有说明,但没有说明清楚,这里再总结 ...
- python nose测试框架全面介绍三
三.nose的测试工具集 nose.tools模块提供了一系列的小工具,包括测试执行时间.异常输出及unittest框架中所有的assert功能. 为了使写用例更加容易,nose.tools提供了部分 ...
- python nose测试框架全面介绍八---接口测试中非法参数的断言
在测接口时,会有这样的场景,输入非法的参数,校验返回的错误码及错误内容 通常做法为发请求,将错误的返回结果拿出,再进行对比匹配:但存在一个问题,需要再写错误返回分析函数,不能与之前正常发请求的函数共用 ...
随机推荐
- UNIX环境编程学习笔记(22)——进程管理之system 函数执行命令行字符串
lienhua342014-10-15 ISO C 定义了 system 函数,用于在程序中执行一个命令字符串.其声明如下, #include <stdlib.h> int system( ...
- Java编程思想学习笔记——注解
前言 在Android开发的过程中,我们为了减少重复代码的编写,会使用类似ButterKnife,AndroidAnnotations 这类依赖注解库.代码示例如下: //不使用 Button btn ...
- MathType输入框怎么调整
在用MathType编辑公式编辑器时,除了可以对MathType工具栏的显示比例进行调整以外,还可以对编辑时的输入框进行调整.这样在编辑的过程中,工具栏可以看得很清楚,同时框输入框也可以看得很清楚,这 ...
- geoserver入门
1.什么是Universal Transverse Mercator system 翻译名叫做通用横轴魔卡托系统,通常称为UTM.这个投影系从中心子午线把世界分成一系列6度的纵向宽区域. 2.什么是w ...
- Centos7以上的版本 mysql 无法启动,无法停止问题
service mysqld start 始终提示如下: Failed to issue method call: Unit mysqld.service failed to load: No suc ...
- @PropertySource加载文件的两种用法以及配置文件加载顺序
第一种: 现在我把资源文件的路径放在application.properties里 config.path=/home/myservice/config.properties @PropertySou ...
- Springboot @webfilter @order filter过滤器
我们使用@WebFilter注解的时候发现注解里面没有提供可以控制执行顺序的参数 @WebFilter 的属性 属性名 类型 描述 filterName String 指定过滤器的 name 属性,等 ...
- logback -- 配置详解 -- 三 -- <encoder>
附: logback.xml实例 logback -- 配置详解 -- 一 -- <configuration>及子节点 logback -- 配置详解 -- 二 -- <appen ...
- Windows最全快捷键
单独按Windows:显示或隐藏“开始”功能表 Windows+BREAK:显示“系统属性” 对话框 Windows+D:显示桌面 Windows+M:最小化所有窗口 Windows+Shift+M: ...
- IDEA maven项目下测试mybatis例子,使用mappper class或package引入mapper映射文件,总是报错Invalid bound statement(所有配置完全正确)
困扰几个小时,终于查到解决办法及原因(可以直接到最后看解决方案) 环境就是用IDEA搭建的maven项目,主要jar包引入配置如下 <dependencies> <dependenc ...