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

[DDW-421] Record screenshots of failed acceptance tests #1103

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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ release
translations/messages
translations/reports

# Paper wallet ceritifcate PDF file generated by acceptance tests
# 'Screenshots' and 'Paper wallet ceritifcate PDF file' generated by acceptance tests
features/support/paper_wallet_certificates/paper-wallet-certificate.pdf
features/screenshots

# Webpack
.cache
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog
- Fixed broken storybook [PR 1041](https://github.com/input-output-hk/daedalus/pull/1041)
- Remove all ETC specific files [PR 1068](https://github.com/input-output-hk/daedalus/pull/1068)
- Make "port" and "ca" of Ada Api configurable during runtime [PR 1067](https://github.com/input-output-hk/daedalus/pull/1067)
- Added screenshots record of failed acceptance tests [PR 1103](https://github.com/input-output-hk/daedalus/pull/1103)

### Features

Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/helper-steps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { When } from 'cucumber';
import { generateScreenshotFilePath, saveScreenshot } from '../support/helpers/screenshot';

const oneHour = 60 * 60 * 1000;
// Helper step to pause execution for up to an hour ;)
When(/^I freeze$/, { timeout: oneHour }, (callback) => {
setTimeout(callback, oneHour);
});

When(/^I take a screenshot named "([^"]*)"$/, async function (testName) {
const file = generateScreenshotFilePath(testName);
await saveScreenshot(this, file);
});
6 changes: 5 additions & 1 deletion features/support/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Application } from 'spectron';
import { defineSupportCode } from 'cucumber';
import electronPath from 'electron';
import environment from '../../source/common/environment';
import { generateScreenshotFilePath, getTestNameFromTestFile, saveScreenshot } from './helpers/screenshot';

const context = {};
const DEFAULT_TIMEOUT = 20000;
Expand Down Expand Up @@ -97,9 +98,12 @@ defineSupportCode(({ BeforeAll, Before, After, AfterAll, setDefaultTimeout }) =>
});

// eslint-disable-next-line prefer-arrow-callback
After(async function ({ result }) {
After(async function ({ sourceLocation, result }) {
scenariosCount++;
if (result.status === 'failed') {
const testName = getTestNameFromTestFile(sourceLocation.uri);
const file = generateScreenshotFilePath(testName);
await saveScreenshot(context.app, file);
await printMainProcessLogs();
}
});
Expand Down
23 changes: 23 additions & 0 deletions features/support/helpers/screenshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from 'fs';
import path from 'path';
import { generateFileNameWithTimestamp } from '../../../source/common/fileName';
import ensureDirectoryExists from '../../../source/main/utils/ensureDirectoryExists';

export const generateScreenshotFilePath = (testName) => {
const filePath = path.resolve(__dirname, '../../screenshots', testName);
const fileName = generateFileNameWithTimestamp(testName, 'png');
ensureDirectoryExists(filePath);
return `${filePath}/${fileName}`;
};

export const getTestNameFromTestFile = (testFile) => testFile
.replace('features/', '')
.replace('.feature', '');

export const saveScreenshot = async (context, file) => {
await context.browserWindow.capturePage()
.then((imageBuffer) => fs.writeFile(file, imageBuffer))
.catch((err) => {
console.log(err);
});
};