Skip to content

feat(testcafe): add the support for testcafe #62

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 1 commit into from
Apr 27, 2020
Merged
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
35 changes: 24 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ class ResembleHelper extends Helper {
const el = els[0];

await el.saveScreenshot(this.screenshotFolder + name + '.png');
} else throw new Error("Method only works with Puppeteer and WebDriver helpers.");
} else if (this.helpers['TestCafe']) {
await helper.waitForVisible(selector);
const els = await helper._locate(selector);
if (!await els.count) throw new Error(`Element ${selector} couldn't be located`);
const { t } = this.helpers['TestCafe'];

await t.takeElementScreenshot(els, name);
} else throw new Error("Method only works with Puppeteer, WebDriver or TestCafe helpers.");
}

/**
Expand Down Expand Up @@ -297,25 +304,18 @@ class ResembleHelper extends Helper {
}

const awsC = this.config.aws;

if (awsC !== undefined && options.prepareBaseImage === false) {
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage);
}

if (options.prepareBaseImage !== undefined && options.prepareBaseImage) {
await this._prepareBaseImage(baseImage);
}

if (selector) {
options.boundingBox = await this._getBoundingBox(selector);
}

const misMatch = await this._fetchMisMatchPercentage(baseImage, options);

this._addAttachment(baseImage, misMatch, options.tolerance);

this._addMochaContext(baseImage, misMatch, options.tolerance);

if (awsC !== undefined) {
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options.prepareBaseImage)
}
Expand Down Expand Up @@ -369,17 +369,24 @@ class ResembleHelper extends Helper {
const helper = this._getHelper();
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];

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`);
}
else {
if (!els.length) throw new Error(`Element ${selector} couldn't be located`);
}

let location, size;

if (this.helpers['Puppeteer']) {
const el = els[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the need for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this assignment from line 373 here. Because that doesn't work like this for TestCafe.

const box = await el.boundingBox();
size = location = box;
}

if (this.helpers['WebDriver'] || this.helpers['Appium']) {
const el = els[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes for the same reason. I didn't like this duplicate of code. But If you have a better solution, I'm ready to implement it.

location = await el.getLocation();
size = await el.getSize();
}
Expand All @@ -388,6 +395,9 @@ class ResembleHelper extends Helper {
location = await helper.browser.getLocation(selector);
size = await helper.browser.getElementSize(selector);
}
if (this.helpers['TestCafe']) {
return await els.boundingClientRect;
}

if (!size) {
throw new Error("Cannot get element size!");
Expand Down Expand Up @@ -421,8 +431,11 @@ class ResembleHelper extends Helper {
if (this.helpers['WebDriverIO']) {
return this.helpers['WebDriverIO'];
}
if (this.helpers['TestCafe']) {
return this.helpers['TestCafe'];
}

throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/Puppeteer');
throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/Puppeteer/TestCafe');
}
}

Expand Down