Skip to content

Commit db839a7

Browse files
authored
Merge pull request #42 from OpenTestSolar/dev/add-run-all-cases
feat: add RUN_ALL_CASES mode support
2 parents 4b2a6ef + a85d1c2 commit db839a7

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎playwright/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "testsolar-oss-playwright",
3-
"version": "0.2.24",
3+
"version": "0.2.26",
44
"description": "TestSolar support for playwright tool",
55
"main": "main.js",
66
"scripts": {

‎playwright/src/playwrightx/parser.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ export async function collectTestCases(
2929
const result = new LoadResult(test, loadError);
3030

3131
try {
32+
// 检查是否启用 RUN_ALL_CASES 模式
33+
const runAllCases = process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "1" ||
34+
process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "true";
35+
36+
if (runAllCases) {
37+
log.info("[Load] 执行一条命令运行当前项目的所有用例");
38+
// 直接透传用例名称,不解析
39+
testSelectors.forEach((selector: string) => {
40+
const testCase = new TestCase(selector, {});
41+
result.Tests.push(testCase);
42+
});
43+
return result;
44+
}
45+
3246
// 进入projPath目录
3347
process.chdir(projPath);
3448
log.info(`Current directory: ${process.cwd()}`);

‎playwright/src/playwrightx/utils.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ export function generateCommands(
356356

357357
// 默认启用环境变量JSON文件,除非明确设置为"0"才禁用
358358
const useEnvJsonFile = process.env.TESTSOLAR_TTP_ENVJSONFILE !== "0";
359-
359+
const runAllCases = process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "1" ||
360+
process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "true";
361+
360362
// 默认启用trace,只有当明确设置TESTSOLAR_TTP_TRACE为"0"时才关闭
361363
const disableTrace = process.env.TESTSOLAR_TTP_TRACE === "0";
362364
const traceOption = disableTrace ? "--trace off" : "--trace on";
@@ -376,7 +378,7 @@ export function generateCommands(
376378

377379
// 获取 grep 模式(在 fileMode 下不使用 grep)
378380
let grepPattern = "";
379-
if (testCases.length > 0 && !fileMode) {
381+
if (testCases.length > 0 && !fileMode && !runAllCases) {
380382
grepPattern = `--grep="${decodeURIComponent(testCases.join("|"))}"`;
381383
}
382384

@@ -392,7 +394,11 @@ export function generateCommands(
392394
command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`;
393395
}
394396
} else {
395-
command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`;
397+
if (runAllCases) {
398+
command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ./${casePath}/ --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`;
399+
} else {
400+
command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`;
401+
}
396402
}
397403
} else {
398404
// 使用原始的重定向方式
@@ -404,7 +410,11 @@ export function generateCommands(
404410
command = `npx playwright test --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs} > ${jsonName}`;
405411
}
406412
} else {
407-
command = `npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs} > ${jsonName}`;
413+
if (runAllCases) {
414+
command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${jsonName} && npx playwright test ./${casePath}/ --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs}`;
415+
} else {
416+
command = `npx playwright test ${casePath} ${grepPattern} --reporter=json ${traceOption} ${workersOption} ${outputOption} ${extraArgs} > ${jsonName}`;
417+
}
408418
}
409419
}
410420

@@ -724,6 +734,8 @@ export function createTestResults(
724734

725735
// 检查是否为 fileMode
726736
const fileMode = process.env.TESTSOLAR_TTP_FILEMODE == "1";
737+
const runAllCases = process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "1" ||
738+
process.env.TESTSOLAR_TTP_RUNALLCASES?.toLowerCase() === "true";
727739

728740
// 首先找出参考失败用例(output中的key不在testIdentifiers中的)
729741
let referenceFailedTest: TestResult | null = null;
@@ -742,6 +754,10 @@ export function createTestResults(
742754
const testFilePath = testCase.split('?')[0];
743755
isInTestIdentifiers = testIdentifiers.includes(testFilePath);
744756
}
757+
758+
if (runAllCases && !isInTestIdentifiers) {
759+
isInTestIdentifiers = true;
760+
}
745761

746762
// 处理每个结果
747763
for (const result of results) {

‎playwright/testtool.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ schemaVersion: 1.0
22
name: playwright
33
nameZh: Playwright自动化测试
44
lang: javascript
5-
version: '0.2.24'
5+
version: '0.2.26'
66
defaultBaseImage: node:18
77
langType: INTERPRETED
88
description: |-

0 commit comments

Comments
 (0)