From 7b2680a09603721ffed945d9967b438986df8caa Mon Sep 17 00:00:00 2001 From: Arpan Patelia Date: Tue, 27 Aug 2024 12:00:18 +0530 Subject: [PATCH 1/4] (feat): Add basic test steps support --- src/generate-report.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/generate-report.ts b/src/generate-report.ts index e18a611..f042008 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -187,6 +187,20 @@ 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) => { + const stepStatus = + step.error !== undefined + ? this.mapPlaywrightStatusToCtrf('failed') + : this.mapPlaywrightStatusToCtrf('passed') + const currentStep = { + name: step.title, + status: stepStatus, + } + test.steps?.push(currentStep) + }) + } if (this.reporterConfigOptions.screenshot === true) { test.screenshot = this.extractScreenshotBase64(testResult) } From a27b725a31083b362945f97153518f973cb915c1 Mon Sep 17 00:00:00 2001 From: Arpan Patelia Date: Wed, 28 Aug 2024 02:13:20 +0530 Subject: [PATCH 2/4] feat: Add basic test steps support for test.step category only --- src/generate-report.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/generate-report.ts b/src/generate-report.ts index f042008..e6b7897 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -189,11 +189,14 @@ class GenerateCtrfReport implements Reporter { test.flaky = testResult.status === 'passed' && testResult.retry > 0 test.steps = [] if (testResult.steps.length > 0) { - testResult.steps.forEach((step) => { + const testSteps = testResult.steps.filter( + (step) => step.category === 'test.step' + ) + testSteps.forEach((step) => { const stepStatus = - step.error !== undefined - ? this.mapPlaywrightStatusToCtrf('failed') - : this.mapPlaywrightStatusToCtrf('passed') + step.error === undefined + ? this.mapPlaywrightStatusToCtrf('passed') + : this.mapPlaywrightStatusToCtrf('failed') const currentStep = { name: step.title, status: stepStatus, From 0a099e31184c7cda7f4ed082b70ff7b430c77b0c Mon Sep 17 00:00:00 2001 From: Arpan Patelia Date: Wed, 28 Aug 2024 21:49:39 +0530 Subject: [PATCH 3/4] fix: include previously left out Background steps - This fix will include steps from Background section of a BDD feature --- src/generate-report.ts | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/generate-report.ts b/src/generate-report.ts index e6b7897..e5744e3 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 { @@ -189,19 +190,8 @@ class GenerateCtrfReport implements Reporter { test.flaky = testResult.status === 'passed' && testResult.retry > 0 test.steps = [] if (testResult.steps.length > 0) { - const testSteps = testResult.steps.filter( - (step) => step.category === 'test.step' - ) - testSteps.forEach((step) => { - const stepStatus = - step.error === undefined - ? this.mapPlaywrightStatusToCtrf('passed') - : this.mapPlaywrightStatusToCtrf('failed') - const currentStep = { - name: step.title, - status: stepStatus, - } - test.steps?.push(currentStep) + testResult.steps.forEach((step) => { + this.processStep(test, step) }) } if (this.reporterConfigOptions.screenshot === true) { @@ -401,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 (step.category === 'hook' && childSteps.length > 0) { + childSteps.forEach((cStep) => { + this.processStep(test, cStep) + }) + } + } } export default GenerateCtrfReport From 99cabae6571a8c49a03e02215e030994f02f1614 Mon Sep 17 00:00:00 2001 From: Arpan Patelia Date: Thu, 29 Aug 2024 02:42:01 +0530 Subject: [PATCH 4/4] fix: include nested test.steps() for non-BDD tests - Update README to indicate 'steps' as a supported property of 'Test' object --- README.md | 1 + src/generate-report.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 e5744e3..85a6c1a 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -407,7 +407,7 @@ class GenerateCtrfReport implements Reporter { const childSteps = step.steps - if (step.category === 'hook' && childSteps.length > 0) { + if (childSteps.length > 0) { childSteps.forEach((cStep) => { this.processStep(test, cStep) })