Skip to content

Commit

Permalink
enable cross-browser testing in cucumber reporter (via #737)
Browse files Browse the repository at this point in the history
  • Loading branch information
aartajew authored Aug 4, 2023
1 parent a7e8fb2 commit b0201a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/allure-cucumberjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,17 @@ Given(/my step/, async function () {
});
});
```

## Cross-browser testing

For cross-browser testing simply add a parameter using Allure API with the browser name to the `World` instance inside your scenario, i.e.:

```js
await this.parameter('Browser', 'firefox')
```

For better presentation, you can also group suites by browser names, i.e.:

```js
await this.parentSuite('Firefox')
```
1 change: 1 addition & 0 deletions packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export class CucumberJSAllureFormatter extends Formatter {
currentTest.status = Status.PASSED;
}

currentTest.calculateHistoryId();
currentTest.endTest(Date.now());

this.currentTestsMap.delete(data.testCaseStartedId);
Expand Down
20 changes: 18 additions & 2 deletions packages/allure-cucumberjs/test/specs/simple_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ const dataSet: { [name: string]: ITestFormatterOptions } = {
},
],
},
parameterized: {
supportCodeLibrary: buildSupportCodeLibrary(({ Given }) => {
Given("a step", function () {
this.parameter("Browser", "firefox");
});
}),
sources: [
{
data: ["Feature: a", "Scenario: b", "Given a step"].join("\n"),
uri: "a.feature",
},
],
},
};

describe("CucumberJSAllureReporter > simple", () => {
Expand Down Expand Up @@ -76,17 +89,20 @@ describe("CucumberJSAllureReporter > simple", () => {
});

it("sets fullName, testCaseId and historyId", async () => {
const results = await runFeatures(dataSet.passed);
const results = await runFeatures(dataSet.parameterized);

expect(results.tests).length(1);
const [testResult] = results.tests;
const source = dataSet.passed.sources?.[0];

const name = source!.data.match(/\nScenario: (.+)\n/)?.[1];
const fullName = `${source!.uri}#${name!}`;
const { name: paramName, value: paramValue } = testResult.parameters[0];
const paramsHash = md5(`${paramName}:${paramValue}`);
const historyId = `${testResult.testCaseId}:${paramsHash}`;
expect(testResult.fullName).eq(fullName);
expect(testResult.testCaseId).eq(md5(fullName));
expect(testResult.historyId).eq(testResult.testCaseId);
expect(testResult.historyId).eq(historyId);
});
});

Expand Down

0 comments on commit b0201a4

Please sign in to comment.