Skip to content

Commit 2893282

Browse files
author
Hilscher, Robert
committed
Add functionality which is compatible with new template
1 parent 3bb7d79 commit 2893282

File tree

5 files changed

+125
-342
lines changed

5 files changed

+125
-342
lines changed

lib/html_formatter.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,18 @@ module.exports = (function() {
7575
* @param feature - object which contains feature data
7676
* @returns {*}
7777
*/
78-
function getFeature(feature) {
78+
function getFeature(feature, scenariosNumberInFeature, passedScenariosNumberInFeature, stepsNumberInFeature, passedStepsInFeature) {
7979

8080
var template = grunt.file.read(templates.featureTemplate),
8181
featureTemplate;
8282

8383
featureTemplate = grunt.template.process(template, {
8484
data:{
85-
name: feature.keyword + ": " +feature.name,
86-
description: feature.description
85+
name: feature.name,
86+
scenariosNumberInFeature: scenariosNumberInFeature,
87+
passedScenariosNumberInFeature: passedScenariosNumberInFeature,
88+
stepsNumberInFeature: stepsNumberInFeature,
89+
passedStepsInFeature: passedStepsInFeature
8790
}
8891
});
8992
return featureTemplate;
@@ -132,38 +135,52 @@ module.exports = (function() {
132135
passedSteps = 0,
133136
stepsNumber = 0,
134137
scenariosNumber = 0,
138+
scenariosNumberInFeature = 0,
139+
passedScenariosNumberInFeature = 0,
140+
stepsNumberInFeature = 0,
141+
passedStepsInFeature = 0,
142+
scenariosHtml = '',
135143
element,
136144
step;
137145

138146
for (var i = 0; i < testResults.length; i++) {
139147

140148
html = '';
141-
html += getFeature(testResults[i]);
149+
scenariosNumberInFeature = 0;
150+
passedScenariosNumberInFeature = 0;
151+
stepsNumberInFeature = 0;
152+
passedStepsInFeature = 0;
142153

143154
for (var j = 0; j < testResults[i].elements.length; j++) {
144155
element = testResults[i].elements[j];
145156
if (element.type === 'scenario') {
146157
scenariosNumber++;
158+
scenariosNumberInFeature++;
147159
stepsHtml = '';
148160
isPassed = true;
149161
for (var k = 0; k < testResults[i].elements[j].steps.length; k++) {
150162
step = testResults[i].elements[j].steps[k];
151163
stepsHtml += getStep(step);
152164
stepsNumber++;
165+
stepsNumberInFeature++;
153166
if (step.result.status !== statuses.PASSED) {
154167
isPassed = false;
155168
} else if (step.result.status === statuses.PASSED) {
156169
passedSteps++;
170+
passedStepsInFeature++;
157171
}
158172
}
159173

160174
if (isPassed) {
161175
passedScenarios++;
176+
passedScenariosNumberInFeature++;
162177
}
163-
html += '<div class="scenario-container">' + getScenario(element, isPassed);
164-
html += stepsHtml + '</div>';
178+
scenariosHtml += '<div class="scenario-container">' + getScenario(element, isPassed);
179+
scenariosHtml += stepsHtml + '</div>';
165180
}
166181
}
182+
html += getFeature(testResults[i],scenariosNumberInFeature, passedScenariosNumberInFeature, stepsNumberInFeature, passedStepsInFeature);
183+
html += scenariosHtml;
167184
}
168185
header = getHeader(scenariosNumber, passedScenarios, stepsNumber, passedSteps);
169186
return header + html;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "grunt-protractor-cucumber-html-report",
33
"description": "Generate html report from JSON file returned by cucumber-js json formatter",
4-
"version": "0.0.3",
4+
"version": "0.0.5",
55
"homepage": "https://github.com/robhil/grunt-protractor-cucumber-html-report",
66
"author": {
77
"name": "Hilscher, Robert",

tasks/protractor-cucumber-html-report.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ module.exports = function(grunt) {
3939
if (grunt.file.exists(jsonPath)) {
4040
testResults = grunt.file.readJSON(jsonPath);
4141
grunt.file.write(options.dest + '/' + options.output, formatter.generateReport(testResults, options.templates));
42+
43+
grunt.file.recurse('./templates/assets', function (abspath, rootdir, subdir, filename) {
44+
45+
grunt.file.copy(abspath, options.dest + '/assets/' + subdir + '/'+ filename);
46+
47+
});
48+
49+
4250
grunt.log.writeln('File ' + options.output + ' has been created in \'' + options.dest + '\' directory');
4351
} else {
4452
grunt.log.error('File ' + jsonPath + ' doesn\'t exists');

templates/feature_template.html

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
<div class="col-md-9 col-sm-8">
2-
<div class="feature">
3-
<h2><i class="fa fa-magic"></i> Feature:</h2>
1+
<div class="row">
2+
<div class="col-md-9 col-sm-8">
3+
<div class="feature">
4+
<h2><i class="fa fa-magic"></i> Feature:</h2>
45

5-
<div class="feature-description">
6-
<%= name %>
6+
<div class="feature-description">
7+
<%= name %>
8+
</div>
79
</div>
810
</div>
9-
</div>
10-
<div class="col-md-3 col-sm-4 feature-statistics">
11-
<div class="scenario-label">Scenarios</div>
12-
<div class="scenario-amount-passed"> 2/3 <br/><span>passed</span></div>
13-
<div class="clear"></div>
14-
<div class="steps-label">Steps</div>
15-
<div class="steps-amount-passed">5/7 <br/><span>passed</span></div>
11+
<div class="col-md-3 col-sm-4 feature-statistics">
12+
<div class="scenario-label">Scenarios</div>
13+
<div class="scenario-amount-passed"> <%= passedScenariosNumberInFeature %>/<%= scenariosNumberInFeature %> <br/><span>passed</span></div>
14+
<div class="clear"></div>
15+
<div class="steps-label">Steps</div>
16+
<div class="steps-amount-passed"> <%= passedStepsInFeature %>/<%= stepsNumberInFeature %> <br/><span>passed</span></div>
17+
</div>
1618
</div>

0 commit comments

Comments
 (0)