Skip to content

Commit e901122

Browse files
author
Marc Rooding
committed
Added support for ‘After’ steps with an embedded screenshot
1 parent 4f1dfc7 commit e901122

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function gulpProtractorCucumberHtmlReport(opts) {
2222
headerTemplate: path.join(currentDir, './templates/header_template.html'),
2323
reportTemplate: path.join(currentDir, './templates/report_template.html'),
2424
scenarioTemplate: path.join(currentDir, './templates/scenario_template.html'),
25-
stepTemplate: path.join(currentDir, './templates/step_template.html')
25+
stepTemplate: path.join(currentDir, './templates/step_template.html'),
26+
screenshotTemplate: path.join(currentDir, './templates/screenshot_template.html')
2627
};
2728

2829
return through.obj(function (file, enc, cb) {

lib/html_formatter.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ module.exports = (function () {
3030
});
3131
}
3232

33+
/**
34+
* Checks if the step is an After step containing a screenshot
35+
* @param step - object which contains step data
36+
* @returns boolean
37+
*/
38+
function isAfterStepWithScreenshot(step) {
39+
return step.keyword.trim() === 'After'
40+
&& step.embeddings
41+
&& step.embeddings[0]
42+
&& step.embeddings[0].mime_type === 'image/png';
43+
}
3344

3445
/**
3546
* Return html code of step element based on step template
@@ -43,10 +54,26 @@ module.exports = (function () {
4354
return compiled({
4455
status: step.result ? step.result.status : '',
4556
errorDetails: step.result ? toHtmlEntities(step.result.error_message) : '',
57+
screenshot: step.embeddings && step.embeddings[0] ? step.embeddings[0].data : '',
4658
name: step.keyword + step.name
4759
});
4860
}
4961

62+
63+
/**
64+
* Return html code of step element based on step template
65+
* @param step - object which contains step data
66+
* @returns string
67+
*/
68+
function getAfterScreenshotStep(step) {
69+
var template = fs.readFileSync(templates.screenshotTemplate),
70+
compiled = lodashTemplate(template.toString());
71+
72+
return compiled({
73+
screenshot: step.embeddings && step.embeddings[0] ? step.embeddings[0].data : ''
74+
});
75+
}
76+
5077
/**
5178
* Return html code of scenario element based on scenario template
5279
* @param scenario - object which contains step data
@@ -148,14 +175,19 @@ module.exports = (function () {
148175
isPassed = true;
149176
for (var k = 0; k < testResults[i].elements[j].steps.length; k++) {
150177
step = testResults[i].elements[j].steps[k];
151-
stepsHtml += getStep(step);
152-
stepsNumber++;
153-
stepsNumberInFeature++;
154-
if (step.result.status !== statuses.PASSED) {
155-
isPassed = false;
156-
} else if (step.result.status === statuses.PASSED) {
157-
passedSteps++;
158-
passedStepsInFeature++;
178+
179+
if(isAfterStepWithScreenshot(step)) {
180+
stepsHtml += getAfterScreenshotStep(step);
181+
} else {
182+
stepsHtml += getStep(step);
183+
stepsNumber++;
184+
stepsNumberInFeature++;
185+
if (step.result.status !== statuses.PASSED) {
186+
isPassed = false;
187+
} else if (step.result.status === statuses.PASSED) {
188+
passedSteps++;
189+
passedStepsInFeature++;
190+
}
159191
}
160192
}
161193

templates/screenshot_template.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="step failed">
2+
<% if (screenshot) { %>
3+
<img src="data:image/png;base64,<%= screenshot %>" width="1050" />
4+
<% } %>
5+
</div>

0 commit comments

Comments
 (0)