python _自動化效能測試指令碼

來源:互聯網
上載者:User

代碼如下:

#!/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()

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.