diff --git a/.gitignore b/.gitignore index ac7daa21ce..1e7cd0f0e3 100755 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6930f44a62..6912aa40b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/features/step_definitions/helper-steps.js b/features/step_definitions/helper-steps.js index d9eb70ae78..6073a2cb47 100644 --- a/features/step_definitions/helper-steps.js +++ b/features/step_definitions/helper-steps.js @@ -1,4 +1,5 @@ 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 ;) @@ -6,3 +7,7 @@ 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); +}); diff --git a/features/support/electron.js b/features/support/electron.js index 4aaba00154..724e4e0d69 100644 --- a/features/support/electron.js +++ b/features/support/electron.js @@ -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; @@ -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(); } }); diff --git a/features/support/helpers/screenshot.js b/features/support/helpers/screenshot.js new file mode 100644 index 0000000000..193299e115 --- /dev/null +++ b/features/support/helpers/screenshot.js @@ -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); + }); +};