diff --git a/README.md b/README.md index b727866..742047c 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,18 @@ Scenario('Compare CPU Usage Images', async (I) => { }); ``` +### Allure Reporter +Allure reports may also be generated directly from the tool. To do so, add +``` +"plugins": { + "allure": {} +} +``` +in the config file. +The attachments will be added to the report only when the calulated mismatch is greater than the given tolerance. +Set `output` to where the generated report is to be stored. Default is the output directory of the project. + +### AWS Support AWS S3 support to upload and download various images is also provided. It can be used by adding the *aws* code inside `"ResembleHelper"` in the `"helpers"` section in config file. The final result should look like: ```json diff --git a/index.js b/index.js index 070a376..100ca6b 100644 --- a/index.js +++ b/index.js @@ -92,6 +92,25 @@ class ResembleHelper extends Helper { else throw new Error("Method only works with Puppeteer"); } + /** + * This method attaches image attachments of the base, screenshot and diff to the allure reporter when the mismatch exceeds tolerance. + * @param baseImage + * @param misMatch + * @param tolerance + * @returns {Promise} + */ + + async _addAttachment(baseImage, misMatch, tolerance) { + const allure = codeceptjs.container.plugins('allure'); + const diffImage = "Diff_" + baseImage.split(".")[0] + ".png"; + + if(allure !== undefined && misMatch >= tolerance) { + allure.addAttachment('Base Image', fs.readFileSync(this.config.baseFolder + baseImage), 'image/png'); + allure.addAttachment('Screenshot Image', fs.readFileSync(this.config.screenshotFolder + baseImage), 'image/png'); + allure.addAttachment('Diff Image', fs.readFileSync(this.config.diffFolder + diffImage), 'image/png'); + } + } + /** * This method uploads the diff and screenshot images into the bucket with diff image under bucketName/diff/diffImage and the screenshot image as * bucketName/output/ssImage @@ -216,6 +235,8 @@ class ResembleHelper extends Helper { const misMatch = await this._fetchMisMatchPercentage(baseImage, options); + this._addAttachment(baseImage, misMatch, options.tolerance); + if(awsC !== undefined) { let ifUpload = options.prepareBaseImage === false ? false : true; await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, ifUpload) @@ -253,6 +274,8 @@ class ResembleHelper extends Helper { options.boundingBox = await this._getBoundingBox(selector); const misMatch = await this._fetchMisMatchPercentage(baseImage, options); + this._addAttachment(baseImage, misMatch, options.tolerance); + if(awsC !== undefined) { let ifUpload = options.prepareBaseImage === false ? false : true; await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, ifUpload)