Skip to content

Commit 2db0fbe

Browse files
committed
feat(bdd): add bdd android test report
1 parent b1653f5 commit 2db0fbe

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

apps/bdd/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"report:cucumber": "node scripts/generate-cucumber-report.js",
2121
"test:report": "node scripts/bdd-test-report.js",
2222
"test:local:report": "node scripts/bdd-test-report.js test:web:local",
23+
"test:android:report": "node scripts/bdd-test-report.js test:native:android",
2324
"test:native:android": "cross-env PLATFORM=android wdio run ./wdio.mobile.conf.ts",
2425
"test:native:ios": "cross-env PLATFORM=ios wdio run ./wdio.mobile.conf.ts"
2526
},
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/**
22
* Run BDD tests and ALWAYS generate the HTML report.
3-
* - Executes `yarn test`, then `yarn report:cucumber` regardless of pass/fail.
4-
* - Exits with the original test exit code (so CI still reflects failures).
5-
* Usage: from root `yarn bdd:test:report`, `yarn bdd:test:report:local`, or here `yarn test:report`.
3+
* - Executes the selected yarn BDD test script
4+
* - Always runs `yarn report:cucumber`
5+
* - Preserves the original exit code for CI
6+
* Usage: yarn bdd:test [test:web|test:native:android]
67
*/
8+
79
const { spawn } = require("node:child_process");
810

911
function run(cmd, args) {
@@ -14,13 +16,15 @@ function run(cmd, args) {
1416
}
1517

1618
(async () => {
17-
// Accept an optional script name (e.g., "test:local"); default to "test"
18-
const which = (process.argv[2] || "test:web").trim();
19+
const script = (process.argv[2] || "test:web").trim();
20+
21+
const ALLOWED = new Set(["test:web", "test:native:android"]);
22+
23+
const testScript = ALLOWED.has(script) ? script : "test:web";
24+
25+
const testExitCode = await run("yarn", [testScript]);
1926

20-
// Basic guard: only allow scripts that start with "test"
21-
const testScript = which.startsWith("test") ? which : "test:web";
27+
await run("yarn", ["report:cucumber"]);
2228

23-
const testExit = await run("yarn", [testScript]); // run chosen test script
24-
await run("yarn", ["report:cucumber"]); // always generate report
25-
process.exit(testExit); // preserve test exit code
29+
process.exit(testExitCode);
2630
})();

apps/bdd/wdio.base.conf.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,27 @@ import {
1212
FEATURE_BUCKET_BY_CID,
1313
} from "./utils/artifacts";
1414

15-
// Define a base config type that matches your specific service configurations
1615
interface CustomTestrunner extends Omit<Options.Testrunner, "services"> {
1716
services?: (string | object)[];
1817
}
18+
function getEnvMetadata(caps: any) {
19+
if (caps.browserName) {
20+
return {
21+
Platform: caps.platformName || process.platform,
22+
Browser: caps.browserName,
23+
"Browser Version": caps.browserVersion || caps.version || "unknown",
24+
};
25+
} else {
26+
return {
27+
Platform: caps.platformName || "Android",
28+
Device: caps["appium:deviceName"] ?? caps.deviceName ?? "Unknown device",
29+
"OS Version":
30+
caps["appium:platformVersion"] ?? caps.platformVersion ?? "Unknown",
31+
Automation:
32+
caps["appium:automationName"] ?? caps.automationName ?? "Appium",
33+
};
34+
}
35+
}
1936

2037
export const baseConfig: CustomTestrunner = {
2138
// ====================
@@ -68,6 +85,10 @@ export const baseConfig: CustomTestrunner = {
6885
"cucumberjs-json",
6986
{
7087
jsonFolder: path.join(REPORTS_ROOT, "cucumber"),
88+
metadata: {
89+
Framework: "WebdriverIO",
90+
Type: "BDD",
91+
},
7192
},
7293
],
7394
],
@@ -118,6 +139,20 @@ export const baseConfig: CustomTestrunner = {
118139
fs.mkdirSync(framesRootDir, { recursive: true });
119140
},
120141

142+
beforeSession: function (_config: any, caps: any) {
143+
const meta = getEnvMetadata(caps);
144+
const cid = process.env.WDIO_WORKER_ID || "global";
145+
146+
Object.entries(meta).forEach(([key, value]) => {
147+
try {
148+
(cucumberJson as any).addMetadata(
149+
cid === "global" ? key : `${key} (${cid})`,
150+
value,
151+
);
152+
} catch {}
153+
});
154+
},
155+
121156
beforeFeature: function (uri: string) {
122157
const cid =
123158
process.env.WDIO_WORKER_ID || (global as any).browser?.config?.cid || "";

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"bdd:test:report": "yarn workspace @treetracker/bdd run test:report",
5151
"bdd:test:local:report": "yarn workspace @treetracker/bdd run test:local:report",
5252
"bdd:test:android": "yarn workspace @treetracker/bdd run test:native:android",
53+
"bdd:test:android:report": "yarn workspace @treetracker/bdd run test:android:report",
5354
"bdd:test:ios": "yarn workspace @treetracker/bdd run test:native:ios",
5455
"native:bdd:test": "yarn workspace native run wdio",
5556
"build-apk-android": "yarn workspace native run build-android",

0 commit comments

Comments
 (0)