diff --git a/playwright/package.json b/playwright/package.json index 906fc97..eede5e8 100644 --- a/playwright/package.json +++ b/playwright/package.json @@ -1,6 +1,6 @@ { "name": "testsolar-oss-playwright", - "version": "0.2.24", + "version": "0.2.26", "description": "TestSolar support for playwright tool", "main": "main.js", "scripts": { 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..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}`; + } } } @@ -724,6 +734,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 +754,10 @@ export function createTestResults( const testFilePath = testCase.split('?')[0]; isInTestIdentifiers = testIdentifiers.includes(testFilePath); } + + if (runAllCases && !isInTestIdentifiers) { + isInTestIdentifiers = true; + } // 处理每个结果 for (const result of results) { diff --git a/playwright/testtool.yaml b/playwright/testtool.yaml index 1f0b2ff..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.24' +version: '0.2.26' defaultBaseImage: node:18 langType: INTERPRETED description: |-