python _自动化性能测试脚本

时间:2022-10-15 09:08:53

代码如下:

#!/usr/bin/python
# -*- coding: cp936 -*-
#filename : SimpleAutoTest.py

import os,io
import sys
import re
#import lib.MyException.myExecpt

#--------------------------------------
#    Class Name :SimpleAutoTest
#--------------------------------------
class SimpleAutoTest:

    #--------------------------------------------------
    #   Function :
    #        method__ : 主函数      Main_()      =>    private
    #
    #                   设置运行参数SetFormat_() =>    private
    #                   写日志      _WriteLog()  =>    public
    #                   读取日志    _ReadLog()   =>    public
    #                   分析数据    _AnaylzData()=>    public
    #                   结果估值    EvalData_()  =>    private
    #
    #                   修改:
    #                        @date  : 2009-4-20
    #                        @writer: 天渊小剑
    #                        设置运行参数& _SetFormat() =>  public
    #                        主函数        _Main()      =>  public
    #
    #                   添加:
    #                        @date  : 2009-4-20
    #                        @writer: 天渊小剑
    #                        缺省设置 DefauleSetting_() =>  private
    #                        @package :  lib/__init__.py
    #                        @Exception handling : lib/MyException/myExcept.py
    #--------------------------------------------------

    def __init__ (self,exeFile,logFile,url):
        '''
            __init__
        '''
        self.SysPath = os.getcwd()
        self.ToolPath = self.SysPath+'\\tool\\'
        self.LogPaht = self.SysPath+'\\Log\\'
        self.ToolName = exeFile
        self.LogName = logFile
        self.Url = url
        self.CMD_ = ''


    def _Main(self):
        self.DefauleSetting_()
        self.SysCmd()

    def DefauleSetting_ (self):
        self.CMD_ = ' -n 3 -c 4 '


    def SysCmd (self):
        try:
            self.Results = os.popen(self.ToolPath+self.ToolName+self.CMD_+self.Url).readlines()
            self._AnaylzData()
        except OSError:
            print('运行有问题')
            os.close()

 

    def _WriteLog(self):
        try:
            f = open(self.LogPaht+self.LogName,'w')
            for line in self.Results:
                f.write(line)

        except EOFError:
            print("没找到文件")
            sys.exit(1)


    def _AnaylzData (self):
        if len(self.Results)>1:
            Static = self.Results[4]
            Res_chk=Static.find('done')
            if Res_chk:
                print('分析结果:这是正确的运行过程')
            else:
                print('分析结果:这是有问题运行过程')
        else:
            print('运行有问题无法进行分析结果!')

 


'''
    def _SetFormat(self,reqNum=3,ccyNum=4,timernu=''):
        self.REQ_NUM = ' -n '+reqNum
        self.CCY_NUM = ' -c '+ccyNum
        self.CMD = self.REQ_NUM + self.CCY_NUM + self.TIMER

 

    def EvalData__ (self):
'''

 


#--------------------------------------
#   Test Name :
#--------------------------------------
exeFile = 'ab'
logFile = 'log.log'
url = 'http://51hongka.com/a/index.html';
bf = SimpleAutoTest(exeFile,logFile,url)
bf._Main()
bf._WriteLog()