Exemplo n.º 1
0
def get_config(path):
    """
    powered by Jhx at 2020/1/27
    用来将配置文件转换为字典,方便后续使用
    :param path:配置文件路径
    :return:返回配置文件dict
    """
    global config
    config.clear()  # 重新获取时,先清空配置
    txt = Txt(path)
    data = txt.read()
    for s in data:
        if s.startswith('#'):  # 跳过注释
            continue
        if not s.find('='):
            logger.warn('配置文件格式错误,请检查:' + str(s))
            continue
        try:
            key = s[0:s.find('=')]
            value = s[s.find('=') + 1:s.__len__()]
            config[key] = value
        except Exception as e:
            logger.warn('配置文件格式错误,请检查:' + str(s))
            logger.exception(e)

    return config
Exemplo n.º 2
0
def get_config(path):
    """
    powered by Mr Will
               at 2018-12-22
            用来格式化打印日志到文件和控制台
    :param path:配置文件路径
    :return:返回配置文件dict
    """
    global config
    # 重新获取时,先清空配置
    config.clear()
    txt = Txt(path)
    data = txt.read()

    for s in data:
        # 跳过注释
        if s.startswith('#'):
            continue

        if not s.find('=') > 0:
            logger.warn('配置文件格式错误,请检查:' + str(s))
            continue
        try:
            key = s[0:s.find('=')]
            value = s[s.find('=') + 1:s.__len__()]
            config[key] = value
        except Exception as e:
            logger.warn('配置文件格式错误,请检查:' + str(s))
            logger.exception(e)
    return config
Exemplo n.º 3
0
def get_config(path):
    global config
    config.clear()
    txt = Txt(path, 'r')
    data = txt.read()
    for s in data:
        if s.startswith('#'):
            continue
        if s.find('=') < 0:
            logger.warn('配置文件格式错误,请检查' + str(s))
            continue
        try:
            key = s[0:s.find('=')]
            value = s[s.find('=') + 1:]
            config[key] = value
        except Exception as e:
            logger.warn("配置文件格式错误,请检查" + str(s))
    return config
Exemplo n.º 4
0
writer.set_sheet(sheetname[0])
endtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
writer.write(1, 4, endtime)
writer.save_close()

# 结果统计
res = Res()
details = res.get_res('./lib/result-%s.xls' % casename)
r = res.get_groups('./lib/result-%s.xls' % casename)

# 关闭jvm
shutdown()

# 邮件处理
mail = Mail()
htmlmodule = Txt('./conf/' + config.config['mailtxt'])
html = htmlmodule.read()[0]
# 对模块文本进行处理
# 替换总体统计信息
sumlist = ['status', 'passrate', 'starttime', 'endtime']
for s in sumlist:
    html = html.replace(s, details[s])

# 生成HTML的一行内容
alltrs = ''
for s in r:
    tr = '<tr><td width="100" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">分组信息</td><td width="80" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">用例总数</td><td width="80" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">通过数</td><td width="80" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">状态</td></tr>'
    tr = tr.replace('分组信息', str(s[0]))
    tr = tr.replace('用例总数', str(s[1]))
    tr = tr.replace('通过数', str(s[2]))
    tr = tr.replace('状态', str(s[3]))
Exemplo n.º 5
0
endtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
writer.set_sheet(writer.get_sheets()[0])
writer.write(1, 4, endtime)
writer.save_close()

# 获取结果数据
res = Res()
summary = res.get_res(f'./lib/{casename}_result.xlsx')
logger.info(summary)

#获取所有用例结果
groups = res.get_groups(f'./lib/{casename}_result.xlsx')
logger.info(groups)

#读取发邮件的html模板
txt = Txt(f"./lib/conf/{config.config['mailtxt']}")
html = txt.read()[0]

# 替换汇总信息
for key in summary.keys():
    if summary[key] == "Pass":
        html = html.replace(
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;">status</td>',
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;color:blue;">Pass</td>'
        )
    elif summary[key] == "Fail":
        html = html.replace(
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;">status</td>',
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;color:red;">Fail</td>'
        )
    else: