Skip to content

Commit

Permalink
fix: getScreenshot (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng authored Sep 23, 2023
1 parent 14d5156 commit 54c4c3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
41 changes: 18 additions & 23 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ controllers.takeElementScreenshot = async function(elementId, params = {}) {
* @return {Promise.<Element>}
*/
controllers.findElement = async function(strategy, selector, ctx) {
return await findElementOrElements.call(this, strategy, selector, ctx, false);
return findElementOrElements.call(this, strategy, selector, ctx, false);
};

controllers.findElements = async function(strategy, selector, ctx) {
return await findElementOrElements.call(this, strategy, selector, ctx, true);
return findElementOrElements.call(this, strategy, selector, ctx, true);
};

/**
Expand All @@ -258,7 +258,7 @@ controllers.findElements = async function(strategy, selector, ctx) {
*/
controllers.getText = async function(elementId) {
const element = this.elements[elementId];
return await element.innerText();
return element.innerText();
};

/**
Expand Down Expand Up @@ -299,7 +299,7 @@ controllers.setValue = async function(elementId, value) {
*/
controllers.isDisplayed = async function(elementId) {
const element = this.elements[elementId];
return await element.isVisible();
return element.isVisible();
};

/**
Expand All @@ -310,7 +310,7 @@ controllers.isDisplayed = async function(elementId) {
*/
controllers.getProperty = async function(elementId, attrName) {
const element = this.elements[elementId];
return await element.getAttribute(attrName);
return element.getAttribute(attrName);
};

/**
Expand All @@ -320,7 +320,7 @@ controllers.getProperty = async function(elementId, attrName) {
* @return {Promise.<Object>}
*/
controllers.title = async function() {
return await this.page.title();
return this.page.title();
};

/**
Expand Down Expand Up @@ -363,7 +363,7 @@ controllers.execute = async function(script, args) {
* @return {Promise.<string>}
*/
controllers.url = async function() {
return await this.page.url();
return this.page.url();
};

/**
Expand Down Expand Up @@ -412,7 +412,7 @@ controllers.back = async function() {
* @return {Promise}
*/
controllers.getWindows = async function() {
return await this.page.frames();
return this.page.frames();
};

/**
Expand Down Expand Up @@ -460,7 +460,7 @@ controllers.setWindowSize = async function(windowHandle, width, height) {
* @return {Promise.<string>}
*/
controllers.maximize = async function(windowHandle) {
return await this.setWindowSize(windowHandle, 1920, 1080);
return this.setWindowSize(windowHandle, 1920, 1080);
};

/**
Expand All @@ -471,7 +471,7 @@ controllers.maximize = async function(windowHandle) {
*/
controllers.refresh = async function() {
this.frame = null;
return await this.page.reload();
return this.page.reload();
};

/**
Expand All @@ -482,7 +482,7 @@ controllers.refresh = async function() {
*/
controllers.getSource = async function() {
const cmd = 'return document.getElementsByTagName(\'html\')[0].outerHTML';
return await this.execute(cmd);
return this.execute(cmd);
};

/**
Expand All @@ -493,14 +493,9 @@ controllers.getSource = async function() {
*/
controllers.getScreenshot = async function(context, params = {}) {
if (params.video) {
return await this.page.video()?.path?.() || null;
return this.page.video()?.path?.() || null;
}
if (params.fullPage) {
params.fullPage = params.fullPage === 'true';
}
const image = await this.page.screenshot(Object.assign({
fullPage: true,
}, params));
const image = await this.page.screenshot(params);
const base64 = image.toString('base64');

if (params.dir) {
Expand All @@ -522,7 +517,7 @@ controllers.getScreenshot = async function(context, params = {}) {
controllers.getComputedCss = async function(elementId, propertyName) {
const element = this.elements[elementId];
/* istanbul ignore next */
return await this.page.evaluate(([ element, propertyName ]) => window.getComputedStyle(element)[propertyName], [ element, propertyName ]);
return this.page.evaluate(([ element, propertyName ]) => window.getComputedStyle(element)[propertyName], [ element, propertyName ]);
};

/**
Expand All @@ -532,7 +527,7 @@ controllers.getComputedCss = async function(elementId, propertyName) {
* @return {Promise.<string>}
*/
controllers.getAllCookies = async function() {
return await this.browserContext.cookies();
return this.browserContext.cookies();
};

/**
Expand All @@ -542,7 +537,7 @@ controllers.getAllCookies = async function() {
* @return {Promise.<string>}
*/
controllers.getNamedCookie = async function() {
return await this.browserContext.cookies();
return this.browserContext.cookies();
};

/**
Expand Down Expand Up @@ -600,7 +595,7 @@ controllers.setContext = async function(name) {

controllers.getRect = async function(elementId) {
const element = this.elements[elementId];
return await element.boundingBox();
return element.boundingBox();
};

/**
Expand All @@ -609,7 +604,7 @@ controllers.getRect = async function(elementId) {
*/
controllers.next = async function(method, args = []) {
assert(method, 'method name is required');
return await nextActions[method].call(this, ...args);
return nextActions[method].call(this, ...args);
};

module.exports = controllers;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-playwright",
"version": "1.11.0",
"version": "1.11.1",
"description": "Macaca Playwright driver",
"keywords": [
"playwright",
Expand Down

0 comments on commit 54c4c3c

Please sign in to comment.