Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DC-TOM
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘照晖
DC-TOM
Commits
fd2f1ecf
Commit
fd2f1ecf
authored
Sep 08, 2025
by
Cai Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(*): 修改测试脚本报告流程
parent
adc36511
Pipeline
#1329
failed
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
147 additions
and
94 deletions
+147
-94
README.md
README.md
+3
-2
package.json
package.json
+6
-5
run-test.bat
run-test.bat
+100
-0
run-tests.bat
run-tests.bat
+28
-87
run-tests.sh
run-tests.sh
+10
-0
No files found.
README.md
View file @
fd2f1ecf
...
@@ -26,8 +26,9 @@ npm run cy:run:prod # 生产环境测试
...
@@ -26,8 +26,9 @@ npm run cy:run:prod # 生产环境测试
npm run cy:run:custom
# 自定义环境测试
npm run cy:run:custom
# 自定义环境测试
# 使用特定浏览器运行测试
# 使用特定浏览器运行测试
npm run cy:run:chrome
# Chrome浏览器
npm run cy:run:electron
# Electron浏览器(默认)
npm run cy:run:firefox
# Firefox浏览器
npm run cy:run:chrome
# Chrome浏览器(需要单独安装)
npm run cy:run:firefox
# Firefox浏览器(需要单独安装)
# 运行完整测试流程(执行测试+生成报告+生成汇总报告)
# 运行完整测试流程(执行测试+生成报告+生成汇总报告)
npm run
test
:full
npm run
test
:full
...
...
package.json
View file @
fd2f1ecf
...
@@ -5,11 +5,12 @@
...
@@ -5,11 +5,12 @@
"type"
:
"module"
,
"type"
:
"module"
,
"scripts"
:
{
"scripts"
:
{
"cy:open"
:
"cypress open"
,
"cy:open"
:
"cypress open"
,
"cy:run"
:
"cypress run"
,
"cy:run"
:
"cypress run --browser chrome"
,
"cy:run:dev"
:
"CYPRESS_BASE_URL=http://localhost:3000 cypress run"
,
"cy:run:dev"
:
"CYPRESS_BASE_URL=http://localhost:3000 cypress run --browser chrome"
,
"cy:run:staging"
:
"CYPRESS_BASE_URL=https://staging.example.com cypress run"
,
"cy:run:staging"
:
"CYPRESS_BASE_URL=https://staging.example.com cypress run --browser chrome"
,
"cy:run:prod"
:
"CYPRESS_BASE_URL=https://app.example.com cypress run"
,
"cy:run:prod"
:
"CYPRESS_BASE_URL=https://app.example.com cypress run --browser chrome"
,
"cy:run:custom"
:
"source .env.custom && cypress run"
,
"cy:run:custom"
:
"source .env.custom && cypress run --browser chrome"
,
"cy:run:electron"
:
"cypress run --browser electron"
,
"cy:run:chrome"
:
"cypress run --browser chrome"
,
"cy:run:chrome"
:
"cypress run --browser chrome"
,
"cy:run:firefox"
:
"cypress run --browser firefox"
,
"cy:run:firefox"
:
"cypress run --browser firefox"
,
"test:all"
:
"npm run cy:run:dev && npm run cy:run:staging && npm run cy:run:prod"
,
"test:all"
:
"npm run cy:run:dev && npm run cy:run:staging && npm run cy:run:prod"
,
...
...
run-test.bat
0 → 100644
View file @
fd2f1ecf
@echo off
setlocal enabledelayedexpansion
REM 参数处理
set ENV=%1
if "%ENV%"=="" set ENV=development
set BROWSER=%2
if "%BROWSER%"=="" set BROWSER=chrome
echo Running tests for %ENV% environment with %BROWSER% browser
REM 环境配置
if "%ENV%"=="development" (
set CYPRESS_BASE_URL=http://172.16.20.227/admin/dcTom/
set CYPRESS_REPORT_TITLE=Development Tests
) else if "%ENV%"=="staging" (
set CYPRESS_BASE_URL=http://172.16.20.227/admin/dcTom/
set CYPRESS_REPORT_TITLE=Staging Tests
) else if "%ENV%"=="production" (
set CYPRESS_BASE_URL=http://172.16.20.227/admin/dcTom/
set CYPRESS_REPORT_TITLE=Production Tests
) else (
if "%ENV:~0,4%"=="http" (
set CYPRESS_BASE_URL=%ENV%
set CYPRESS_REPORT_TITLE=Custom URL Tests
echo Using custom URL: %ENV%
) else (
echo Unknown environment: %ENV%
echo Supported environments: development, staging, production
echo Or specify a URL directly
exit /b 1
)
)
echo CYPRESS_BASE_URL: %CYPRESS_BASE_URL%
REM 浏览器选择和 fallback
set FALLBACK_BROWSER=electron
set CHROME_CUSTOM=chrome-custom
if /i "%BROWSER%"=="chrome" (
echo Replacing chrome with %CHROME_CUSTOM%
set BROWSER=%CHROME_CUSTOM%
)
REM 检查浏览器是否可用
npx cypress info | findstr /i "%BROWSER%" >nul
if errorlevel 1 (
echo Browser %BROWSER% not found, falling back to %FALLBACK_BROWSER%
set BROWSER=%FALLBACK_BROWSER%
)
echo Using browser: %BROWSER%
REM 查找测试文件
echo Finding test scripts...
set SPEC_FILES=
for %%f in (cypress\e2e\*.cy.js) do (
if exist "%%f" (
if "!SPEC_FILES!"=="" (
set SPEC_FILES=%%f
) else (
set SPEC_FILES=!SPEC_FILES!,%%f
)
echo - %%f
)
)
REM 创建报告目录
if not exist "cypress\reports" mkdir cypress\reports
if not exist "public\reports" mkdir public\reports
REM 运行测试
if defined SPEC_FILES (
echo Running specified test scripts...
npx cypress run --browser %BROWSER% --spec "%SPEC_FILES%"
) else (
echo No first-level test scripts found, running all tests...
npx cypress run --browser %BROWSER%
)
set TEST_EXIT_CODE=%errorlevel%
echo Test execution completed with exit code: %TEST_EXIT_CODE%
REM 合并和生成报告
echo Merging reports...
npx mochawesome-merge cypress/reports/**/*.json -o public/reports/merged-report.json
echo Generating HTML report...
npx marge public/reports/merged-report.json --reportDir public/reports --inline
echo Generating summary report...
node scripts/generate-summary-report.cjs
echo All reports generated!
echo View summary report: public/reports/summary-report.html
echo View detailed report: public/reports/merged-report.html
echo Test execution finished
run-tests.bat
View file @
fd2f1ecf
@echo off
@echo off
setlocal enabledelayedexpansion
setlocal enabledelayedexpansion
REM Windows测试执行脚本
REM 用法: run-tests.bat [environment] [browser]
REM 示例: run-tests.bat staging chrome
set ENV=%1
set ENV=%1
if "%ENV%"=="" set ENV=development
if "%ENV%"=="" set ENV=development
set BROWSER=%2
set BROWSER=%2
if "%BROWSER%"=="" set BROWSER=chrome
if "%BROWSER%"=="" set BROWSER=chrome
echo
开始执行 %ENV% 环境的测试,使用 %BROWSER% 浏览器
echo
Running tests for %ENV% environment with %BROWSER% browser
REM 根据环境设置变量
if "%ENV%"=="development" (
if "%ENV%"=="development" (
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_REPORT_TITLE=Development Tests
set CYPRESS_REPORT_TITLE=Development Tests
set CYPRESS_REPORT_PAGE_TITLE=开发环境测试报告
) else if "%ENV%"=="dev" (
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_REPORT_TITLE=Development Tests
set CYPRESS_REPORT_PAGE_TITLE=开发环境测试报告
) else if "%ENV%"=="staging" (
) else if "%ENV%"=="staging" (
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_REPORT_TITLE=Staging Tests
set CYPRESS_REPORT_TITLE=Staging Tests
set CYPRESS_REPORT_PAGE_TITLE=预发布环境测试报告
) else if "%ENV%"=="production" (
) else if "%ENV%"=="production" (
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_REPORT_TITLE=Production Tests
set CYPRESS_REPORT_TITLE=Production Tests
set CYPRESS_REPORT_PAGE_TITLE=生产环境测试报告
) else if "%ENV%"=="prod" (
set CYPRESS_BASE_URL=https://screen.bmetech.com/admin/dctom/
set CYPRESS_REPORT_TITLE=Production Tests
set CYPRESS_REPORT_PAGE_TITLE=生产环境测试报告
) else if "%ENV%"=="custom" (
REM 加载自定义环境变量
if exist .env.custom (
for /f "tokens=*" %%i in (.env.custom) do set %%i
echo 已加载自定义环境配置
) else (
echo 警告: 未找到 .env.custom 文件
)
) else (
) else (
REM 支持直接指定URL
if "%ENV:~0,4%"=="http" (
echo %ENV% | findstr /C:"http" >nul
if !errorlevel! equ 0 (
set CYPRESS_BASE_URL=%ENV%
set CYPRESS_BASE_URL=%ENV%
set CYPRESS_REPORT_TITLE=Custom URL Tests
set CYPRESS_REPORT_TITLE=Custom URL Tests
set CYPRESS_REPORT_PAGE_TITLE=自定义URL测试报告
echo Using custom URL: %ENV%
echo 使用自定义URL: %ENV%
) else (
) else (
echo
未知环境
: %ENV%
echo
Unknown environment
: %ENV%
echo
支持的环境: development, staging, production, custom
echo
Supported environments: development, staging, production
echo
或者直接指定URL,例如: run-tests.bat https://your-site.com chrome
echo
Or specify a URL directly
exit /b 1
exit /b 1
)
)
)
)
REM 输出环境变量以供调试
echo CYPRESS_BASE_URL: %CYPRESS_BASE_URL%
echo CYPRESS_BASE_URL: %CYPRESS_BASE_URL%
echo CYPRESS_REPORT_TITLE: %CYPRESS_REPORT_TITLE%
echo CYPRESS_REPORT_PAGE_TITLE: %CYPRESS_REPORT_PAGE_TITLE%
REM 查找并执行cypress/e2e目录下的第一层测试脚本
REM 检查浏览器是否可用
echo 查找cypress/e2e目录下的第一层测试脚本...
echo Checking if browser %BROWSER% is available...
REM 在Windows上,我们简化处理,直接使用electron作为备选
set FALLBACK_BROWSER=electron
echo Finding test scripts...
set SPEC_FILES=
set SPEC_FILES=
for %%f in (cypress\e2e\*.cy.js) do (
for %%f in (cypress\e2e\*.cy.js) do (
if exist "%%f" (
if exist "%%f" (
...
@@ -77,65 +51,32 @@ for %%f in (cypress\e2e\*.cy.js) do (
...
@@ -77,65 +51,32 @@ for %%f in (cypress\e2e\*.cy.js) do (
)
)
)
)
REM 确保报告目录存在
echo Creating report directories...
echo 创建报告目录...
if not exist "cypress\reports" mkdir cypress\reports
if not exist "cypress\reports" mkdir cypress\reports
if not exist "public\reports" mkdir public\reports
if not exist "public\reports" mkdir public\reports
echo 清理旧的报告文件...
del /q "cypress\reports\*.json" 2>nul
del /q "cypress\reports\*.html" 2>nul
del /q "public\reports\*.json" 2>nul
del /q "public\reports\*.html" 2>nul
if defined SPEC_FILES (
if defined SPEC_FILES (
echo 执行指定的测试脚本...
echo Running specified test scripts...
echo 运行命令: npx cypress run --browser %BROWSER% --spec "%SPEC_FILES%"
npx cypress run --browser %BROWSER% --spec "%SPEC_FILES%"
npx cypress run --browser %BROWSER% --spec "%SPEC_FILES%"
) else (
) else (
echo
未找到第一层测试脚本,执行所有测试
...
echo
No first-level test scripts found, running all tests
...
npx cypress run --browser %BROWSER%
npx cypress run --browser %BROWSER%
)
)
REM 检查测试是否成功执行
set TEST_EXIT_CODE=%errorlevel%
set TEST_EXIT_CODE=%errorlevel%
echo
测试执行完成,退出码
: %TEST_EXIT_CODE%
echo
Test execution completed with exit code
: %TEST_EXIT_CODE%
REM 检查是否有JSON报告文件生成
echo Merging reports...
for /f %%i in ('dir /b /s "cypress\reports\*.json" 2^>nul ^| find /c /v ""') do set JSON_REPORT_COUNT=%%i
npx mochawesome-merge cypress/reports/**/*.json -o public/reports/merged-report.json
echo 找到 %JSON_REPORT_COUNT% 个JSON报告文件
if %JSON_REPORT_COUNT% GTR 0 (
echo Generating HTML report...
echo 合并报告...
npx marge public/reports/merged-report.json --reportDir public/reports --inline
npx mochawesome-merge cypress/reports/**/*.json -o public/reports/merged-report.json
if !errorlevel! neq 0 (
echo Generating summary report...
echo 报告合并失败,退出码: !errorlevel!
node scripts/generate-summary-report.cjs
exit /b 1
)
echo All reports generated!
echo View summary report: public/reports/summary-report.html
echo 生成HTML报告...
echo View detailed report: public/reports/merged-report.html
npx marge public/reports/merged-report.json --reportDir public/reports --inline
if !errorlevel! neq 0 (
echo HTML报告生成失败,退出码: !errorlevel!
exit /b 1
)
echo 生成自定义汇总报告...
node scripts/generate-summary-report.cjs
if !errorlevel! neq 0 (
echo 自定义汇总报告生成失败,退出码: !errorlevel!
exit /b 1
)
echo 所有报告生成完成!
echo 查看汇总报告: public/reports/summary-report.html
echo 查看详细报告: public/reports/merged-report.html
) else (
echo 未找到任何JSON报告文件,跳过报告生成
if %TEST_EXIT_CODE% neq 0 (
echo 测试执行失败,请检查错误信息
exit /b 1
)
)
echo 测试执行完成
echo Test execution finished
\ No newline at end of file
\ No newline at end of file
run-tests.sh
View file @
fd2f1ecf
...
@@ -64,6 +64,16 @@ if [[ "$OSTYPE" == "msys"* ]] || [[ "$OSTYPE" == "win32" ]] || [[ "$(uname -s)"
...
@@ -64,6 +64,16 @@ if [[ "$OSTYPE" == "msys"* ]] || [[ "$OSTYPE" == "win32" ]] || [[ "$(uname -s)"
exit
0
exit
0
fi
fi
# 检查浏览器是否可用
echo
"检查浏览器
$BROWSER
是否可用..."
AVAILABLE_BROWSERS
=
$(
npx cypress info |
grep
"Available browsers"
-A
20 |
grep
-E
"^
\s
*-"
|
sed
's/^\s*-\s*//'
|
tr
'\n'
' '
)
echo
"系统可用的浏览器:
$AVAILABLE_BROWSERS
"
if
[[
$AVAILABLE_BROWSERS
!=
*
"
$BROWSER
"
*
]]
;
then
echo
"警告: 浏览器
$BROWSER
不可用,使用默认浏览器 electron"
BROWSER
=
"electron"
fi
# 执行测试 - 自动涵盖cypress/e2e下面的第一层测试脚本
# 执行测试 - 自动涵盖cypress/e2e下面的第一层测试脚本
echo
"查找cypress/e2e目录下的第一层测试脚本..."
echo
"查找cypress/e2e目录下的第一层测试脚本..."
SPEC_FILES
=
""
SPEC_FILES
=
""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment