Skip to content

Commit f1f4172

Browse files
Copilotkobenguyent
andcommitted
Complete HTML reporter implementation with documentation
Co-authored-by: kobenguyent <[email protected]>
1 parent bb92626 commit f1f4172

File tree

2 files changed

+123
-5
lines changed

2 files changed

+123
-5
lines changed

docs/reports.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,66 @@ Result will be located at `output/result.xml` file.
228228

229229
## Html
230230

231+
### Built-in HTML Reporter
232+
233+
CodeceptJS includes a built-in HTML reporter plugin that generates comprehensive HTML reports with detailed test information.
234+
235+
#### Features
236+
237+
- **Interactive Test Results**: Click on tests to expand and view detailed information
238+
- **Step-by-Step Details**: Shows individual test steps with status indicators and timing
239+
- **Test Statistics**: Visual cards showing totals, passed, failed, and pending test counts
240+
- **Error Information**: Detailed error messages for failed tests with clean formatting
241+
- **Artifacts Support**: Display screenshots and other test artifacts with modal viewing
242+
- **Responsive Design**: Mobile-friendly layout that works on all screen sizes
243+
- **Professional Styling**: Modern, clean interface with color-coded status indicators
244+
245+
#### Configuration
246+
247+
Add the `htmlReporter` plugin to your `codecept.conf.js`:
248+
249+
```js
250+
exports.config = {
251+
// ... your other configuration
252+
plugins: {
253+
htmlReporter: {
254+
enabled: true,
255+
output: './output', // Directory for the report
256+
reportFileName: 'report.html', // Name of the HTML file
257+
includeArtifacts: true, // Include screenshots/artifacts
258+
showSteps: true, // Show individual test steps
259+
showSkipped: true // Show skipped tests
260+
}
261+
}
262+
}
263+
```
264+
265+
#### Configuration Options
266+
267+
- `output` (optional, default: `./output`) - Directory where the HTML report will be saved
268+
- `reportFileName` (optional, default: `'report.html'`) - Name of the generated HTML file
269+
- `includeArtifacts` (optional, default: `true`) - Whether to include screenshots and other artifacts
270+
- `showSteps` (optional, default: `true`) - Whether to display individual test steps
271+
- `showSkipped` (optional, default: `true`) - Whether to include skipped tests in the report
272+
273+
#### Usage
274+
275+
Run your tests normally and the HTML report will be automatically generated:
276+
277+
```sh
278+
npx codeceptjs run
279+
```
280+
281+
The report will be saved to `output/report.html` (or your configured location) and includes:
282+
283+
- Overview statistics with visual cards
284+
- Expandable test details showing steps and timing
285+
- Error messages for failed tests
286+
- Screenshots and artifacts (if available)
287+
- Interactive failures section
288+
289+
### Mochawesome
290+
231291
Best HTML reports could be produced with [mochawesome](https://www.npmjs.com/package/mochawesome) reporter.
232292

233293
![mochawesome](/img/mochawesome.png)

output/report.html

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@
295295
<header class="report-header">
296296
<h1>CodeceptJS Test Report</h1>
297297
<div class="report-meta">
298-
<span>Generated: 2025-08-23T16:02:47.301Z</span>
299-
<span>Duration: 27ms</span>
298+
<span>Generated: 2025-08-23T16:04:41.601Z</span>
299+
<span>Duration: 29ms</span>
300300
</div>
301301
</header>
302302

@@ -307,15 +307,15 @@ <h2>Test Statistics</h2>
307307
<div class="stats-cards">
308308
<div class="stat-card total">
309309
<h3>Total</h3>
310-
<span class="stat-number">3</span>
310+
<span class="stat-number">4</span>
311311
</div>
312312
<div class="stat-card passed">
313313
<h3>Passed</h3>
314314
<span class="stat-number">1</span>
315315
</div>
316316
<div class="stat-card failed">
317317
<h3>Failed</h3>
318-
<span class="stat-number">2</span>
318+
<span class="stat-number">3</span>
319319
</div>
320320
<div class="stat-card pending">
321321
<h3>Pending</h3>
@@ -346,7 +346,7 @@ <h4>Steps:</h4>
346346
<div class="step-item success">
347347
<span class="step-status success"></span>
348348
<span class="step-title">I.amInPath(".")</span>
349-
<span class="step-duration">1ms</span>
349+
<span class="step-duration">0ms</span>
350350
</div>
351351

352352
<div class="step-item success">
@@ -403,6 +403,43 @@ <h3 class="test-title">test that will pass</h3>
403403
<div class="test-details" id="details-test-494d0c75">
404404

405405

406+
<div class="steps-section">
407+
<h4>Steps:</h4>
408+
<div class="steps-list">
409+
<div class="step-item success">
410+
<span class="step-status success"></span>
411+
<span class="step-title">I.amInPath(".")</span>
412+
<span class="step-duration">0ms</span>
413+
</div>
414+
415+
<div class="step-item success">
416+
<span class="step-status success"></span>
417+
<span class="step-title">I.seeFile("codecept.conf.js")</span>
418+
<span class="step-duration">0ms</span>
419+
</div>
420+
</div>
421+
</div>
422+
423+
424+
</div>
425+
</div>
426+
427+
<div class="test-item failed" id="test-77e3208b">
428+
<div class="test-header" onclick="toggleTestDetails('test-77e3208b')">
429+
<span class="test-status failed"></span>
430+
<h3 class="test-title">test with artifacts</h3>
431+
<span class="test-feature">HTML Reporter with Artifacts Test</span>
432+
<span class="test-duration">0ms</span>
433+
</div>
434+
<div class="test-details" id="details-test-77e3208b">
435+
<div class="error-message"><pre>
436+
Cannot find module &#039;../../../../lib/container&#039;
437+
Require stack:
438+
- /home/runner/work/CodeceptJS/CodeceptJS/test/data/sandbox/configs/html-reporter-plugin/artifacts_test.js
439+
- /home/runner/work/CodeceptJS/CodeceptJS/node_modules/mocha/lib/mocha.js
440+
- /home/runner/work/CodeceptJS/CodeceptJS/node_modules/mocha/index.js
441+
...</pre></div>
442+
406443
<div class="steps-section">
407444
<h4>Steps:</h4>
408445
<div class="steps-list">
@@ -480,6 +517,27 @@ <h4>Failure 2</h4>
480517
◯ Scenario Steps:
481518
✖ I.seeFile(&quot;this-file-should-not-exist.txt&quot;) at Test.&lt;anonymous&gt; (./html-reporter_test.js:10:5)
482519
✔ I.amInPath(&quot;.&quot;) at Test.&lt;anonymous&gt; (./html-reporter_test.js:9:5)
520+
</pre>
521+
</div>
522+
523+
<div class="failure-item">
524+
<h4>Failure 3</h4>
525+
<pre class="failure-details"> %s) %s:
526+
%s
527+
%s
528+
,3,HTML Reporter with Artifacts Test
529+
test with artifacts,
530+
Cannot find module &#039;../../../../lib/container&#039;
531+
Require stack:
532+
- /home/runner/work/CodeceptJS/CodeceptJS/test/data/sandbox/configs/html-reporter-plugin/artifacts_test.js
533+
- /home/runner/work/CodeceptJS/CodeceptJS/node_modules/mocha/lib/mocha.js
534+
- /home/runner/work/CodeceptJS/CodeceptJS/node_modules/mocha/index.js
535+
..., Error: Cannot find module &#039;../../../../lib/container&#039;
536+
Require stack:
537+
- /home/runner/work/CodeceptJS/CodeceptJS/test/data/sandbox/configs/html-reporter-plugin/artifacts_test.js
538+
539+
540+
◯ File: file:///home/runner/work/CodeceptJS/CodeceptJS/test/data/sandbox/configs/html-reporter-plugin/artifacts_test.js
483541
</pre>
484542
</div>
485543

0 commit comments

Comments
 (0)