Skip to content

support playwright helper #81

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
Oct 20, 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
24 changes: 13 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
});
Expand Down Expand Up @@ -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);
Expand All @@ -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.");
}

/**
Expand Down Expand Up @@ -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`);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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');
}
}

Expand Down