Skip to content

Commit 7173ede

Browse files
committed
Added allure reporter functionality
1 parent 5dc650f commit 7173ede

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,12 @@ Scenario('Compare CPU Usage Images', async (I) => {
102102
});
103103
```
104104

105+
Allure reports may also be generated directly from the tool. To do so, add
106+
```
107+
"plugins": {
108+
"allure": {}
109+
}
110+
```
111+
in the config file.
112+
The attachments will be added to the report only when the calulated mismatch is greater than the given tolerance.
113+
Set `output` to where the generated report is to be stored. Default is the output directory of the project.

index.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const resemble = require("resemblejs");
22
const fs = require('fs');
33
const assert = require('assert');
44
const mkdirp = require('mkdirp');
5-
const getDirName = require('path').dirname;
5+
const path = require('path');
6+
const getDirName = path.dirname;
67

78
/**
89
* Resemble.js helper class for CodeceptJS, this allows screen comparison
@@ -91,6 +92,25 @@ class ResembleHelper extends Helper {
9192
else throw new Error("Method only works with Puppeteer");
9293
}
9394

95+
/**
96+
* This method attaches image attachments of the base, screenshot and diff to the allure reporter when the mismatch exceeds tolerance.
97+
* @param baseImage
98+
* @param misMatch
99+
* @param tolerance
100+
* @returns {Promise<void>}
101+
*/
102+
103+
async _addAttachment(baseImage, misMatch, tolerance) {
104+
const allure = codeceptjs.container.plugins('allure');
105+
const diffImage = "Diff_" + baseImage.split(".")[0] + ".png";
106+
107+
if(allure && misMatch >= tolerance) {
108+
allure.addAttachment('Base Image', fs.readFileSync(path.join(this.config.baseFolder, baseImage)), 'image/png');
109+
allure.addAttachment('Screenshot Image', fs.readFileSync(path.join(this.config.screenshotFolder, baseImage)), 'image/png');
110+
allure.addAttachment('Diff Image', fs.readFileSync(path.join(this.config.diffFolder, diffImage)), 'image/png');
111+
}
112+
}
113+
94114
/**
95115
* Check Visual Difference for Base and Screenshot Image
96116
* @param baseImage Name of the Base Image (Base Image path is taken from Configuration)
@@ -108,6 +128,9 @@ class ResembleHelper extends Helper {
108128
}
109129

110130
const misMatch = await this._fetchMisMatchPercentage(baseImage, options);
131+
132+
this._addAttachment(baseImage, misMatch, options.tolerance);
133+
111134
this.debug("MisMatch Percentage Calculated is " + misMatch);
112135
assert(misMatch <= options.tolerance, "MissMatch Percentage " + misMatch);
113136
}
@@ -133,6 +156,9 @@ class ResembleHelper extends Helper {
133156

134157
options.boundingBox = await this._getBoundingBox(selector);
135158
const misMatch = await this._fetchMisMatchPercentage(baseImage, options);
159+
160+
this._addAttachment(baseImage, misMatch, options.tolerance);
161+
136162
this.debug("MisMatch Percentage Calculated is " + misMatch);
137163
assert(misMatch <= options.tolerance, "MissMatch Percentage " + misMatch);
138164
}

0 commit comments

Comments
 (0)