allure安装&使用

allure在linux环境的安装

首先在本机安装jdk8以上版本,以及 npm
安装allure服务:npm install -g allure-commandline --save-dev
python安装allure库:sudo pip3 install allure-python-commons
python安装pytest的allure插件库:sudo pip3 install allure-pytest
此时运行:allure 应该会有相关的帮助指引,若报错则未安装成功

allure使用

命令行参数

qydev012@qydev012:~/workspace/uiautotest$ allure --help
Usage: allure [options] [command] [command options]
  Options:
    --help
      Print commandline help.
    -q, --quiet
      Switch on the quiet mode.
      Default: false
    -v, --verbose
      Switch on the verbose mode.
      Default: false
    --version
      Print commandline version.
      Default: false
  Commands:
    generate      Generate the report
      Usage: generate [options] The directories with allure results
        Options:
          -c, --clean
            Clean Allure report directory before generating a new one.
            Default: false
          --config
            Allure commandline config path. If specified overrides values from 
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses 
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
          -o, --report-dir, --output
            The directory to generate Allure report into.
            Default: allure-report

    serve      Serve the report
      Usage: serve [options] The directories with allure results
        Options:
          --config
            Allure commandline config path. If specified overrides values from 
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses 
            ALLURE_HOME directory.
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0
          --profile
            Allure commandline configuration profile.

    open      Open generated report
      Usage: open [options] The report directory
        Options:
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0

    plugin      Generate the report
      Usage: plugin [options]
        Options:
          --config
            Allure commandline config path. If specified overrides values from 
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses 
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.

常用的几个参数解读

  • options:
    • -q 安静模式,默认关闭 开启后 将会有allure从源文件-生成文件过程中的日志
    • -v 日志模式,默认关闭 开启后 将会有详细的日志
    • --version 版本 可单独使用
image.png
  • Commands:
    • generate 把源文件生成report
      • options:
        • -c & --clean 在生成新的Allure报告目录之前,清除该目录。(tips:清除的是生成目录,注意源文件不能和生成目录一个地址)
        • -o & --report-dir & --output 输出report文件地址
    • serve 临时利用源文件启动report服务
      • -h & --host 临时服务host
      • -p & --port 临时服务port

常用生成report语法

allure  generate 源文件 -o 输出文件 --clean # 源文件 != 输出文件
allure serve 源文件  # 临时使用

代码使用


标记用例

    @allure.feature("")  # 标记特性场景(大功能模块类级)
    @allure.story("")  # 次于feature的标记用例(分支模块函数级)
第一层为feature,第二层为story

image.png

用例步骤

方法一:用作装饰器在function上

    @allure.step("用例步骤")
    def func():
        pass

方法二:分步步骤,在代码块中

    with allure.step(""):
        pass  # 代码块

缺陷等级

1)blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)
2)critical级别:临界缺陷(功能点缺失)
3)normal级别:正常 默认为这个级别
4)minor级别:次要缺陷(界面错误与UI需求不符)
5)trivial级别:轻微缺陷(必输项无提示,或者提示不规范)

级别 描述
blocker 中断缺陷
critical 功能缺陷
minor 次要缺陷
trivial 轻微缺陷
normal 正常
    @allure.severity("blocker")
    def func():
        pass
未声明优先级

附加信息

 allure.attach(body, name=None, attachment_type=None, extension=None)
参数 描述
body 数据
name 附件名称
attachment_type 附件类型
extension 后缀名

附件类型

类型 类型值
文本 allure.attachment_type.TEXT
CSV allure.attachment_type.CSV
图片 allure.attachment_type.JPG或PNG
PDF allure.attachment_type.PDF
html文件 allure.attachment_type.HTML
json文件 allure.attachment_type.JSON
xml文件 allure.attachment_type.XML
mp4 allure.attachment_type.MP4
    def test_login_failed(self, init_driver, data):
    driver = lp(init_driver)
    with allure.step("步骤一登录"):
        driver.login(data["account"], data["password"])
    with allure.step("步骤二拿content"):
        content = driver.get_login_content()
    allure.attach(content, "实际结果")
    allure.attach(data["content"], "预期结果")  # 可以用来存放图片
    assert content == data["content"]
    
    # 添加照片附件
    with open(r"2.jpg","rb") as file:          #先打开图片
        file=file.read()           #读取图片
    allure.attach(file,"预期结果",attachment_type=allure.attachment_type.JPG) 


attach图中打错了

其他

    #
    allure.link(url, link_type=LinkType.LINK, name=None)
    allure.testcase(url, name=None)  # 对应的用例
    allure.issue(url, name=None)  # 这里传的是一个连接,记录的是你的问题

结合pytest生成源文件

pytest.main使用

    pytest.main("--alluredir=path")  # path 为路径

命令行使用

    pytest --alluredir=path  # path 为路径

效果图

index
testsuite
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容