Skip to content
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

fix: screenshots every session for easy debugging #3711

Merged
merged 3 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
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
31 changes: 20 additions & 11 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,23 +2090,32 @@ class Playwright extends Helper {
*/
async saveScreenshot(fileName, fullPage) {
const fullPageOption = fullPage || this.options.fullPageScreenshots;
const outputFile = screenshotOutputFolder(fileName);
let outputFile = screenshotOutputFolder(fileName);

this.debug(`Screenshot is saving to ${outputFile}`);

await this.page.screenshot({
path: outputFile,
fullPage: fullPageOption,
type: 'png',
});

if (this.activeSessionName) {
const activeSessionPage = this.sessionPages[this.activeSessionName];

if (activeSessionPage) {
return activeSessionPage.screenshot({
path: outputFile,
fullPage: fullPageOption,
type: 'png',
});
for (const sessionName in this.sessionPages) {
const activeSessionPage = this.sessionPages[sessionName];
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`);

this.debug(`${sessionName} - Screenshot is saving to ${outputFile}`);

if (activeSessionPage) {
await activeSessionPage.screenshot({
path: outputFile,
fullPage: fullPageOption,
type: 'png',
});
}
}
}

return this.page.screenshot({ path: outputFile, fullPage: fullPageOption, type: 'png' });
}

/**
Expand Down
31 changes: 20 additions & 11 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1838,23 +1838,32 @@ class Puppeteer extends Helper {
*/
async saveScreenshot(fileName, fullPage) {
const fullPageOption = fullPage || this.options.fullPageScreenshots;
const outputFile = screenshotOutputFolder(fileName);
let outputFile = screenshotOutputFolder(fileName);

this.debug(`Screenshot is saving to ${outputFile}`);

await this.page.screenshot({
path: outputFile,
fullPage: fullPageOption,
type: 'png',
});

if (this.activeSessionName) {
const activeSessionPage = this.sessionPages[this.activeSessionName];

if (activeSessionPage) {
return activeSessionPage.screenshot({
path: outputFile,
fullPage: fullPageOption,
type: 'png',
});
for (const sessionName in this.sessionPages) {
const activeSessionPage = this.sessionPages[sessionName];
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`);

this.debug(`${sessionName} - Screenshot is saving to ${outputFile}`);

if (activeSessionPage) {
await activeSessionPage.screenshot({
path: outputFile,
fullPage: fullPageOption,
type: 'png',
});
}
}
}

return this.page.screenshot({ path: outputFile, fullPage: fullPageOption, type: 'png' });
}

async _failed() {
Expand Down
13 changes: 11 additions & 2 deletions lib/plugin/screenshotOnFail.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ module.exports = function (config) {
event.dispatcher.on(event.test.failed, (test) => {
recorder.add('screenshot of failed test', async () => {
let fileName = clearString(test.title);
// This prevent data driven to be included in the failed screenshot file name
const dataType = 'image/png';
// This prevents data driven to be included in the failed screenshot file name
if (fileName.indexOf('{') !== -1) {
fileName = fileName.substr(0, (fileName.indexOf('{') - 3)).trim();
}
Expand Down Expand Up @@ -106,7 +107,15 @@ module.exports = function (config) {

const allureReporter = Container.plugins('allure');
if (allureReporter) {
allureReporter.addAttachment('Last Seen Screenshot', fs.readFileSync(path.join(global.output_dir, fileName)), 'image/png');
allureReporter.addAttachment('Main session - Last Seen Screenshot', fs.readFileSync(path.join(global.output_dir, fileName)), dataType);

if (helper.activeSessionName) {
for (const sessionName in helper.sessionPages) {
const screenshotFileName = `${sessionName}_${fileName}`;
test.artifacts[`${sessionName.replace(/ /g, '_')}_screenshot`] = path.join(global.output_dir, screenshotFileName);
allureReporter.addAttachment(`${sessionName} - Last Seen Screenshot`, fs.readFileSync(path.join(global.output_dir, screenshotFileName)), dataType);
}
}
}

const cucumberReporter = Container.plugins('cucumberJsonReporter');
Expand Down