文章目录
前言
- 本篇来学习下allure插件的使用吧
安装插件
- Manage Jenkins --> Manage Plugins --> 可选插件 --> 搜索 allure --> 安装好记得重启Jenkins
前置条件
- 已安装jdk:安装可参考 Java环境搭建
- 已安装allure:安装可参考 allure环境搭建
准备代码
- 新建test_01.py,代码如下
# -*- coding: utf-8 -*-
# @Author : 大海
import os
import allure
import pytest
'''
场景:商品添加购物车,结算支付成功。
用例步骤:1.登陆 2.商品添加购物车 3.生成订单 4.支付成功
'''
@allure.step('前置操作:登录')
def login(username, password):
"""登录"""
print(f"前置操作:登陆成功!{username}{password}")
@allure.step("step1:商品添加购物车")
def add_shopping_cart(goods_id):
"""添加购物车"""
print(f"添加购物车{goods_id}")
@allure.step("step2:生成订单")
def create_order():
"""生成订单"""
print("create_order:生成订单")
@allure.step("step3:支付")
def pay_money():
"""支付"""
print("pay:支付!")
@pytest.fixture(scope="session")
def login_setup():
login("大海", "123456")
@allure.feature("购物模块")
@allure.story("登录用户可购买商品")
@allure.title("登录用户,添加商品到购物车,下单支付成功。")
def test_add_goods_and_buy_(login_setup):
"""
用例描述:
前置:登陆
用例步骤:1.添加购物车 2.生成订单 3.支付成功
"""
# 商品添加购物车
add_shopping_cart(goods_id=1018)
# 生成订单
create_order()
# 支付
pay_money()
with allure.step("断言支付状态为true"):
status = True
assert status
if __name__ == '__main__':
os.system('pytest -s test_01.py --alluredir ./report/allure_raw')
os.system('allure generate -c -o ./allure-report ./report/allure_raw')
配置环境变量
配置JDK
- Manage Jenkins --> Global Tool Configuration
配置allure
- Mange Jenkins --> Global Tool Configuration
Pipeline
pipeline {
agent any
stages {
stage('checkout code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/分支']], extensions: [], userRemoteConfigs: [[credentialsId: '秘钥id', url: '你的仓库地址']]])
}
}
stage('auto test') {
steps {
bat 'python test_01.py'
}
}
}
post {
success {
// 注意报告地址写相对路径,也就是--alluredir后面的路径,如我的报告路径:report/allure_raw,但不要写成 /report/allure_raw
allure includeProperties: false, jdk: 'jdk1.8', results: [[path: 'report/allure_raw']]
}
}
}
查看报告