Skip to content

Commit

Permalink
fix: take element screenshot (#24)
Browse files Browse the repository at this point in the history
* fix: takeElementScreenshot
  • Loading branch information
yihuineng authored Aug 11, 2023
1 parent ac2e532 commit 1ceccfd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
25 changes: 2 additions & 23 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,9 @@ controllers.click = async function(elementId) {
* @module takeElementScreenshot
* @return {Promise}
*/
controllers.takeElementScreenshot = async function(_, params = {}) {
controllers.takeElementScreenshot = async function(elementId, params = {}) {
const { file } = params;
let { selector, strategy } = params;

if (selector && selector.startsWith('//')) {
strategy = 'xpath';
}

if (strategy === 'name') {
selector = `text=${selector}`;
} else if (strategy === 'id') {
selector = `//*[@id="${selector}"]`;
}

if (strategy) {
this.locator = await this.page.locator(selector);
} else {
this.locator = await this.page.$(selector);
}

if (!this.locator) {
throw new errors.NoSuchElement();
}
const image = await this.locator.screenshot();
const image = await this.elements[elementId].screenshot();
const base64 = image.toString('base64');
if (file) {
const img = new Buffer(base64, 'base64');
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-playwright",
"version": "1.7.0",
"version": "1.8.0",
"description": "Macaca Playwright driver",
"keywords": [
"playwright",
Expand Down Expand Up @@ -41,7 +41,8 @@
},
"scripts": {
"test": "nyc --reporter=lcov --reporter=text mocha --require ts-node/register",
"lint": "eslint --ext js,ts --fix lib test",
"lint": "eslint --ext js,ts lib test",
"lint:fix": "eslint --ext js,ts --fix lib test",
"prepublishOnly": "npm run build",
"build": "sh ./build.sh",
"contributor": "git-contributor"
Expand Down

0 comments on commit 1ceccfd

Please sign in to comment.