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.测试报告内容如下:

相关推荐
站大爷IP2 小时前
Python operator模块的methodcaller:一行代码搞定对象方法调用的黑科技
python
GarrettGao4 小时前
Frida常见用法
javascript·python·逆向
Juchecar4 小时前
Pandas技巧:利用 category 类型节省内存
python
跟橙姐学代码5 小时前
Python时间处理秘籍:别再让日期时间卡住你的代码了!
前端·python·ipython
mortimer7 小时前
Python 文件上传:一个简单却易犯的错误及解决方案
人工智能·python
Juchecar8 小时前
NumPy编程:鼓励避免 for 循环
python
Java陈序员8 小时前
直播录制神器!一款多平台直播流自动录制客户端!
python·docker·ffmpeg
c8i8 小时前
drf 在django中的配置
python·django
这里有鱼汤10 小时前
【花姐小课堂】新手也能秒懂!用「风险平价」打造扛造的投资组合
后端·python
databook1 天前
Manim实现闪光轨迹特效
后端·python·动效