Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playwright/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
14 changes: 14 additions & 0 deletions playwright/src/playwrightx/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`);
Expand Down
24 changes: 20 additions & 4 deletions playwright/src/playwrightx/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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("|"))}"`;
}

Expand All @@ -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 {
// 使用原始的重定向方式
Expand All @@ -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}`;
}
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion playwright/testtool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down
Loading