webdriverio-community/wdio-cucumberjs-json-reporter

Explicitly specified cjson:metadata gets ignored

mhanysz opened this issue · 2 comments

Environment (please complete the following information):

  • Node.js version: 14.17.5
  • NPM version: 6.14.14
  • webdriver.io version: 7.12.2
  • @wdio/cucumber-framework version: 7.12.2
  • wdio-cucumberjs-json-reporter version: 4.1.1

Config of webdriver.io and the reporter

exports.config = {
    maxInstances: 1,
    capabilities: [{
        "bstack:options": {
            osVersion: "14",
            deviceName: "iPhone 12",
            realMobile: true,
            debug: true,
            networkLogs: true,
            userName: "****",
            accessKey: "****",
            },
        browserName: "iPhone", 
        acceptInsecureCerts: true,
        "cjson:metadata": {
            device: "Test Device",
            browser: {
                name: "safari",
                version: "14.1"
            },
            platform: {
                name: "ios",
                version: "14"
            }
        }
    }],

    logLevel: 'info',
    bail: 0,
    waitforTimeout: 10000,
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,

    user: "****",
    key: "****",
    services: [
        'browserstack',
    ],
    
    framework: 'cucumber',
    specs: [
        './test/**/*.feature'
    ],
    cucumberOpts: {
        require: ["./test/**/*.js"],
    },
    reporters: ["cucumberjs-json"],
}

Describe the bug
The generated report contains incomplete metadata, even though, it has been specified explicitly in the capabilities. The resulting metadata in the generated json is:

"metadata":{
  "browser":{
    "name":"safari",
    "version":"No metadata.browser.version available"},
  "device":"iPhone 12",
  "platform":{
    "name":"iOS",
    "version":"Version not known"}
}

Browser version and os version are not properly filled, even though they were provided in the "cjson:metadata" object of the capabilities.

I debugged this into node_modules\wdio-cucumberjs-json-reporter\dist\metadata.js. The function determineMetadata(...) tries to access w3cCaps.cjson_metadata which is undefined. It looks like the correct property to access would be w3cCaps["cjson:metadata"]. If I change this manually, the metadata in the generated json will contain the explicitly specified cjson:metadata, as expected.

To Reproduce
Steps to reproduce the behavior:

  1. generate a wdio sample project with npx wdio config --yes
  2. replace wdio.conf.js with content shown above
  3. create package.json and set it to
{
  "name": "wdio-cucumberjs-json-reporter-bug",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@wdio/cli": "^7.12.2"
  },
  "devDependencies": {
    "@cucumber/cucumber": "^7.3.1",
    "@wdio/browserstack-service": "^7.12.2",
    "@wdio/cucumber-framework": "^7.12.2",
    "@wdio/local-runner": "^7.12.2",
    "@wdio/spec-reporter": "^7.10.1",
    "wdio-cucumberjs-json-reporter": "^4.1.1"
  }
}
  1. npm i
  2. npx wdio run wdio.conf.js

Expected behavior
I'd expect the automatic detection of the metadata to only fill in values, that were not provided explicitly by filling "cjson:metadata" in the capabilities. That means, if there's no browser name and version explicitly specified, fill in the automatically detected values. Same for device name, platform name and version, and app name and version.

Thanks @mhanysz

Can you take a stab at this and create a PR based on what you found?

Thanks @mhanysz

Can you take a stab at this and create a PR based on what you found?

Sure, I'll take care of this.