diff --git a/README.md b/README.md index d6664e0..4344b6b 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ The test object in the report includes the following [CTRF properties](https://c | `flaky` | Boolean | Optional | Indicates whether the test result is flaky. | | `browser` | String | Optional | The browser used for the test. | | `screenshot` | String | Optional | A base64 encoded screenshot taken during the test. | +| `steps` | Array of Objects | Optional | Individual steps in the test, especially for BDD-style testing. | ## Advanced usage diff --git a/src/generate-report.ts b/src/generate-report.ts index e18a611..85a6c1a 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -7,6 +7,7 @@ import { type TestCase, type TestResult, type FullConfig, + type TestStep, } from '@playwright/test/reporter' import { @@ -187,6 +188,12 @@ class GenerateCtrfReport implements Reporter { test.filePath = testCase.location.file test.retries = testResult.retry test.flaky = testResult.status === 'passed' && testResult.retry > 0 + test.steps = [] + if (testResult.steps.length > 0) { + testResult.steps.forEach((step) => { + this.processStep(test, step) + }) + } if (this.reporterConfigOptions.screenshot === true) { test.screenshot = this.extractScreenshotBase64(testResult) } @@ -384,6 +391,28 @@ class GenerateCtrfReport implements Reporter { console.error(`Error writing ctrf json report:, ${String(error)}`) } } + + processStep(test: CtrfTest, step: TestStep): void { + if (step.category === 'test.step') { + const stepStatus = + step.error === undefined + ? this.mapPlaywrightStatusToCtrf('passed') + : this.mapPlaywrightStatusToCtrf('failed') + const currentStep = { + name: step.title, + status: stepStatus, + } + test.steps?.push(currentStep) + } + + const childSteps = step.steps + + if (childSteps.length > 0) { + childSteps.forEach((cStep) => { + this.processStep(test, cStep) + }) + } + } } export default GenerateCtrfReport