Skip to content

Commit e8a87df

Browse files
authored
feat(testcafe): add the support for testcafe (#62)
1 parent 3732670 commit e8a87df

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

index.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ class ResembleHelper extends Helper {
126126
const el = els[0];
127127

128128
await el.saveScreenshot(this.screenshotFolder + name + '.png');
129-
} else throw new Error("Method only works with Puppeteer and WebDriver helpers.");
129+
} else if (this.helpers['TestCafe']) {
130+
await helper.waitForVisible(selector);
131+
const els = await helper._locate(selector);
132+
if (!await els.count) throw new Error(`Element ${selector} couldn't be located`);
133+
const { t } = this.helpers['TestCafe'];
134+
135+
await t.takeElementScreenshot(els, name);
136+
} else throw new Error("Method only works with Puppeteer, WebDriver or TestCafe helpers.");
130137
}
131138

132139
/**
@@ -302,25 +309,18 @@ class ResembleHelper extends Helper {
302309
}
303310

304311
const awsC = this.config.aws;
305-
306312
if (awsC !== undefined && options.prepareBaseImage === false) {
307313
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage);
308314
}
309-
310315
if (options.prepareBaseImage !== undefined && options.prepareBaseImage) {
311316
await this._prepareBaseImage(baseImage);
312317
}
313-
314318
if (selector) {
315319
options.boundingBox = await this._getBoundingBox(selector);
316320
}
317-
318321
const misMatch = await this._fetchMisMatchPercentage(baseImage, options);
319-
320322
this._addAttachment(baseImage, misMatch, options.tolerance);
321-
322323
this._addMochaContext(baseImage, misMatch, options.tolerance);
323-
324324
if (awsC !== undefined) {
325325
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options.prepareBaseImage)
326326
}
@@ -377,17 +377,24 @@ class ResembleHelper extends Helper {
377377
const helper = this._getHelper();
378378
await helper.waitForVisible(selector);
379379
const els = await helper._locate(selector);
380-
if (!els.length) throw new Error(`Element ${selector} couldn't be located`);
381-
const el = els[0];
380+
381+
if (this.helpers['TestCafe']) {
382+
if (await els.count != 1) throw new Error(`Element ${selector} couldn't be located or isn't unique on the page`);
383+
}
384+
else {
385+
if (!els.length) throw new Error(`Element ${selector} couldn't be located`);
386+
}
382387

383388
let location, size;
384389

385390
if (this.helpers['Puppeteer']) {
391+
const el = els[0];
386392
const box = await el.boundingBox();
387393
size = location = box;
388394
}
389395

390396
if (this.helpers['WebDriver'] || this.helpers['Appium']) {
397+
const el = els[0];
391398
location = await el.getLocation();
392399
size = await el.getSize();
393400
}
@@ -396,6 +403,9 @@ class ResembleHelper extends Helper {
396403
location = await helper.browser.getLocation(selector);
397404
size = await helper.browser.getElementSize(selector);
398405
}
406+
if (this.helpers['TestCafe']) {
407+
return await els.boundingClientRect;
408+
}
399409

400410
if (!size) {
401411
throw new Error("Cannot get element size!");
@@ -429,8 +439,11 @@ class ResembleHelper extends Helper {
429439
if (this.helpers['WebDriverIO']) {
430440
return this.helpers['WebDriverIO'];
431441
}
442+
if (this.helpers['TestCafe']) {
443+
return this.helpers['TestCafe'];
444+
}
432445

433-
throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/Puppeteer');
446+
throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/Puppeteer/TestCafe');
434447
}
435448
}
436449

0 commit comments

Comments
 (0)