Skip to content

Added allure reporter functionality #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down