cucumber-html-reporter icon indicating copy to clipboard operation
cucumber-html-reporter copied to clipboard

Unable to attach text to HTML report

Open nanichandu84 opened this issue 8 years ago • 6 comments

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 avatar Jul 26 '17 19:07 nanichandu84

@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'));

EugeneSnihovsky avatar Jul 27 '17 13:07 EugeneSnihovsky

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

nanichandu84 avatar Jul 27 '17 17:07 nanichandu84

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?

nanichandu84 avatar Jul 27 '17 22:07 nanichandu84

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');
      });
    }
  });```

erikgk avatar Aug 01 '17 07:08 erikgk

@nanichandu84

this.attach would work for Cucumber V2. Were you able to attach?

gkushang avatar Aug 01 '17 15:08 gkushang

I am unable to attach text in HTML report in 4.0.4 version. Any workaround?

uditanegi avatar Feb 20 '19 08:02 uditanegi