From ee289e97d5b086d7e99966ad12bef89c3af0edd4 Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Mon, 22 Dec 2025 15:21:16 +0800 Subject: [PATCH 1/3] feat: add RUN_ALL_CASES mode support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增通过环境变量控制直接运行所有测试用例的功能,跳过解析步骤。 --- playwright/src/playwrightx/parser.ts | 14 ++++++++++++++ playwright/src/playwrightx/utils.ts | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/playwright/src/playwrightx/parser.ts b/playwright/src/playwrightx/parser.ts index d26814c..2be3404 100644 --- a/playwright/src/playwrightx/parser.ts +++ b/playwright/src/playwrightx/parser.ts @@ -29,6 +29,20 @@ export async function collectTestCases( const result = new LoadResult(test, loadError); try { + // 检查是否启用 RUN_ALL_CASES 模式 + const runAllCases = process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "1" || + process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "true"; + + if (runAllCases) { + log.info("[Load] 执行一条命令运行当前项目的所有用例"); + // 直接透传用例名称,不解析 + testSelectors.forEach((selector: string) => { + const testCase = new TestCase(selector, {}); + result.Tests.push(testCase); + }); + return result; + } + // 进入projPath目录 process.chdir(projPath); log.info(`Current directory: ${process.cwd()}`); diff --git a/playwright/src/playwrightx/utils.ts b/playwright/src/playwrightx/utils.ts index 02abe6a..f8dda3f 100644 --- a/playwright/src/playwrightx/utils.ts +++ b/playwright/src/playwrightx/utils.ts @@ -724,6 +724,8 @@ export function createTestResults( // 检查是否为 fileMode const fileMode = process.env.TESTSOLAR_TTP_FILEMODE == "1"; + const runAllCases = process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "1" || + process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "true"; // 首先找出参考失败用例(output中的key不在testIdentifiers中的) let referenceFailedTest: TestResult | null = null; @@ -742,6 +744,10 @@ export function createTestResults( const testFilePath = testCase.split('?')[0]; isInTestIdentifiers = testIdentifiers.includes(testFilePath); } + + if (runAllCases && !isInTestIdentifiers) { + isInTestIdentifiers = true; + } // 处理每个结果 for (const result of results) { From d2e462bb82b6fa15e5abaab2efcc9447ec0b4da0 Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Mon, 22 Dec 2025 15:23:10 +0800 Subject: [PATCH 2/3] chore: update version to 0.2.25 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同步 package.json 和 testtool.yaml 中的版本号。 --- playwright/package.json | 2 +- playwright/testtool.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/playwright/package.json b/playwright/package.json index 906fc97..45b2cb3 100644 --- a/playwright/package.json +++ b/playwright/package.json @@ -1,6 +1,6 @@ { "name": "testsolar-oss-playwright", - "version": "0.2.24", + "version": "0.2.25", "description": "TestSolar support for playwright tool", "main": "main.js", "scripts": { diff --git a/playwright/testtool.yaml b/playwright/testtool.yaml index 1f0b2ff..622b908 100644 --- a/playwright/testtool.yaml +++ b/playwright/testtool.yaml @@ -2,7 +2,7 @@ schemaVersion: 1.0 name: playwright nameZh: Playwright自动化测试 lang: javascript -version: '0.2.24' +version: '0.2.25' defaultBaseImage: node:18 langType: INTERPRETED description: |- From a85d1c2c490fba6abaed70b6a21a35905442b099 Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Wed, 7 Jan 2026 15:31:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20utils.ts=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正 utils.ts 中的工具函数逻辑,确保功能正常运行。 --- playwright/package.json | 2 +- playwright/src/playwrightx/utils.ts | 18 ++++++++++++++---- playwright/testtool.yaml | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/playwright/package.json b/playwright/package.json index 45b2cb3..eede5e8 100644 --- a/playwright/package.json +++ b/playwright/package.json @@ -1,6 +1,6 @@ { "name": "testsolar-oss-playwright", - "version": "0.2.25", + "version": "0.2.26", "description": "TestSolar support for playwright tool", "main": "main.js", "scripts": { diff --git a/playwright/src/playwrightx/utils.ts b/playwright/src/playwrightx/utils.ts index f8dda3f..9c6fbfb 100644 --- a/playwright/src/playwrightx/utils.ts +++ b/playwright/src/playwrightx/utils.ts @@ -356,7 +356,9 @@ export function generateCommands( // 默认启用环境变量JSON文件,除非明确设置为"0"才禁用 const useEnvJsonFile = process.env.TESTSOLAR_TTP_ENVJSONFILE !== "0"; - + const runAllCases = process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "1" || + process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "true"; + // 默认启用trace,只有当明确设置TESTSOLAR_TTP_TRACE为"0"时才关闭 const disableTrace = process.env.TESTSOLAR_TTP_TRACE === "0"; const traceOption = disableTrace ? "--trace off" : "--trace on"; @@ -376,7 +378,7 @@ export function generateCommands( // 获取 grep 模式(在 fileMode 下不使用 grep) let grepPattern = ""; - if (testCases.length > 0 && !fileMode) { + if (testCases.length > 0 && !fileMode && !runAllCases) { grepPattern = `--grep="${decodeURIComponent(testCases.join("|"))}"`; } @@ -392,7 +394,11 @@ export function generateCommands( command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`; } } else { - command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`; + if (runAllCases) { + command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ./${casePath}/ --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`; + } else { + command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`; + } } } else { // 使用原始的重定向方式 @@ -404,7 +410,11 @@ export function generateCommands( command = `npx playwright test --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs} > ${jsonName}`; } } else { - command = `npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs} > ${jsonName}`; + if (runAllCases) { + command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ./${casePath}/ --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`; + } else { + command = `npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs} > ${jsonName}`; + } } } diff --git a/playwright/testtool.yaml b/playwright/testtool.yaml index 622b908..ccbcf40 100644 --- a/playwright/testtool.yaml +++ b/playwright/testtool.yaml @@ -2,7 +2,7 @@ schemaVersion: 1.0 name: playwright nameZh: Playwright自动化测试 lang: javascript -version: '0.2.25' +version: '0.2.26' defaultBaseImage: node:18 langType: INTERPRETED description: |-