windows环境下批处理文件方案

1:window机器上创建一个 .bat 结尾的批处理文件

@echo off
echo 袁大总统接口自动化运行准备开始......
@echo on

del /f /s /q G:\SongQin\Python\Demo\teach_sq\report\tmp\*.json
del /f /s /q G:\SongQin\Python\Demo\teach_sq\report\tmp\*.jpg
del /f /s /q G:\SongQin\Python\Demo\teach_sq\report\report

@echo off
echo 环境文件删除工作完成,开始运行脚本......
@echo on

cd G:/SongQin/Python/Demo/teach_sq/test_case
pytest -sq --alluredir=../report/tmp
allure serve ../report/tmp

@echo off
echo 接口自动化运行成功
pause

2:运行模式

1- 使用 终端(win/linux)运行: python -m run.py
2- 使用执行文件运行: run.bat(Win) ; run.sh(Linux) 运行指令 ./run.sh
3- jenkins运行 会使用自带的 sh 功能运行

3:获取项目工程路径  【python代码版本】

"""
在一些代码里使用相对路径会报文件找不到!
../data/xxxxxx
解决方案:
通过代码自动获取当前运行项目的路径:
"""
import os   #
print(__file__)      # 当前运行文件的路径
print(os.path.realpath(__file__))    #当前运行文件的绝对路径
project_path = os.path.split(os.path.realpath(__file__))[0].split('configs')[0]
print(project_path)  # 项目路径

4:接口自动化之 Allure 报告优化

1:浏览器打开allure报告:建议使用火狐浏览器- 谷歌是loading和404 不要用chrome,ie浏览器打开
2、定制化标签
    @allure.epic("外卖系统")
    @allure.feature("商铺模块")
    @allure.tag("核心关注")
3:allure用例描述
    使用方法                   参数值             参数说明
   @allure.epic()             epic描述          敏捷里面的概念,定义史诗,往下是feature
   @allure.feature()           模块名称          功能点的描述,往下是story
   @allure.story()            用户故事          用户故事,往下是title
   @allure.title(用例的 标题)       用例的 标题         重命名html报告名 称
   @allure.testcase()           测试用 例的链 接地址 对应功能测试用例 系统里面的case  
   @allure.issue()             缺陷             对应缺陷管理系统 里面的链接
   @allure.description()         用例描 述           测试用例的描述
   @allure.step()              操作步 骤           测试用例的步骤
   @allure.severity()           用例等 级            blocker,critical, normal,minor, trivial
   @allure.link()              链接 定义一个链接,      在 测试报告展现
   @allure.attachment()          附件              报告添加附件
import pytest
import allure
@allure.feature(
'这里是一级标签') class TestAllure():   @allure.title("用例标题0")   @allure.story("这里是第一个二级标签")   @allure.title("用例标题1")   @allure.story("这里是第二个二级标签")   def test_1(self):     allure.attach.file(r'E:\Myproject\pytest-allure\test\test_1.jpg' ,
      '我是附件截图的名字', attachment_type=allure.attachment_type.JPG)   @allure.title("用例标题2")   @allure.story("这里是第三个二级标签") @allure.severity("critical") @allure.description("这里只是做一个web ui自动化的截图效果")
设置用例级别:
pytest -sq --alluredir=../report/tmp --allure-severities=normal,critical
pytest -sq ywt001.py --alluredir=../report/tmp --allure-severities=normal,critical    windows的cmd命令这样运行
import pytest
import allure
'''
@allure.severity装饰器按严重性级别来标记case
执行指定测试用例 --allure-severities
blocker
BLOCKER = 'blocker' 阻塞缺陷
CRITICAL = 'critical' 严重缺陷
NORMAL = 'normal' 一般缺陷
MINOR = 'minor' 次要缺陷
TRIVIAL = 'trivial' 轻微缺陷
'''
@allure.severity("normal")
def test_case_1():
  '''修改个人信息-sex参数为空'''
  print("test case 11111111")
@allure.severity(
"critical") def test_case_2():'''修改个人信息-sex参数传F和M两种类型,成功(枚举类型)'''   print("test case 222222222")
@allure.severity(
"critical") def test_case_3(): '''修改个人信息-修改不是本人的用户信息,无权限操作'''   print("test case 333333333")
@allure.severity(
"blocker") def test_case_4(): '''修改个人信息-修改自己的个人信息,修改成功'''   print("test case 4444444")
def test_case_5(): '''没标记severity的用例默认为normal'''   print("test case 5555555555")

 5:设置allure显示环境

在Allure报告中添加环境信息,通过创建 environment.properties 或者environment.xml文件,
  并把文件存放到allure
-results(这个目录是生成最后的html报告之前,生成依赖文件的目录)目录下 environment.properties    文件,内容如下   Browser=Firefox   Browser.Version=77   Stand=songqin_teach   ApiUrl=127.0.0.1/login   python.Version=3.6

 

posted @ 2023-07-12 23:16  至高无上10086  阅读(29)  评论(0编辑  收藏  举报