From c2c76f1ae4a468ac01d23714dac352d0033834de Mon Sep 17 00:00:00 2001 From: Peter Nguyen Tr Date: Tue, 20 Oct 2020 07:10:17 +0200 Subject: [PATCH 1/4] support playwright helper (#81) --- index.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 99645fa..3e1e5e7 100644 --- a/index.js +++ b/index.js @@ -77,16 +77,16 @@ class ResembleHelper extends Helper { if (!data.isSameDimensions) { let dimensions1 = sizeOf(baseImage); let dimensions2 = sizeOf(actualImage); - reject(new Error("The base image is of " + dimensions1.height + " X " + dimensions1.width + " and actual image is of " + dimensions2.height + " X " + dimensions2.width + ". Please use images of same dimensions so as to avoid any unexpected results.")); + reject(new Error(`The base image is of ${dimensions1.height} X ${dimensions1.width} and actual image is of ${dimensions2.height} X ${dimensions2.width}. Please use images of same dimensions so as to avoid any unexpected results.`)); } resolve(data); if (data.misMatchPercentage >= tolerance) { if (!fs.existsSync(getDirName(this.diffFolder + diffImage))) { - fs.mkdirSync(getDirName(this.diffFolder + diffImage)); + fs.mkdirSync(getDirName(this.diffFolder + diffImage)); } fs.writeFileSync(this.diffFolder + diffImage + '.png', data.getBuffer()); const diffImagePath = path.join(process.cwd(), this.diffFolder + diffImage + '.png'); - this.debug("Diff Image File Saved to: " + diffImagePath); + this.debug(`Diff Image File Saved to: ${diffImagePath}`); } } }); @@ -114,15 +114,13 @@ class ResembleHelper extends Helper { */ async screenshotElement(selector, name) { const helper = this._getHelper(); - if (this.helpers['Puppeteer']) { + if (this.helpers['Puppeteer'] || this.helpers['Playwright']) { await helper.waitForVisible(selector); const els = await helper._locate(selector); if (!els.length) throw new Error(`Element ${selector} couldn't be located`); const el = els[0]; - await el.screenshot({ - path: global.output_dir + "/" + name + '.png' - }); + await el.screenshot({path: `${global.output_dir}/${name}.png`}); } else if (this.helpers['WebDriver']) { await helper.waitForVisible(selector); const els = await helper._locate(selector); @@ -137,7 +135,7 @@ class ResembleHelper extends Helper { const { t } = this.helpers['TestCafe']; await t.takeElementScreenshot(els, name); - } else throw new Error("Method only works with Puppeteer, WebDriver or TestCafe helpers."); + } else throw new Error("Method only works with Playwright, Puppeteer, WebDriver or TestCafe helpers."); } /** @@ -381,7 +379,7 @@ class ResembleHelper extends Helper { const helper = this._getHelper(); await helper.waitForVisible(selector); const els = await helper._locate(selector); - + if (this.helpers['TestCafe']) { if (await els.count != 1) throw new Error(`Element ${selector} couldn't be located or isn't unique on the page`); } @@ -391,7 +389,7 @@ class ResembleHelper extends Helper { let location, size; - if (this.helpers['Puppeteer']) { + if (this.helpers['Puppeteer'] || this.helpers['Playwright']) { const el = els[0]; const box = await el.boundingBox(); size = location = box; @@ -447,7 +445,11 @@ class ResembleHelper extends Helper { return this.helpers['TestCafe']; } - throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/Puppeteer/TestCafe'); + if (this.helpers['Playwright']) { + return this.helpers['Playwright']; + } + + throw new Error('No matching helper found. Supported helpers: Playwright/WebDriver/Appium/Puppeteer/TestCafe'); } } From fad954be00f8fdd6c1085022dfcdffca4456c65d Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 20 Oct 2020 07:12:31 +0200 Subject: [PATCH 2/4] Default to config.prepareBaseImage if no param specified (#79) * Update index.js We are only downloading the base image if the `options` param explicitly includes the option `{prepareBaseImage: false}`. Otherwise, it will omit downloading the base file, even if the helper configuration includes the prepareBaseImage option. This change allows us to default to the value in the config file if the method doesn't receive that param. * Update index.js --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 3e1e5e7..65662db 100644 --- a/index.js +++ b/index.js @@ -306,12 +306,11 @@ class ResembleHelper extends Helper { options.tolerance = 0; } - if (this.prepareBaseImage) { - options.prepareBaseImage = true; - } - + const prepareBaseImage = options.prepareBaseImage !== undefined + ? options.prepareBaseImage + : (this.prepareBaseImage === true) const awsC = this.config.aws; - if (awsC !== undefined && options.prepareBaseImage === false) { + if (awsC !== undefined && prepareBaseImage === false) { await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage); } if (options.prepareBaseImage !== undefined && options.prepareBaseImage) { From abb968575404208f087d2860be468282878bf19c Mon Sep 17 00:00:00 2001 From: Shan Date: Tue, 20 Oct 2020 01:16:08 -0400 Subject: [PATCH 3/4] Fix bug - baseline and comparison images write mode (#75) (#76) --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 65662db..680741d 100644 --- a/index.js +++ b/index.js @@ -42,17 +42,19 @@ class ResembleHelper extends Helper { const actualImage = this.screenshotFolder + image; // check whether the base and the screenshot images are present. - fs.access(baseImage, fs.constants.F_OK | fs.constants.W_OK, (err) => { + fs.access(baseImage, fs.constants.F_OK | fs.constants.R_OK, (err) => { if (err) { throw new Error( - `${baseImage} ${err.code === 'ENOENT' ? 'base image does not exist' : 'is read-only'}`); + `${baseImage} ${err.code === 'ENOENT' ? 'base image does not exist' : + 'base image has an access error'}`); } }); - fs.access(actualImage, fs.constants.F_OK | fs.constants.W_OK, (err) => { + fs.access(actualImage, fs.constants.F_OK | fs.constants.R_OK, (err) => { if (err) { throw new Error( - `${actualImage} ${err.code === 'ENOENT' ? 'screenshot image does not exist' : 'is read-only'}`); + `${actualImage} ${err.code === 'ENOENT' ? 'screenshot image does not exist' : + 'screenshot image has an access error'}`); } }); From d513ef0ea66a739e0135b1ba758aec572a7720d2 Mon Sep 17 00:00:00 2001 From: Puneet Kala Date: Wed, 21 Oct 2020 09:50:10 +0530 Subject: [PATCH 4/4] Prepare for 1.9.3 release --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7d07f9f..33bfb7b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "codeceptjs-resemblehelper", - "version": "1.9.2", - "description": "Resemble Js helper for CodeceptJS, with Support for Webdriver, Puppeteer & Appium", + "version": "1.9.3", + "description": "Resemble Js helper for CodeceptJS, with Support for Playwright, Webdriver, TestCafe, Puppeteer & Appium", "repository": { "type": "git", "url": "git@github.com:Percona-Lab/codeceptjs-resemblehelper.git"