【自定义logo】

  1. 进入Allure的安装路径,找到config目录。
  2. 在config目录下,找到allure.yml文件,并打开该文件。
  3. 在allure.yml文件中,添加custom-logo-plugin选项。
  4. 进入Allure的安装路径,找到plugins目录下的custom-logo-plugin目录。
  5. 在custom-logo-plugin目录下,找到static目录,并将自己需要展示的Logo图片放到这个目录下。
  6. 编辑styles.css文件(如果存在的话),可以自定义Logo的大小、位置和样式等。

【自定义模块名,用例标题】

Allure企业级报告定制化自定义logo,中文标题,模块名,用例名,用例详细的测试数据如用例日志,请求信息,返回信息等一文道尽_企业级allure报告

代码

@allure.story("登录模块")   #定义用例模块名称
@pytest.mark.parametrize("base_info,testcase", get_testcase_yaml("./testcases/test_Juhe_post_login_new.yaml"))
def test_post_login(self, base_info,testcase):
    #定义用例名称 如:登录失败的用例-密码不正确
    allure.dynamic.title(testcase["case_name"])
    

【用例详细信息】

上图,当点击用例的时候,右边会出现该用例测试结果相关的信息。这些信息如:用例日志log、接口名称、接口地址、请求方法、请求头等。他们都可以用attach的方式,加入到用例详细信息的列表。

Allure企业级报告定制化自定义logo,中文标题,模块名,用例名,用例详细的测试数据如用例日志,请求信息,返回信息等一文道尽_接口自动化测试_02

代码:

api_name = case_info['api_name']
allure.attach(api_name, f'接口名称:{api_name}', allure.attachment_type.TEXT)
url = url_host + base_info['url']
allure.attach(api_name, f'接口地址:{url}', allure.attachment_type.TEXT)
method = case_info['method']
allure.attach(api_name, f'请求方法:{method}', allure.attachment_type.TEXT)
header = self.replace_load(case_info['header'])
allure.attach(api_name, f'请求头:{header}', allure.attachment_type.TEXT)

【中文网页标题 & 总览内容页标题】

Allure企业级报告定制化自定义logo,中文标题,模块名,用例名,用例详细的测试数据如用例日志,请求信息,返回信息等一文道尽_企业级allure报告_03

中文网页标题:

Allure企业级报告定制化自定义logo,中文标题,模块名,用例名,用例详细的测试数据如用例日志,请求信息,返回信息等一文道尽_企业级allure报告_04

总览内容页标题:

Allure企业级报告定制化自定义logo,中文标题,模块名,用例名,用例详细的测试数据如用例日志,请求信息,返回信息等一文道尽_企业级allure报告_05

为了方便修改,可以写代码,在生成allure报告之后,自动完成上述设置。

我写了一个类,希望对大家有帮助。

class allureUtil:
    def __init__(self):
        self.title = conf.get_section_ALLURE_REPORT_CUSTOM("title")
        self.LogoFile = conf.get_section_ALLURE_REPORT_CUSTOM("LogoFile")
        self.reportFilePath = conf.get_section_ALLURE_REPORT_CUSTOM("reportFilePath")
        self.logoText = conf.get_section_ALLURE_REPORT_CUSTOM("logoText")
        self.reportContentTitle = conf.get_section_ALLURE_REPORT_CUSTOM("reportContentTitle")

    def doAllureCustom(self):
        self.replaceWebSiteTitle()
        self.replaceReportContentPageTitle()
        self.replaceFavicon()
        self.replaceLogosvg()

    def replaceFavicon(self):
        # 定义源文件和目标目录
        target_Favicon_filepath = self.reportFilePath + r"/"
        source_Favicon_filepath = "./imgs/favicon.ico"
        # 使用shutil.copy2()函数复制文件到目标目录并覆盖已存在的文件
        shutil.copy2(source_Favicon_filepath, target_Favicon_filepath)

    def replaceLogosvg(self):
        # 定义源文件和目标目录
        target_Logosvg_filepath = self.reportFilePath + r"/plugins/custom-logo/"
        source_Logosvg_filepath = r"./imgs/custom-logo.svg"
        # 使用shutil.copy2()函数复制文件到目标目录并覆盖已存在的文件
        shutil.copy2(source_Logosvg_filepath, target_Logosvg_filepath)

    def replaceReportContentPageTitle(self):
        # 获取文件的路径
        report_filepath = self.reportFilePath + r"/widgets/summary.json"
        try:
            file = open(report_filepath, 'r', encoding="utf-8")
            content = file.read()
            contentJson = json.loads(content)
            contentJson["reportName"] = self.reportContentTitle
            file.close()

            content = json.dumps(contentJson, ensure_ascii=False)
            file = open(report_filepath, 'w', encoding="utf-8")
            file.write(content)
        except Exception as e:
            logs.error(f'获取【{report_filepath}】文件数据时出现未知错误: {str(e)}')
        finally:
            file.close()


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: go