Commit bb69cfe2 by Jaxon

chron: playwright 配置

1 parent bcd8bbcd
...@@ -11,11 +11,18 @@ ...@@ -11,11 +11,18 @@
*/ */
import { defineConfig, devices } from "@playwright/test"; import { defineConfig, devices } from "@playwright/test";
import dayjs from "dayjs";
// 生成时间戳,用于报告和结果目录
const timestamp = dayjs().format("YYYY-MM-DD HH");
export default defineConfig({ export default defineConfig({
// 测试文件位置 // 测试文件位置
testDir: "./e2e", testDir: "./e2e",
// 测试文件匹配模式
testMatch: "**/*.e2e.js",
// 超时时间 // 超时时间
timeout: 30 * 1000, timeout: 30 * 1000,
...@@ -28,21 +35,28 @@ export default defineConfig({ ...@@ -28,21 +35,28 @@ export default defineConfig({
retries: 1, retries: 1,
// 并行执行配置 // 并行执行配置
workers: 4, workers: 1,
// 是否失败即停止 // 是否失败即停止
failOnFlakyTests: false, failOnFlakyTests: false,
// 报告配置 // 报告配置
// 产出到 playwright/report/index.YYYY-MM-DD hh-mm.html
reporter: [ reporter: [
["list"], ["list"],
["html", { outputFolder: "playwright-report", open: "never" }], [
"html",
{
outputFolder: `playwright/report/${timestamp}`,
open: "never",
},
],
], ],
// 共享配置 // 共享配置
use: { use: {
// 基础 URL // 基础 URL - 使用当前 IP 访问
baseURL: process.env.BASE_URL || "http://localhost:8080", baseURL: process.env.BASE_URL || "http://192.168.1.146:8080/dj-carlife-web/",
// 截图配置 // 截图配置
screenshot: "only-on-failure", screenshot: "only-on-failure",
...@@ -58,6 +72,10 @@ export default defineConfig({ ...@@ -58,6 +72,10 @@ export default defineConfig({
navigationTimeout: 30000, navigationTimeout: 30000,
}, },
// 测试结果目录(截图、视频、trace)
// 产出到 playwright/result/YYYY-MM-DD hh-mm/
outputDir: `playwright/result/${timestamp}`,
// 浏览器配置 // 浏览器配置
projects: [ projects: [
{ {
...@@ -67,40 +85,19 @@ export default defineConfig({ ...@@ -67,40 +85,19 @@ export default defineConfig({
viewport: { width: 1920, height: 1080 }, viewport: { width: 1920, height: 1080 },
}, },
}, },
{
name: "firefox",
use: {
...devices["Desktop Firefox"],
viewport: { width: 1920, height: 1080 },
},
},
{
name: "webkit",
use: {
...devices["Desktop Safari"],
viewport: { width: 1920, height: 1080 },
},
},
// 移动端测试
{
name: "Mobile Chrome",
use: {
...devices["Pixel 5"],
},
},
{
name: "Mobile Safari",
use: {
...devices["iPhone 12"],
},
},
], ],
// Web 服务器配置 (可选,用于自动启动开发服务器) // Web 服务器配置 (用于自动启动开发服务器)
// webServer: { // 如果在远程机器运行,请设置 SKIP_WEBSERVER=true 并手动启动服务
// command: "npm run dev", webServer: process.env.SKIP_WEBSERVER
// port: 8080, ? undefined
// timeout: 120 * 1000, : {
// reuseExistingServer: true, command: "npm run serve",
// }, timeout: 120 * 1000,
reuseExistingServer: true,
// 等待 URL,确保服务器准备好
url: process.env.BASE_URL
? process.env.BASE_URL.replace(/\/$/, "") + "/#/"
: "http://192.168.1.146:8080/dj-carlife-web/#/",
},
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!