标签:报告 __name__ == mat spl filename info abs 创建目录
现有几个jmeter脚本,准备以命令行的方式执行jmeter脚本,并生成报告。
一、使用python语言处理
1、目录结构

2、说明
jmx目录下是jmeter脚本
result目录下是生成的报告及文件
jtl目录下是执行过程中生成的jtl文件,jtl文件名不能重复,所以给jtl文件以时间戳命令
report目录下是生成的报告,在report目录下自动给每个脚本创建目录,创建的目录下存放以时间戳命令的报告
3、代码
import os
import time
def dir_is_exists(path):
    if not os.path.exists(path):
        os.mkdir(path)
def run():
    jtl_dir_path = os.path.abspath("./result/jtl")   # jtl文件存放目录
    dir_is_exists(jtl_dir_path)
    jmx_dir_path = "./jmx"   # jmeter脚本存放路径
    dir_is_exists(jmx_dir_path)
    report_path = "./result/report"   # jmeter生成的测试报告存放路径
    dir_is_exists(report_path)
    for file in os.listdir(jmx_dir_path):
        file_name, etc = os.path.splitext(file)
        jmx_path = os.path.join(os.path.abspath(jmx_dir_path), file)
        jmx_report_path = os.path.join(report_path, file_name)
        dir_is_exists(jmx_report_path)
        current_time = time.strftime("%Y%m%d%H%M%S", time.localtime())
        currentReport = os.path.join(os.path.abspath(jmx_report_path), current_time)
        jtl_path = os.path.join(jtl_dir_path, "{}.jtl".format(current_time))
        cmd_jmx = "jmeter -n -t {} -l {} -e -o {}".format(jmx_path, jtl_path, currentReport)
        print(cmd_jmx)
        os.system(cmd_jmx)
if __name__ == ‘__main__‘:
    run()
4、接口自动化结果展示
生成的文件

报告展示

二、使用bat脚本处理
1、目录结构

2、说明
目录结构和上面的相似
code目录下是jmx脚本
result目录下是生成 的结果文件,report目录和jtl目录
3、bat脚本
 
@echo off set filename=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2% set "filename=%filename: =0%" echo %filename% d: cd D:\software\apache-jmeter-4.0\bin jmeter -n -t D:\code\jmeter-code\code\1001.jmx -l D:\code\jmeter-code\result\jtl\%filename%.jtl -e -o D:\code\jmeter-code\result\report\%filename%
4、结果

报告都一样,一个模板,不发了
对bat脚本运用没有python语言熟练,这是简单尝试,以后熟练了再更新
标签:报告 __name__ == mat spl filename info abs 创建目录
原文地址:https://www.cnblogs.com/sleep10000years/p/12376340.html