zoukankan      html  css  js  c++  java
  • 接口自动化(七)--主程序

    主程序就是这个框架的执行模块,所有的实现方法几种到主程序模块:

     1 from main import requestMethord
     2 from data import get_Case
     3 from common import compare
     4 from common import datadepend
     5 from data import operateExcel
     6 import json
     7 from Log import printlog
     8 from common import run_sendMail
     9 
    10 class runCase():
    11     def __init__(self):
    12         self.reqMethord = requestMethord.Methord()
    13         self.case = get_Case.getCaseData()
    14         self.compare = compare.compareStr()
    15         self.operateExcel = operateExcel.operateExcel()
    16 
    17     #程序执行的主入口
    18     def goRun(self):
    19         passlist = []
    20         faillist = []
    21         res = None
    22         excelRowNum = self.case.getExcelRow()
    23         for rownum in range(1,excelRowNum):
    24             print("正在执行的行数",rownum)
    25             try:
    26                 reqUrl = self.case.getUrl(rownum)
    27                 runOrNot = self.case.getRun_or_not(rownum)
    28                 reqMethord = self.case.getRequestMethord(rownum)
    29                 reqData = self.case.getJsonData(rownum)
    30                 header = self.case.getHeader(rownum)
    31                 respectResult = self.case.getRespectResult(rownum)
    32                 depCaseID = self.case.judgeCaseDep(rownum)
    33                 depkey = self.case.getDependKey(rownum)
    34                 if runOrNot:
    35                     if depCaseID != None:
    36                         print(depCaseID)
    37                         dataDep = datadepend.dataDepend(depCaseID)
    38                         #从依赖用例的返回结果中获取被依赖的数据
    39                         depdata = dataDep.getDepData(rownum)
    40                         dd = depdata[0]
    41                         reqData = json.loads(reqData)
    42                         reqData["data"][depkey]=dd
    43                         reqData = json.dumps(reqData)
    44                     responds = self.reqMethord.runMethord(reqMethord,reqUrl,reqData,header)
    45                     re = json.loads(responds.text)["respMsg"]
    46                     if self.compare.is_contain(respectResult,re):
    47                         self.case.wriRealResult(rownum,"pass")
    48                         passlist.append(rownum)
    49                     else:
    50                         self.case.wriRealResult(rownum,"fail")
    51                         faillist.append(rownum)
    52                     self.case.wriReturn(rownum,value=responds.text)
    53                 print("#"*100)
    54                 logger = printlog.Logger(responds).log()
    55             except Exception as e:
    56                 print(e)
    57                 logger = printlog.Logger(e).log()
    58         run_sendMail.RunSendMail(passlist,faillist).sendmail()
    59 
    60 
    61 if __name__ == '__main__':
    62     run = runCase()
    63     run = run.goRun()

    到这整个框架算基本完成了,操作数据库的部分以及读取配置文件的部分后续补充,代码持续优化。

  • 相关阅读:
    JqGrid在IE8中表头不能分组的解决办法
    Task 异步小技巧
    封装好的socket,拿去用
    反射 实现不同模型相同属性赋值 第二集(automapper)
    .net破解二(修改dll)
    .net破解一(反编译,反混淆-剥壳)
    c/s 自动升级(WebService)
    反射实现不同模型相同属性赋值
    row_number() over()分页查询
    SQL函数
  • 原文地址:https://www.cnblogs.com/kakaln/p/8401843.html
Copyright © 2011-2022 走看看