Skip to content

Commit 845a018

Browse files
authored
Merge pull request #26 from Kartikeya99/reporter
Added allure reporter functionality
2 parents f38d152 + 5721a69 commit 845a018

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

README.md

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

105+
### Allure Reporter
106+
Allure reports may also be generated directly from the tool. To do so, add
107+
```
108+
"plugins": {
109+
"allure": {}
110+
}
111+
```
112+
in the config file.
113+
The attachments will be added to the report only when the calulated mismatch is greater than the given tolerance.
114+
Set `output` to where the generated report is to be stored. Default is the output directory of the project.
115+
116+
### AWS Support
105117
AWS S3 support to upload and download various images is also provided.
106118
It can be used by adding the *aws* code inside `"ResembleHelper"` in the `"helpers"` section in config file. The final result should look like:
107119
```json

index.js

+23
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ class ResembleHelper extends Helper {
9292
else throw new Error("Method only works with Puppeteer");
9393
}
9494

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 !== undefined && misMatch >= tolerance) {
108+
allure.addAttachment('Base Image', fs.readFileSync(this.config.baseFolder + baseImage), 'image/png');
109+
allure.addAttachment('Screenshot Image', fs.readFileSync(this.config.screenshotFolder + baseImage), 'image/png');
110+
allure.addAttachment('Diff Image', fs.readFileSync(this.config.diffFolder + diffImage), 'image/png');
111+
}
112+
}
113+
95114
/**
96115
* This method uploads the diff and screenshot images into the bucket with diff image under bucketName/diff/diffImage and the screenshot image as
97116
* bucketName/output/ssImage
@@ -216,6 +235,8 @@ class ResembleHelper extends Helper {
216235

217236
const misMatch = await this._fetchMisMatchPercentage(baseImage, options);
218237

238+
this._addAttachment(baseImage, misMatch, options.tolerance);
239+
219240
if(awsC !== undefined) {
220241
let ifUpload = options.prepareBaseImage === false ? false : true;
221242
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, ifUpload)
@@ -253,6 +274,8 @@ class ResembleHelper extends Helper {
253274
options.boundingBox = await this._getBoundingBox(selector);
254275
const misMatch = await this._fetchMisMatchPercentage(baseImage, options);
255276

277+
this._addAttachment(baseImage, misMatch, options.tolerance);
278+
256279
if(awsC !== undefined) {
257280
let ifUpload = options.prepareBaseImage === false ? false : true;
258281
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, ifUpload)

0 commit comments

Comments
 (0)