cucumber-html-reporter
cucumber-html-reporter copied to clipboard
Unable to attach text to HTML report
I am trying to attach text to HTML report using this.attach('text to be added'), it is throwing Cannot read property 'attach' of undefined.
My cucumber-html-reoporter version -- 0.3.9
Do I need to add any config to add text to HTML files?
@nanichandu84 I have same problem today. My problem was with the loss of context (this). My work example (typescript)
'use strict';
import { browser } from 'protractor';
import { defineSupportCode, CallbackStepDefinition, HookScenarioResult } from 'cucumber';
defineSupportCode(function ({After}) {
After(function (scenario: HookScenarioResult, done: CallbackStepDefinition) {
let _self = this;
browser.manage().logs()
.get('browser').then((browserLog) => {
let log = 'log: ' +
require('util').inspect(browserLog);
_self.attach(JSON.stringify(browserLog, undefined, 4));
})
.then(() => done(), done);
});
});
Without _self and with arrow function this code doesn't work.
But this is not end of problem. This code works fine, but reporter show attachment text as ���u�Z and I have not found a solution yet.
Update: found solution in other issue to show normal text
_self.attach(Buffer.from('Hello world!').toString('base64'));
Thanks @EugeneSnihovsky for the help. Looks like I need to update my reporter version to @2.0 as well. Will try the solution after updating the version
I was under assumption, if I add, this.attach('text'), that should take care of adding the text to HTML report. Now after updating the version also, i am unable to use just this.attach().
Do I need to add anything to my hooks file?
I had a problem attaching images to the report. I had to change the anonymous function assignment The scope that is attached to a function() argument is different than assigning a anonymous function using () => { My wording to explain this may be a bit off Does not work
After(() => { var world = this; }
Does work
After(function () { var world = this; }
Complete code that works
After(function (scenario) {
var world = this;
if (scenario.isFailed()) {
return browser.takeScreenshot().then((screenShot) => {
// screenShot is a base-64 encoded PNG
world.attach(screenShot, 'image/png');
});
}
});```
@nanichandu84
this.attach would work for Cucumber V2. Were you able to attach?
I am unable to attach text in HTML report in 4.0.4 version. Any workaround?