在使用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框架的更多相关文章

  1. python nose测试框架全面介绍十---用例的跳过

    又来写nose了,这次主要介绍nose中的用例跳过应用,之前也有介绍,见python nose测试框架全面介绍四,但介绍的不详细.下面详细解析下 nose自带的SkipTest 先看看nose自带的S ...

  2. python nose测试框架全面介绍七--日志相关

    引: 之前使用nose框架时,一直使用--logging-config的log文件来生成日志,具体的log配置可见之前python nose测试框架全面介绍四. 但使用一段时间后,发出一个问题,生成的 ...

  3. python nose测试框架全面介绍六--框架函数别名

    之前python nose测试框架全面介绍二中介绍了nose框架的基本构成,但在实际应该中我们也会到setup_function等一系列的名字,查看管网后,我们罗列下nose框架中函数的别名 1.pa ...

  4. Jenkins自动化构建python nose测试

    [本文出自天外归云的博客园] 简介 通过Jenkins自动化构建python nose测试分两步: 1. 创建节点(节点就是执行自动化测试的机器): 2. 创建任务并绑定节点(用指定的机器来跑我们创建 ...

  5. php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中

    php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中 1.phalcon框架的安装: phalcon框架在windows本地安装可以利用wamp软件,安装之后可以查看对应 ...

  6. 框架中的导航框架 & position定位

    框架中,通过链接将一个页面显示在另一个框架中:   总框架: <frameset cols="15%,*">   <frame src="xx.html ...

  7. python nose测试框架全面介绍五--attr介绍

    之前写了一系列nose框架的,这篇介绍下attr tag 在nose框架中attr用来标识用例,使得在运行时可以通过标识来执行用例,之前在nose测试框架全面介绍四中有说明,但没有说明清楚,这里再总结 ...

  8. python nose测试框架全面介绍三

    三.nose的测试工具集 nose.tools模块提供了一系列的小工具,包括测试执行时间.异常输出及unittest框架中所有的assert功能. 为了使写用例更加容易,nose.tools提供了部分 ...

  9. python nose测试框架全面介绍八---接口测试中非法参数的断言

    在测接口时,会有这样的场景,输入非法的参数,校验返回的错误码及错误内容 通常做法为发请求,将错误的返回结果拿出,再进行对比匹配:但存在一个问题,需要再写错误返回分析函数,不能与之前正常发请求的函数共用 ...

随机推荐

  1. Peckham添加引用文件模糊匹配智能提示

    下载地址:https://github.com/markohlebar/Peckham ​ 跟VVDocumenter规范注释生成器的安装方式一样: 下载开源工程在Xcode重新编译运行会自动安装此插 ...

  2. 数据库事务MTDC出错解决办法

    Communication with the underlying transaction manager has failed 与基础事务管理器的通信失败 排除步驟: 1.檢查MS DTC 設置.[ ...

  3. 阿里云提出的漏洞(Phpcms V9某处逻辑问题导致getshell漏洞解决方法)的问题

    最近从阿里云云盾检测流出来的,相比使用阿里云服务器的朋友已经收到漏洞提醒:Phpcms V9某处逻辑问题导致getshell漏洞解决方法,这个漏洞怎么办呢?CMSYOU在这里找到针对性解决办法分享给大 ...

  4. 【java】 java SPI

    SPI(Service provider interface)是旨在由第三方实现或扩展的API.它可以用于启用框架扩展和可替换组件. 服务是一组众所周知的接口或(通常是抽象的)类.服务提供者是服务的特 ...

  5. 浅谈Java的学习

    Java就是用来做项目的!Java的主要应用领域就是企业级的项目开发!要想从事企业级的项目开发,你必须掌握如下要点: 1.掌握项目开发的基本步骤2.具备极强的面向对象的分析与设计技巧3.掌握用例驱动. ...

  6. ios开发之 -- NSString指定字体高亮显示

    一个简单的小需求,就是在一个字符串里面,指定一部分字节高亮显示,代码如下: NSString *descStr = @"需要高亮显示的字符"; NSString *nickStr ...

  7. PyCharm使用Github管理代码

    本篇文章主要写一下如何通过pycharm客户端来上传下载代码. 安装Git 在Windows上使用Git,可以从Git官网直接下载安装程序,(网速慢的同学请移步国内镜像),然后按默认选项安装即可. 安 ...

  8. 【代码审计】iZhanCMS_v2.1 后台存在多个SQL注入漏洞分析

      0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...

  9. 【代码审计】CLTPHP_v5.5.3后台任意文件删除漏洞分析

      0x00 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chich ...

  10. VMware 14 的永久许可密钥

    VMware workstation 14永久激活密钥分享: CG54H-D8D0H-H8DHY-C6X7X-N2KG6 ZC3WK-AFXEK-488JP-A7MQX-XL8YF AC5XK-0ZD ...