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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions src/generate-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type TestCase,
type TestResult,
type FullConfig,
type TestStep,
} from '@playwright/test/reporter'

import {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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