Skip to content

Commit 6401b45

Browse files
puneet0191kobenguyentcaragpeshanplourde
authored
Prepare for version 1.9.3 (#82)
* support playwright helper (#81) * 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 * Fix bug - baseline and comparison images write mode (#75) (#76) * Prepare for 1.9.3 release Co-authored-by: Peter Nguyen Tr <[email protected]> Co-authored-by: Carlos <[email protected]> Co-authored-by: Shan <[email protected]>
1 parent d163f6d commit 6401b45

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

index.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ class ResembleHelper extends Helper {
4242
const actualImage = this.screenshotFolder + image;
4343

4444
// check whether the base and the screenshot images are present.
45-
fs.access(baseImage, fs.constants.F_OK | fs.constants.W_OK, (err) => {
45+
fs.access(baseImage, fs.constants.F_OK | fs.constants.R_OK, (err) => {
4646
if (err) {
4747
throw new Error(
48-
`${baseImage} ${err.code === 'ENOENT' ? 'base image does not exist' : 'is read-only'}`);
48+
`${baseImage} ${err.code === 'ENOENT' ? 'base image does not exist' :
49+
'base image has an access error'}`);
4950
}
5051
});
5152

52-
fs.access(actualImage, fs.constants.F_OK | fs.constants.W_OK, (err) => {
53+
fs.access(actualImage, fs.constants.F_OK | fs.constants.R_OK, (err) => {
5354
if (err) {
5455
throw new Error(
55-
`${actualImage} ${err.code === 'ENOENT' ? 'screenshot image does not exist' : 'is read-only'}`);
56+
`${actualImage} ${err.code === 'ENOENT' ? 'screenshot image does not exist' :
57+
'screenshot image has an access error'}`);
5658
}
5759
});
5860

@@ -77,16 +79,16 @@ class ResembleHelper extends Helper {
7779
if (!data.isSameDimensions) {
7880
let dimensions1 = sizeOf(baseImage);
7981
let dimensions2 = sizeOf(actualImage);
80-
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."));
82+
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.`));
8183
}
8284
resolve(data);
8385
if (data.misMatchPercentage >= tolerance) {
8486
if (!fs.existsSync(getDirName(this.diffFolder + diffImage))) {
85-
fs.mkdirSync(getDirName(this.diffFolder + diffImage));
87+
fs.mkdirSync(getDirName(this.diffFolder + diffImage));
8688
}
8789
fs.writeFileSync(this.diffFolder + diffImage + '.png', data.getBuffer());
8890
const diffImagePath = path.join(process.cwd(), this.diffFolder + diffImage + '.png');
89-
this.debug("Diff Image File Saved to: " + diffImagePath);
91+
this.debug(`Diff Image File Saved to: ${diffImagePath}`);
9092
}
9193
}
9294
});
@@ -114,15 +116,13 @@ class ResembleHelper extends Helper {
114116
*/
115117
async screenshotElement(selector, name) {
116118
const helper = this._getHelper();
117-
if (this.helpers['Puppeteer']) {
119+
if (this.helpers['Puppeteer'] || this.helpers['Playwright']) {
118120
await helper.waitForVisible(selector);
119121
const els = await helper._locate(selector);
120122
if (!els.length) throw new Error(`Element ${selector} couldn't be located`);
121123
const el = els[0];
122124

123-
await el.screenshot({
124-
path: global.output_dir + "/" + name + '.png'
125-
});
125+
await el.screenshot({path: `${global.output_dir}/${name}.png`});
126126
} else if (this.helpers['WebDriver']) {
127127
await helper.waitForVisible(selector);
128128
const els = await helper._locate(selector);
@@ -137,7 +137,7 @@ class ResembleHelper extends Helper {
137137
const { t } = this.helpers['TestCafe'];
138138

139139
await t.takeElementScreenshot(els, name);
140-
} else throw new Error("Method only works with Puppeteer, WebDriver or TestCafe helpers.");
140+
} else throw new Error("Method only works with Playwright, Puppeteer, WebDriver or TestCafe helpers.");
141141
}
142142

143143
/**
@@ -308,12 +308,11 @@ class ResembleHelper extends Helper {
308308
options.tolerance = 0;
309309
}
310310

311-
if (this.prepareBaseImage) {
312-
options.prepareBaseImage = true;
313-
}
314-
311+
const prepareBaseImage = options.prepareBaseImage !== undefined
312+
? options.prepareBaseImage
313+
: (this.prepareBaseImage === true)
315314
const awsC = this.config.aws;
316-
if (awsC !== undefined && options.prepareBaseImage === false) {
315+
if (awsC !== undefined && prepareBaseImage === false) {
317316
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage);
318317
}
319318
if (options.prepareBaseImage !== undefined && options.prepareBaseImage) {
@@ -381,7 +380,7 @@ class ResembleHelper extends Helper {
381380
const helper = this._getHelper();
382381
await helper.waitForVisible(selector);
383382
const els = await helper._locate(selector);
384-
383+
385384
if (this.helpers['TestCafe']) {
386385
if (await els.count != 1) throw new Error(`Element ${selector} couldn't be located or isn't unique on the page`);
387386
}
@@ -391,7 +390,7 @@ class ResembleHelper extends Helper {
391390

392391
let location, size;
393392

394-
if (this.helpers['Puppeteer']) {
393+
if (this.helpers['Puppeteer'] || this.helpers['Playwright']) {
395394
const el = els[0];
396395
const box = await el.boundingBox();
397396
size = location = box;
@@ -447,7 +446,11 @@ class ResembleHelper extends Helper {
447446
return this.helpers['TestCafe'];
448447
}
449448

450-
throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/Puppeteer/TestCafe');
449+
if (this.helpers['Playwright']) {
450+
return this.helpers['Playwright'];
451+
}
452+
453+
throw new Error('No matching helper found. Supported helpers: Playwright/WebDriver/Appium/Puppeteer/TestCafe');
451454
}
452455
}
453456

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codeceptjs-resemblehelper",
3-
"version": "1.9.2",
4-
"description": "Resemble Js helper for CodeceptJS, with Support for Webdriver, Puppeteer & Appium",
3+
"version": "1.9.3",
4+
"description": "Resemble Js helper for CodeceptJS, with Support for Playwright, Webdriver, TestCafe, Puppeteer & Appium",
55
"repository": {
66
"type": "git",
77
"url": "[email protected]:Percona-Lab/codeceptjs-resemblehelper.git"

0 commit comments

Comments
 (0)