Skip to content

Commit

Permalink
handle screenshot failure scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Dileep Bellamkonda authored and Dileep17 committed Jan 17, 2024
1 parent 957f361 commit d2a27e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-reporter-plugin",
"version": "1.1.0-beta.04",
"version": "1.1.0-beta.05",
"description": "Appium 2.0 plugin for generating html report with screenshots server side.",
"main": "./lib/index.js",
"scripts": {
Expand Down
41 changes: 22 additions & 19 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,30 @@ export class ReportPlugin extends BasePlugin {
log.info(`session: ${driver.sessionId}; cmd ${commandName}; time appium took for screenshot: ${prettyHrtime(afterScreenshot)}`);

const beforeimgProcess = process.hrtime();
const buffer = base64screenshot.split(';base64,').pop();
let imgBuffer = Buffer.from(buffer, 'base64');

let meta = await sharp(imgBuffer).metadata();

img = await sharp(imgBuffer);
if (meta.width > 500) {
img = await img.resize(500);
if(base64screenshot) {
const buffer = base64screenshot.split(';base64,').pop();
let imgBuffer = Buffer.from(buffer, 'base64');

let meta = await sharp(imgBuffer).metadata();

img = await sharp(imgBuffer);
if (meta.width > 500) {
img = await img.resize(500);
}

img = await img
.toFormat('jpeg', { mozjpeg: true })
.toBuffer()
.then((data) => {
return data.toString('base64');
})
.catch((err) => {
log.error(`downsize issue ${err}`);
return null;
});
img = `data:image/jpeg;base64, ${img}`;
}

img = await img
.toFormat('jpeg', { mozjpeg: true })
.toBuffer()
.then((data) => {
return data.toString('base64');
})
.catch((err) => {
log.error(`downsize issue ${err}`);
return null;
});
img = `data:image/jpeg;base64, ${img}`;
const afterimgProcess = process.hrtime(beforeimgProcess);
log.info(`session: ${driver.sessionId}; cmd ${commandName}; time took to process image: ${prettyHrtime(afterimgProcess)}`);

Expand Down

0 comments on commit d2a27e8

Please sign in to comment.