所有 E2E 测试(17 个 Playwright 文件,100+ 场景)因 uni-app H5 前端未部署到浏览器可见的 URL 而被阻塞。
当前 playwright.config.js 的 baseURL: https://cfc.iwintrue.com 指向的是 API 后端(Spring Boot),不是前端页面。
将 uni-app 前端以 H5 模式构建并部署到 Web 服务器。
cd cfc-frontend
npm install
# 构建 uni-app H5 版本
npm run build:h5
# 产物在 dist/build/h5/ 目录
如果 package.json 中没有 build:h5 脚本,手动执行:
npx uni-app build --platform h5
# 部署到 192.168.16.251(与 cfc-web 同一台服务器)
rsync -av --delete dist/build/h5/ 192.168.16.251:/var/www/cfc-h5/
在 cfc.iwintrue.com 的 nginx 配置中添加:
location /cfc-h5/ {
alias /var/www/cfc-h5/;
try_files $uri $uri/ /cfc-h5/index.html;
}
或者使用子域名(推荐):
server {
listen 80;
server_name h5.cfc.iwintrue.com;
root /var/www/cfc-h5;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
重要: uni-app H5 使用 hash 路由(#/),上述配置中 try_files 确保 SPA 路由刷新时正确 fallback 到 index.html。
// playwright.config.js
const config = {
// 使用子域名部署时:
baseURL: 'https://h5.cfc.iwintrue.com',
// 或使用路径部署时:
// baseURL: 'https://cfc.iwintrue.com/cfc-h5/',
};
访问部署后的 URL,确认:
https://h5.cfc.iwintrue.com/ 返回 uni-app 首页https://h5.cfc.iwintrue.com/#/pages/index/index 能正常打开页面# 启动 uni-app H5 开发服务器
cd cfc-frontend
npm run dev:h5 # 默认监听 localhost:8080
# 更新 playwright.config.js 的 baseURL
# baseURL: 'http://localhost:8080'
| 组件 | URL | 状态 |
|---|---|---|
| API 后端 | cfc.iwintrue.com |
✅ 可用 |
| cfc-web 管理端 | 需本地启动 | ⚠️ 仅开发 |
| uni-app H5 | 待部署 | ❌ 不可用 |
所有 E2E 测试在 uni-app H5 部署后即可运行。