Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Using junit reporter with cucumber-boilerplate seems to not work #34

Open
christian-bromann opened this issue Mar 29, 2017 · 11 comments
Open

Comments

@christian-bromann
Copy link
Contributor

From @inspiraller on March 29, 2017 9:9

Using cucumber-boilerplate with junit reporter, I get an error:
This is inside my wdio.conf:

    reporters: ['spec','junit'],
    reporterOptions: {
        junit: {
            outputDir: './reports/'
        }
    },  

This is the error:

cucumber_boilerplate_prototype\node_modules\webdriverio\build\lib\utils\BaseReporter.js:336
                        throw _iteratorError;
                        ^

TypeError: Cannot read property 'toLowerCase' of undefined
    at JunitReporter.prepareName (c:\projects\cucumber_boilerplate_prototype\node_modules\wdio-junit-reporter\build\reporter.js:98:24)
    at JunitReporter.prepareXml (c:\projects\cucumber_boilerplate_prototype\node_modules\wdio-junit-reporter\build\reporter.js:147:57)
    at JunitReporter.onEnd (c:\projects\cucumber_boilerplate_prototype\node_modules\wdio-junit-reporter\build\reporter.js:75:36)
    at emitOne (events.js:77:13)
    at JunitReporter.emit (events.js:169:7)
    at BaseReporter.handleEvent (c:\projects\cucumber_boilerplate_prototype\node_modules\webdriverio\build\lib\utils\BaseReporter.js:324:35)
    at Launcher.endHandler (c:\projects\cucumber_boilerplate_prototype\node_modules\webdriverio\build\lib\launcher.js:637:28)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)

Copied from original issue: webdriverio/cucumber-boilerplate#73

@christian-bromann
Copy link
Contributor Author

Did you experience this @wvankuipers ?

@chadbrogan
Copy link

I am running into the exact same error with Jasmine 2.5.3 when I have a test marked as excluded xit.

@chadbrogan
Copy link

Skipped tests have an undefined value for the title attribute, which throws an error on prepareName(...)

https://github.com/webdriverio/wdio-junit-reporter/blob/2521ab547ac1ac8898b9f71c3ee56da00a4d1aee/lib/reporter.js#L74

Is that a legitimate situation, having an undefined title in a pending spec? I'm working on a pull request to more gracefully handle this situation. Would this be a good approach, or there something further upstream that needs to be looked at?

    prepareName (name) {
        if (name) {
            return name.toLowerCase().split(this.suiteNameRegEx).filter(
                (item) => item && item.length
            ).join('_')
        }
        return ''
    }

@drawm
Copy link

drawm commented Apr 17, 2017

In my case, there is an undefined value after each Scenario. I do not have a blank title. Imho it looks like a problem upstream.

Here's a test feature and step.

test.feature

Feature: true test
  Scenario: True should always be true
  Given blank test
  When blank test
  Then blank test

test.step-definition.js

var myStepDefinitionsWrapper = function () {
  this.Given(/^blank test$/, function () {
  });
};
module.exports = myStepDefinitionsWrapper;

package.json

{
  "name": "test-junit-wdio",
  "version": "0.0.0",
  "license": "",
  "author": "",
  "description": "",
  "repository": "",
  "main": "",
  "engines": {
    "node": "~6.10.0",
    "yarn": "^0.20.0"
  },
  "scripts": {
    "test": "wdio",
    "test:report": "wdio"
  },
  "dependencies": {
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-register": "^6.24.1",
    "babel-runtime": "^6.23.0",
    "webdriverio": "^4.6.2"
  },
  "devDependencies": {
    "wdio-browserstack-service": "^0.1.4",
    "wdio-cucumber-framework": "^0.2.16",
    "wdio-dot-reporter": "0.0.8",
    "wdio-junit-reporter": "^0.3.0",
    "wdio-phantomjs-service": "^0.2.2",
    "wdio-selenium-standalone-service": "0.0.8",
    "wdio-spec-reporter": "^0.1.0"
  }
}

wdio-junit-reporter/build/reporter.js

        value: function prepareName(name) {
            console.log('prepareName', name);
            if(!name) return '';
            return name.toLowerCase().split(this.suiteNameRegEx).filter(function (item) {
                return item && item.length;
            }).join('_');
        }

cli output

$ yarn run test
yarn run v0.20.3
$ wdio 
prepareName true test
prepareName True should always be true
prepareName undefined
prepareName blank test
prepareName blank test
prepareName blank test
Wrote xunit report to [./outputDir].


3 passing (1.00s)

Done in 1.51s.

@wvankuipers
Copy link

Did you experience this @wvankuipers ?

@christian-bromann I have not used the junit reporter in combination with the boilerplate. I'm going to look into this.

@mfurtado-mdsol
Copy link

mfurtado-mdsol commented May 10, 2017

I am experiencing the same problem as @drawm. I don't have any new lines after Scenario line but for some reason the SuiteStats object passed (as one of the keys of capabilities) into prepareXml method of wdio-junit-reporter from upstream contains

{ 
       undefined:
       TestStats {
         type: 'test',
         start: 2017-05-10T14:29:40.961Z,
         _duration: 0,
         uid: 'undefined',
         title: undefined,
         state: '',
         screenshots: [],
         output: [] 
}

@mfurtado-mdsol
Copy link

@christian-bromann Do you have any idea on why this could be happening? Thanks.

@christian-bromann
Copy link
Contributor Author

not without having a reproducible example

@mfurtado-mdsol
Copy link

@christian-bromann Here is a reproducible example repo: https://github.com/mfurtado-mdsol/junit-cucumber-failure.

I basically copied example given by @drawm with one difference(Before hook) in my steps file.

var myStepDefinitionsWrapper = function () {

  this.Before(scenario => {
    // Do something
  });

  this.Given(/^blank test$/, function () {
  });
};
module.exports = myStepDefinitionsWrapper;

It seems to me adding a Before hook leads to this issue of undefined newline after Scenario title.

@christian-bromann
Copy link
Contributor Author

this.Before is not supported by wdio-cucumber-framework. Please use wdio hooks. If it is supported in Cucumber v1.x.x than I am happy to add support for it. PRs welcome.

@mfurtado-mdsol
Copy link

@christian-bromann thanks. I can live with using wdio hooks. 🍻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants