postman脚本生成可执行文件(6)

一.通过Python脚本(executescript.py)执行newman指令

javascript 复制代码
#!usr/bin/python
import subprocess
from datetime import datetime

class Newman_automate():
    '''
    Newman_automate():该类主要是定义postman脚本执行
    __path:cmd命令行中执行newnan脚本指令(1.不包括测试报告文件名;2.文件路径要专义)
    '''
    __path='newman run C:\\Users\\ZhuQing\\OneDrive\\桌面\\postman\\JSONcrip -r html --reporter-html-export  C:\\Users\\ZhuQing\\OneDrive\\桌面\\postman\\'
    def file_name(self):
        '''
        :file_name()函数定义测试报告文件名(文件名以日期命名)
        :return:文件名
        '''
        try:
            now_date=datetime.now().strftime("%Y-%m-%d_%H%M%S")+'.html'
            return now_date
        except Exception as ex:
            print(ex)
    def newman_order(self):
        '''
        ;newman_order()该函数定义通过cmd命令行执行的newman完整指令
        :return: 返回newman完整指令
        '''
        try:
            filename =self.__path+Newman_automate.file_name(self)
            # print(filename)
            return filename
        except Exception as ex:
            print(ex )
    def open_cmd(self):
        '''
        :open_cmd():该函数主要是打开cmd窗口并执行指令
        :param newman:指令
        :return:
        '''
        try:
            filename =Newman_automate.newman_order(self)
            # print('文件路径;',filename)
            subprocess.call(filename,shell=True)
        except Exception as ex:
            print(ex)

if __name__=="__main__":
    c=Newman_automate()
    c.open_cmd()

二.打包executescript.py文件(即生成可执行文件)

1.在executescript.py文件夹内执行打包指令:pyinstaller -F executescript.py

javascript 复制代码
D:\Python_stady>pyinstaller -F executescript.py


补充:

1...pyinstaller打包安装

2.定时执行postman脚本

3.测试报告内容如下:

相关推荐
寻星探路3 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
ValhallaCoder5 小时前
hot100-二叉树I
数据结构·python·算法·二叉树
猫头虎6 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
八零后琐话7 小时前
干货:程序员必备性能分析工具——Arthas火焰图
开发语言·python
青春不朽5128 小时前
Scrapy框架入门指南
python·scrapy
MZ_ZXD0018 小时前
springboot旅游信息管理系统-计算机毕业设计源码21675
java·c++·vue.js·spring boot·python·django·php
全栈老石9 小时前
Python 异步生存手册:给被 JS async/await 宠坏的全栈工程师
后端·python
梨落秋霜9 小时前
Python入门篇【模块/包】
python
阔皮大师10 小时前
INote轻量文本编辑器
java·javascript·python·c#