def generate_html_tail(): return '''</div></div></table><script src="%s"></script> <script src="%s"></script> <script type="text/javascript"> $("#check-all").click(function(e){ $(".case-tr").removeClass("hidden-tr"); }); $("#check-pass").click(function(e){ $(".case-tr").removeClass("hidden-tr"); $(".fail").addClass("hidden-tr"); $(".error").addClass("hidden-tr"); }); $("#check-fail").click(function(e){ $(".case-tr").removeClass("hidden-tr"); $(".pass").addClass("hidden-tr"); $(".error").addClass("hidden-tr"); }); $("#check-error").click(function(e){ $(".case-tr").removeClass("hidden-tr"); $(".pass").addClass("hidden-tr"); $(".fail").addClass("hidden-tr"); }); </script> </body></html>''' % (getRootPath() + '/files/plugs/jquery-1.10.2.js', getRootPath() + '/files/plugs/bootstrap.min.js')
def TransSpecial(self, configDic): try: file = xlrd.open_workbook(getRootPath() + '/files/xlsx/%s.xlsx' % configDic[ExcelName]) me = file.sheets()[0] nrows = me.nrows result = [] itemList = configDic[ParamList] for i in range(1, nrows): item = dict() for j in range(len(itemList)): ctype = me.cell(i, j).ctype cell = me.cell_value(i, j) if ctype == 2 and cell % 1 == 0: cell = int(cell) elif ctype == 3: date = datetime(*xldate_as_tuple(cell, 0)) cell = date.strftime('%Y/%d/%m %H:%M:%S') elif ctype == 4: cell = True if cell == 1 else False item[itemList[j]] = cell result.append(item) return result except Exception as e: print('打开测试用例失败,原因是:%s' % e) return
def htmlTitle(titles): title = '''<!DOCTYPE html> <htmls> <head> <title>%s</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="%s" rel="stylesheet"> <![endif]--> <style type="text/css"> table tr td{ vertical-align: middle; } .hidden-detail,.hidden-tr{ display:none; } .result_red{ background: red; color: white; } .result_green{ background: green !important; color: white; } </style> </head> <body> ''' % (titles, getRootPath() + '/files/plugs/bootstrap.min.css') return title
def outputFile(text, fileName): day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = getRootPath() filepath = os.path.join(basdir + '/files/report/%s-%s.html' % (day, fileName)) # if os.path.exists(filepath) is False: # os.system(r'touch %s' % filepath) # else: with open(filepath, 'wb') as f: f.write(text.encode('utf-8'))
class GlobalConfig(object): Domain = 'http://msg2.0234.co' # 网络请求域名 Client_version = '5.2.3' # 当前版本号 Max_retry = 1 # 请求错误最大重试次数 Request_timeout = 15 # 网络超时请求时间 User_agent = 'SSCBeta' # 请求头代理 X_requested_with = 'XMLHttpRequest' # 请求头参数 Success_count = 0 # 成功的个数 Failure_count = 0 # 失败的个数 Error_count = 0 # 异常的个数 Exception_count = 0 # 未知错误的个数 Report_path = getRootPath() + '/files/report/' # 测试报告文档路径 # 测试数据配置 User_account = '1002' # 投注测试账号 User_password = '******' # 投注测试密码 Lottery_layout = '江苏快3' # 布局——彩种名称 Lottery_bet = '安徽快3' # 投注——彩种名称
def generate_html_head(): html = '''<!DOCTYPE html> <html> <head> <title>测试结果</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8″> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="%s" rel="stylesheet"> ''' % (getRootPath() + '/files/plugs/bootstrap.min.css') html += ''' <![endif]--> <style type="text/css"> .hidden-detail,.hidden-tr{ display:none; } </style> </head> <body> <div class="row " style="margin:6px"> <div style='margin-top: 1%;' > <div class="btn-group" role="group" aria-label="..."> <button type="button" id="check-all" class="btn btn-primary">所有用例</button> <button type="button" id="check-pass" class="btn btn-success">成功用例</button> <button type="button" id="check-fail" class="btn btn-danger">失败用例</button> <button type="button" id="check-error" class="btn btn-warning">异常用例</button> </div> <div class="btn-group" role="group" aria-label="..."></div> <table class="table table-hover table-condensed table-bordered" style="word-wrap:break-word; word-break:break-all; margin-top: 7px; table-layout: fixed;"> <tr style='text-align:center;'> <td class='col-md-1' style='width:40px'><strong>编号</strong></td> <td class='col-md-1'><strong>用例名字</strong></td> <td class='col-md-2'><strong>请求参数</strong></td> <td class='col-md-3'><strong>url</strong></td> <td class='col-md-1'><strong>期望code值</strong></td> <td class='col-md-4'><strong>实际返回</strong></td> <td class='col-md-1'><strong>结果</strong></td> <td class='col-md-1'><strong>请求时长(ms)</strong></td> </tr> ''' return html
def create_html_file(fileName): localtime = time.strftime("%Y%m%d%H%M%S", time.localtime()) GlobalConfig.Report_path = getRootPath() + '/files/report/' GlobalConfig.Report_path = GlobalConfig.Report_path + '%s_%s.html' % ( localtime, fileName)
<script src="%s"></script> <script type="text/javascript"> $("#check-all").click(function(e){ $(".case-tr").removeClass("hidden-tr"); }); $("#check-failure").click(function(e){ $(".case-tr").removeClass("hidden-tr"); $(".success").addClass("hidden-tr"); $(".failure").removeClass("hidden-tr"); }); $("#check-success").click(function(e){ $(".case-tr").removeClass("hidden-tr"); $(".success").removeClass("hidden-tr"); $(".failure").addClass("hidden-tr"); }); </script> </body></html>''' % (getRootPath() + '/files/plugs/jquery-1.10.2.js', getRootPath() + '/files/plugs/bootstrap.min.js') def outputFile(text, fileName): day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = getRootPath() filepath = os.path.join(basdir + '/files/report/%s-%s.html' % (day, fileName)) # if os.path.exists(filepath) is False: # os.system(r'touch %s' % filepath) # else: with open(filepath, 'wb') as f: f.write(text.encode('utf-8'))