From b47110e2393e1f953ee18855085757a43866c1cc Mon Sep 17 00:00:00 2001 From: Jonatas Kirsch Date: Sun, 26 Apr 2020 01:39:32 +0200 Subject: [PATCH] Issue #60 - Prepare all baselines of test by setting parameter in config --- README.md | 18 ++++++++++++------ index.js | 9 +++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bc75a17..6bb2c7f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # codeceptjs-resemblehelper -Helper for resemble.js, used for image comparison in tests with WebdriverIO. +Helper for resemble.js, used for image comparison in tests with WebdriverIO or Puppeteer. codeceptjs-resemblehelper is a [CodeceptJS](https://codecept.io/) helper which can be used to compare screenshots and make the tests fail/pass based on the tolerance allowed. @@ -21,19 +21,25 @@ Example: "ResembleHelper" : { "require": "codeceptjs-resemblehelper", "baseFolder": "./tests/screenshots/base/", - "diffFolder": "./tests/screenshots/diff/" + "diffFolder": "./tests/screenshots/diff/", + "prepareBaseImage": true } } } ``` -To use the Helper, users must provide the two parameters: +To use the Helper, users may provide the parameters: -`baseFolder`: This is the folder for base images, which will be used with screenshot for comparison. +`baseFolder`: Mandatory. This is the folder for base images, which will be used with screenshot for comparison. -`diffFolder`: This will the folder where resemble would try to store the difference image, which can be viewed later. +`diffFolder`: Mandatory. This will the folder where resemble would try to store the difference image, which can be viewed later. -Usage, these are major functions that help in visual testing +`prepareBaseImage`: Optional. When `true` then the system replaces all of the baselines related to the test case(s) you ran. This is equivalent of setting the option `prepareBaseImage: true` in all verifications of the test file. + + +### Usage + +These are the major functions that help in visual testing: First one is the `seeVisualDiff` which basically takes two parameters 1) `baseImage` Name of the base image, this will be the image used for comparison with the screenshot image. It is mandatory to have the same image file names for base and screenshot image. diff --git a/index.js b/index.js index ecb5383..0c47aa2 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ class ResembleHelper extends Helper { this.baseFolder = this.resolvePath(config.baseFolder); this.diffFolder = this.resolvePath(config.diffFolder); this.screenshotFolder = global.output_dir + "/"; + this.prepareBaseImage = config.prepareBaseImage; } resolvePath(folderPath) { @@ -177,7 +178,7 @@ class ResembleHelper extends Helper { * @param region * @param bucketName * @param baseImage - * @param ifBaseImage - tells if the prepareBaseImage is true or false. If false, then it won't upload the baseImage. + * @param ifBaseImage - tells if the prepareBaseImage is true or false. If false, then it won't upload the baseImage. However, this parameter is not considered if the config file has a prepareBaseImage set to true. * @returns {Promise} */ @@ -296,6 +297,10 @@ class ResembleHelper extends Helper { options.tolerance = 0; } + if (this.prepareBaseImage) { + options.prepareBaseImage = true; + } + const awsC = this.config.aws; if (awsC !== undefined && options.prepareBaseImage === false) { @@ -426,4 +431,4 @@ class ResembleHelper extends Helper { } } -module.exports = ResembleHelper; \ No newline at end of file +module.exports = ResembleHelper;