Skip to content

Commit

Permalink
fix: takeElementScreenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng committed Aug 18, 2023
1 parent 4a307f0 commit ba53c2a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,14 @@ controllers.click = async function(elementId) {
*/
controllers.takeElementScreenshot = async function(elementId, params = {}) {
const { file } = params;
const image = await this.elements[elementId].screenshot();
let image;
if (elementId) {
image = await this.elements[elementId].screenshot();

Check warning on line 201 in lib/controllers.js

View check run for this annotation

Codecov / codecov/patch

lib/controllers.js#L201

Added line #L201 was not covered by tests
} else if (this.locator) {
image = await this.locator.screenshot();
} else {
throw new errors.NoSuchElement();
}
const base64 = image.toString('base64');
if (file) {
const img = new Buffer(base64, 'base64');
Expand All @@ -211,7 +218,7 @@ controllers.takeElementScreenshot = async function(elementId, params = {}) {
* Search for an element on the page, starting from the document root.
* @module findElement
* @param {string} strategy The type
* @param {string} using The locator strategy to use.
* @param selector Selector string
* @param {string} ctx The search target.
* @return {Promise.<Element>}
*/
Expand Down

0 comments on commit ba53c2a

Please sign in to comment.