diff --git a/config/allure_config/http_server.exe b/config/allure_config/http_server.exe new file mode 100644 index 0000000..9200f5e Binary files /dev/null and b/config/allure_config/http_server.exe differ diff --git a/config/logo.svg b/config/allure_config/logo.svg similarity index 100% rename from config/logo.svg rename to config/allure_config/logo.svg diff --git a/config/allure_config/双击打开Allure报告.bat b/config/allure_config/双击打开Allure报告.bat new file mode 100644 index 0000000..c9fe67a --- /dev/null +++ b/config/allure_config/双击打开Allure报告.bat @@ -0,0 +1,35 @@ +@echo off +setlocal enabledelayedexpansion + +set "chrome_path=" +::从注册表查找谷歌浏览器路径 +set reg_query_command=reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" /ve + +::遍历注册表查询结果 +for /f "tokens=2*" %%A in ('%reg_query_command%') do ( + ::如果有REG_SZ,则证明找到了谷歌浏览器 + if "%%A"=="REG_SZ" ( + ::如果路径存在,则设置谷歌浏览器绝对路径到变量chrome_path + set "tmp_chrome_path=%%B" + if exist "!tmp_chrome_path!" ( + set "chrome_path=%%B" + ) + ) +) + +::如果上面找到了谷歌浏览器的路径 +if defined chrome_path ( + ::打印找到了谷歌浏览器的文件地址 + echo Chrome found at: "%chrome_path%" + ::带参启动谷歌浏览器,使其不校验跨域问题 + "%chrome_path%" --disable-web-security --user-data-dir="./" %~dp0/index.html +) else ( + ::如果没找到,打印没找到 + echo Chrome not found. + ::打印启动web信息 + echo start a webserver ... + ::启动一个web服务监听5001端口,在后台运行。默认用当前文件夹的index.html作为首页 + start /b http-server.exe -port 5001 + ::使用默认浏览器打开web服务的地址并等待浏览器关闭 + start /WAIT msedge.exe http://127.0.0.1:5001 +) diff --git a/config/pytest_html_report.css b/config/pytest_html_config/pytest_html_report.css similarity index 100% rename from config/pytest_html_report.css rename to config/pytest_html_config/pytest_html_report.css diff --git a/config/settings.py b/config/settings.py index 23d831a..451c4de 100644 --- a/config/settings.py +++ b/config/settings.py @@ -11,7 +11,7 @@ CASE_FILE_TYPE = 1 # 0表示默认不发送任何通知, 1代表钉钉通知,2代表企业微信通知, 3代表邮件通知, 4代表所有途径都发送通知 -SEND_RESULT_TYPE = 4 +SEND_RESULT_TYPE = 0 # 测试报告的定制化信息展示 ENV_INFO = { diff --git a/run.py b/run.py index 8f8002d..3789cf1 100644 --- a/run.py +++ b/run.py @@ -30,7 +30,7 @@ from case_utils.get_results_handle import get_test_results_from_pytest_html_repo get_test_results_from_from_allure_report from case_utils.send_result_handle import send_result from case_utils.allure_handle import AllureReportBeautiful -from common_utils.files_handle import zip_file +from common_utils.files_handle import zip_file, copy_file @click.command() @@ -86,6 +86,7 @@ def run(env, m, report): # 执行指定测试用例 if m is not None: arg_list.append(f"-m {m}") + current_time = datetime.now().strftime("%Y-%m-%d+%H_%M_%S") if report.lower() == "allure": arg_list.extend(['-q', '--cache-clear', f'--alluredir={ALLURE_RESULTS_DIR}', '--clean-alluredir']) """ @@ -110,16 +111,23 @@ def run(env, m, report): # 往allure测试报告中写入环境配置相关信息 ENV_INFO["project_env"] = env AllureReportBeautiful(allure_html_path=ALLURE_HTML_DIR).set_report_env_on_html(env_info=ENV_INFO) - # 发送从allure-html获取的测试报告 + # 从allure-html测试报告获取测试结果 results = get_test_results_from_from_allure_report(ALLURE_HTML_DIR) + # 复制http_server.exe以及双击查看报告.bat文件到allure-html根目录下,用于支撑电脑在未安装allure服务的情况下打开allure-html报告 + # 注意:ZIP文件的名称包含某些特殊字符,会导致无法使用.bat文件打开allure-html报告, 例如空格,/ 等 + allure_config_path = os.path.join(CONF_DIR, "allure_config") + copy_file(src_file_path=os.path.join(allure_config_path, [i for i in os.listdir(allure_config_path) if i.endswith(".exe")][0]), + dest_dir_path=ALLURE_HTML_DIR) + copy_file(src_file_path=os.path.join(allure_config_path, [i for i in os.listdir(allure_config_path) if i.endswith(".bat")][0]), + dest_dir_path=ALLURE_HTML_DIR) # 压缩allure-html报告为一个压缩文件zip - allure_zip_path = os.path.join(REPORT_DIR, f'{ENV_INFO["report_name"]}.zip') + allure_zip_path = os.path.join(REPORT_DIR, f'{ENV_INFO["report_name"]}{str(current_time)}.zip') zip_file(in_path=ALLURE_HTML_DIR, out_path=allure_zip_path) send_result(results=results, attachment_path=allure_zip_path) else: - current_time = datetime.now().strftime("%Y-%m-%d %H_%M_%S") report_path = os.path.join(REPORT_DIR, ENV_INFO["report_name"] + str(current_time) + ".html") - report_css = os.path.join(CONF_DIR, "pytest_html_report.css") + pytest_html_config_path = os.path.join(CONF_DIR, "pytest_html_config") + report_css = os.path.join(pytest_html_config_path, "pytest_html_report.css") arg_list.extend([f'--html={report_path}', f"--css={report_css}"]) pytest.main(args=arg_list) logger.debug("-------测试完成,发送测试报告-------")