From c2adfed1b9a24adece2f03de3bb67291a005f914 Mon Sep 17 00:00:00 2001 From: Thanh Nguyen Date: Sat, 9 Feb 2019 14:35:13 +0100 Subject: [PATCH 1/4] fixed no screenshots on passed cases allure --- lib/command/definitions.js | 4 ++-- lib/parser.js | 2 +- lib/plugin/stepByStepReport.js | 6 ------ lib/utils.js | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/command/definitions.js b/lib/command/definitions.js index 96b1afdd9..fdfd5eeae 100644 --- a/lib/command/definitions.js +++ b/lib/command/definitions.js @@ -206,9 +206,9 @@ module.exports = function (genPath, options) { function addAllMethodsInObject(supportObj, actions, methods, translations) { for (const action of methodsOfObject(supportObj)) { - let fn = supportObj[action]; + const fn = supportObj[action]; if (!fn.name) { - Object.defineProperty(fn, "name", {value: action}); + Object.defineProperty(fn, 'name', { value: action }); } const actionAlias = translations ? translations.actionAliasFor(action) : action; if (!actions[actionAlias]) { diff --git a/lib/parser.js b/lib/parser.js index 7583eb050..99eaa4460 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -87,7 +87,7 @@ function getParams(fn) { }); return params; } catch (err) { - console.log('Error in ' + newFn.toString()); + console.log(`Error in ${newFn.toString()}`); console.error(err); } } diff --git a/lib/plugin/stepByStepReport.js b/lib/plugin/stepByStepReport.js index 506323a4c..ab6d99e0b 100644 --- a/lib/plugin/stepByStepReport.js +++ b/lib/plugin/stepByStepReport.js @@ -148,12 +148,6 @@ module.exports = function (config) { error = err; } savedStep = step; - - const allureReporter = Container.plugins('allure'); - if (allureReporter) { - output.plugin('stepByStepReport', 'Adding screenshot to Allure'); - allureReporter.addAttachment('Screenshot', fs.readFileSync(path.join(dir, fileName)), 'image/png'); - } } function persist(test, err) { diff --git a/lib/utils.js b/lib/utils.js index 1f02abd7c..9b6b5c28e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -40,7 +40,7 @@ const isGenerator = module.exports.isGenerator = function (fn) { }; const isFunction = module.exports.isFunction = function (fn) { - return typeof fn === 'function' + return typeof fn === 'function'; }; const isAsyncFunction = module.exports.isAsyncFunction = function (fn) { From 0284ba7d1fff451dff4116143f16426ab1219d3f Mon Sep 17 00:00:00 2001 From: Thanh Nguyen Date: Mon, 11 Feb 2019 13:47:13 +0100 Subject: [PATCH 2/4] introduced a config option to turn on step by step report for allure --- docs/plugins.md | 5 ++++- lib/plugin/stepByStepReport.js | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index 0118f3361..303fa5455 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -299,10 +299,13 @@ Possible config options: - `ignoreSteps`: steps to ignore in report. Array of RegExps is expected. Recommended to skip `grab*` and `wait*` steps. - `fullPageScreenshots`: should full page screenshots be used. Default: false. - `output`: a directory where reports should be stored. Default: `output`. +- `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false ##### Allure Reports -If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. +If Allure plugin is enabled this plugin attaches each saved screenshot to allure report when stepByStepAllure is set to true. + +- `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false ### Parameters diff --git a/lib/plugin/stepByStepReport.js b/lib/plugin/stepByStepReport.js index ab6d99e0b..0c03c095a 100644 --- a/lib/plugin/stepByStepReport.js +++ b/lib/plugin/stepByStepReport.js @@ -23,6 +23,7 @@ const defaultConfig = { ignoreSteps: [], fullPageScreenshots: false, output: global.output_dir, + stepByStepAllure: false, }; const templates = {}; @@ -58,11 +59,12 @@ const templates = {}; * * `ignoreSteps`: steps to ignore in report. Array of RegExps is expected. Recommended to skip `grab*` and `wait*` steps. * * `fullPageScreenshots`: should full page screenshots be used. Default: false. * * `output`: a directory where reports should be stored. Default: `output`. + * * `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false * * ##### Allure Reports * - * If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. - * + * If Allure plugin is enabled this plugin attaches each saved screenshot to allure report when stepByStepAllure is set to true. + * * `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false * * @param {*} config */ @@ -148,6 +150,12 @@ module.exports = function (config) { error = err; } savedStep = step; + + const allureReporter = Container.plugins('allure'); + if (allureReporter && (config.stepByStepAllure === true)) { + output.plugin('stepByStepReport', 'Adding screenshot to Allure'); + allureReporter.addAttachment('Screenshot', fs.readFileSync(path.join(dir, fileName)), 'image/png'); + } } function persist(test, err) { From 71cfa5a38d81fc72682c86e0ca97ade2086c095e Mon Sep 17 00:00:00 2001 From: Thanh Nguyen Date: Mon, 25 Feb 2019 14:02:31 +0100 Subject: [PATCH 3/4] introduced screenshots to allure as a config option --- docs/plugins.md | 7 ++----- lib/plugin/stepByStepReport.js | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index 303fa5455..7a68974f9 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -270,7 +270,7 @@ Possible config options: - `config` -## stepByStepReport +## screenshotsForAllureReport ![step-by-step-report][2] @@ -299,13 +299,10 @@ Possible config options: - `ignoreSteps`: steps to ignore in report. Array of RegExps is expected. Recommended to skip `grab*` and `wait*` steps. - `fullPageScreenshots`: should full page screenshots be used. Default: false. - `output`: a directory where reports should be stored. Default: `output`. -- `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false ##### Allure Reports -If Allure plugin is enabled this plugin attaches each saved screenshot to allure report when stepByStepAllure is set to true. - -- `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false +- `screenshotsForAllureReport`: If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. Default: false. ### Parameters diff --git a/lib/plugin/stepByStepReport.js b/lib/plugin/stepByStepReport.js index 0c03c095a..6ccc9bbd0 100644 --- a/lib/plugin/stepByStepReport.js +++ b/lib/plugin/stepByStepReport.js @@ -11,6 +11,7 @@ const { template, clearString, deleteDir } = require('../utils'); const supportedHelpers = [ 'WebDriverIO', + 'WebDriver', 'Protractor', 'Appium', 'Nightmare', @@ -23,7 +24,7 @@ const defaultConfig = { ignoreSteps: [], fullPageScreenshots: false, output: global.output_dir, - stepByStepAllure: false, + screenshotsForAllureReport: false, }; const templates = {}; @@ -59,15 +60,15 @@ const templates = {}; * * `ignoreSteps`: steps to ignore in report. Array of RegExps is expected. Recommended to skip `grab*` and `wait*` steps. * * `fullPageScreenshots`: should full page screenshots be used. Default: false. * * `output`: a directory where reports should be stored. Default: `output`. - * * `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false * * ##### Allure Reports * - * If Allure plugin is enabled this plugin attaches each saved screenshot to allure report when stepByStepAllure is set to true. - * * `stepByStepAllure`: attaches each saved screenshot to allure report. Default: false + * * `screenshotsForAllureReport`: If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. Default: false. * * @param {*} config */ + +screenshotsForAllureReport; module.exports = function (config) { const helpers = Container.helpers(); let helper; @@ -101,13 +102,12 @@ module.exports = function (config) { savedStep = null; }); + event.dispatcher.on(event.step.failed, persistStep); + event.dispatcher.on(event.step.after, (step) => { recorder.add('screenshot of failed test', async () => persistStep(step), true); }); - event.dispatcher.on(event.step.failed, persistStep); - - event.dispatcher.on(event.test.passed, (test) => { if (!config.deleteSuccessful) return persist(test); // cleanup @@ -152,9 +152,9 @@ module.exports = function (config) { savedStep = step; const allureReporter = Container.plugins('allure'); - if (allureReporter && (config.stepByStepAllure === true)) { + if (allureReporter && config.screenshotsForAllureReport) { output.plugin('stepByStepReport', 'Adding screenshot to Allure'); - allureReporter.addAttachment('Screenshot', fs.readFileSync(path.join(dir, fileName)), 'image/png'); + allureReporter.addAttachment(`Screenshot of step ${step}`, fs.readFileSync(path.join(dir, fileName)), 'image/png'); } } @@ -174,7 +174,7 @@ module.exports = function (config) { slideHtml += template(templates.slides, { image: i, - caption: step.toString(), + caption: step.toString().replace(/\[\d{2}m/g, ''), // remove ANSI escape sequence isActive: stepNum ? '' : 'active', isError: step.status === 'failed' ? 'error' : '', }); From 9fecb79e2f1ada50cbdf7cf8614f3a47c96b04f3 Mon Sep 17 00:00:00 2001 From: Thanh Nguyen Date: Mon, 25 Feb 2019 14:42:02 +0100 Subject: [PATCH 4/4] removed redundant text --- lib/plugin/stepByStepReport.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/plugin/stepByStepReport.js b/lib/plugin/stepByStepReport.js index 6ccc9bbd0..8784c07e3 100644 --- a/lib/plugin/stepByStepReport.js +++ b/lib/plugin/stepByStepReport.js @@ -68,7 +68,6 @@ const templates = {}; * @param {*} config */ -screenshotsForAllureReport; module.exports = function (config) { const helpers = Container.helpers(); let helper;